Skip to content

Commit

Permalink
add iter
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 committed Dec 17, 2024
1 parent 3045165 commit 2ebe36c
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def handle(self, *args, **options):
self.github()

def github(self):
ids = []
processed = set()
for settings in AcademyAuthSettings.objects.filter(
github_owner__isnull=False, github_owner__credentialsgithub__isnull=False
Expand All @@ -32,20 +33,28 @@ def github(self):
processed.add(key)
allowed_users = ["breatheco-de", "4GeeksAcademy", "4geeksacademy"]

items = RepositoryDeletionOrder.objects.filter(provider=RepositoryDeletionOrder.Provider.GITHUB)
for deletion_order in items:
if deletion_order.repository_user not in allowed_users:
continue
while True:
items = RepositoryDeletionOrder.objects.filter(
provider=RepositoryDeletionOrder.Provider.GITHUB, notified_at=None
).exclude(id__in=ids)[:100]

if deletion_order.repository_name.endswith(".git"):
deletion_order.repository_name = deletion_order.repository_name[:-4]
deletion_order.save()
if len(items) == 0:
break

new_owner = self.get_username(deletion_order.repository_user, deletion_order.repository_name)
if new_owner is None:
continue
for deletion_order in items:
ids.append(deletion_order.id)
if deletion_order.repository_user not in allowed_users:
continue

if deletion_order.repository_name.endswith(".git"):
deletion_order.repository_name = deletion_order.repository_name[:-4]
deletion_order.save()

new_owner = self.get_username(deletion_order.repository_user, deletion_order.repository_name)
if new_owner is None:
continue

tasks.send_repository_deletion_notification.delay(deletion_order.id, new_owner)
tasks.send_repository_deletion_notification.delay(deletion_order.id, new_owner)

def check_path(self, obj: dict, *indexes: str) -> bool:
try:
Expand Down

0 comments on commit 2ebe36c

Please sign in to comment.