2024-02-07 14:49:55 +01:00
|
|
|
#!/usr/bin/env python3
|
2022-11-23 22:01:07 +01:00
|
|
|
|
2022-11-26 20:45:17 +01:00
|
|
|
# Obtained with `pip install PyGithub`, better within a venv
|
2022-11-23 22:01:07 +01:00
|
|
|
from github import Github
|
|
|
|
from github.Workflow import Workflow
|
|
|
|
|
|
|
|
# API token for yunohost-bot, with "delete_repo" right
|
2022-12-29 14:50:32 +01:00
|
|
|
g = Github(open(".github_token").read().strip())
|
2022-11-23 22:01:07 +01:00
|
|
|
u = g.get_user("yunohost-bot")
|
|
|
|
|
2022-11-26 20:45:17 +01:00
|
|
|
# Let's build a minimalistic summary table
|
2022-11-23 22:01:07 +01:00
|
|
|
print("| Repository ".ljust(22) + " | Decision |")
|
2024-03-11 17:34:33 +01:00
|
|
|
print("| ".ljust(22, "-") + " | -------- |")
|
2022-11-23 22:01:07 +01:00
|
|
|
|
2022-11-26 20:53:50 +01:00
|
|
|
# For each repositories belonging to the bot (user `u`)
|
2022-11-23 22:01:07 +01:00
|
|
|
for repo in u.get_repos():
|
2022-11-26 20:45:17 +01:00
|
|
|
# Proceed iff the repository is a fork (`parent` key is set) of a repository in our apps organization
|
2024-03-11 17:34:33 +01:00
|
|
|
if repo.parent.full_name.split("/")[0] != "YunoHost-Apps":
|
|
|
|
print("| " + repo.name.ljust(20) + " | Skipping |")
|
2022-11-23 22:01:07 +01:00
|
|
|
else:
|
2022-11-26 20:53:50 +01:00
|
|
|
# If none of the PRs are opened by the bot, delete the repository
|
2024-03-11 17:34:33 +01:00
|
|
|
if not any(
|
|
|
|
[
|
|
|
|
(pr.user == u)
|
|
|
|
for pr in list(repo.parent.get_pulls(state="open", sort="created"))
|
|
|
|
]
|
|
|
|
):
|
|
|
|
print("| " + repo.name.ljust(20) + " | Deleting |")
|
2022-11-26 20:53:50 +01:00
|
|
|
repo.delete()
|
|
|
|
else:
|
2024-03-11 17:34:33 +01:00
|
|
|
print("| " + repo.name.ljust(20) + " | Keeping |")
|