Optimize the bot-repo-cleanup script
This commit is contained in:
parent
c2de636ba4
commit
2dca5670de
1 changed files with 8 additions and 16 deletions
|
@ -12,24 +12,16 @@ u = g.get_user("yunohost-bot")
|
|||
print("| Repository ".ljust(22) + " | Decision |")
|
||||
print("| ".ljust(22, '-') + " | -------- |")
|
||||
|
||||
# For each repositories belonging to the bot (user `u`), assume we will not delete it
|
||||
# For each repositories belonging to the bot (user `u`)
|
||||
for repo in u.get_repos():
|
||||
delete = False
|
||||
# Proceed iff the repository is a fork (`parent` key is set) of a repository in our apps organization
|
||||
if repo.parent.full_name.split('/')[0] == "YunoHost-Apps":
|
||||
prs = []
|
||||
# Build the list of PRs currently opened in the repository
|
||||
# (the get_pulls method returns an iterable, not the full list)
|
||||
for pr in repo.parent.get_pulls(state='open', sort='created'):
|
||||
prs.append(pr)
|
||||
# If none of the PRs are opened by the bot, delete the repository
|
||||
if not any([ (pr.user == u) for pr in prs ]):
|
||||
delete = True
|
||||
else:
|
||||
if repo.parent.full_name.split('/')[0] != "YunoHost-Apps":
|
||||
print("| "+repo.name.ljust(20) + " | Skipping |")
|
||||
continue
|
||||
if delete:
|
||||
print("| "+repo.name.ljust(20) + " | Deleting |")
|
||||
repo.delete()
|
||||
else:
|
||||
print("| "+repo.name.ljust(20) + " | Keeping |")
|
||||
# If none of the PRs are opened by the bot, delete the repository
|
||||
if not any([ (pr.user == u) for pr in list(repo.parent.get_pulls(state='open', sort='created')) ]):
|
||||
print("| "+repo.name.ljust(20) + " | Deleting |")
|
||||
repo.delete()
|
||||
else:
|
||||
print("| "+repo.name.ljust(20) + " | Keeping |")
|
||||
|
|
Loading…
Reference in a new issue