1
0
Fork 0

Comment the bot-repo-cleanup script

This commit is contained in:
tituspijean 2022-11-26 20:45:17 +01:00
parent fe2dd13c93
commit c2de636ba4

View file

@ -1,5 +1,6 @@
#!venv/bin/python3 #!venv/bin/python3
# Obtained with `pip install PyGithub`, better within a venv
from github import Github from github import Github
from github.Workflow import Workflow from github.Workflow import Workflow
@ -7,15 +8,21 @@ from github.Workflow import Workflow
g = Github("TOKEN_REPLACE_ME") g = Github("TOKEN_REPLACE_ME")
u = g.get_user("yunohost-bot") u = g.get_user("yunohost-bot")
# Let's build a minimalistic summary table
print("| Repository ".ljust(22) + " | Decision |") print("| Repository ".ljust(22) + " | Decision |")
print("| ".ljust(22, '-') + " | -------- |") print("| ".ljust(22, '-') + " | -------- |")
# For each repositories belonging to the bot (user `u`), assume we will not delete it
for repo in u.get_repos(): for repo in u.get_repos():
delete = False 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": if repo.parent.full_name.split('/')[0] == "YunoHost-Apps":
prs = [] 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'): for pr in repo.parent.get_pulls(state='open', sort='created'):
prs.append(pr) 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 ]): if not any([ (pr.user == u) for pr in prs ]):
delete = True delete = True
else: else: