Merge pull request #1544 from YunoHost/bot-repo-cleanup
This commit is contained in:
commit
bfc5fc1f13
2 changed files with 28 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,6 +5,7 @@
|
||||||
.apps_cache
|
.apps_cache
|
||||||
builds
|
builds
|
||||||
tools/README-generator/venv/
|
tools/README-generator/venv/
|
||||||
|
tools/bot-repo-cleanup/.github_token
|
||||||
|
|
||||||
tools/autopatches/login
|
tools/autopatches/login
|
||||||
tools/autopatches/token
|
tools/autopatches/token
|
26
bot-repo-cleanup/cleanup.py
Normal file
26
bot-repo-cleanup/cleanup.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!venv/bin/python3
|
||||||
|
|
||||||
|
# Obtained with `pip install PyGithub`, better within a venv
|
||||||
|
from github import Github
|
||||||
|
from github.Workflow import Workflow
|
||||||
|
|
||||||
|
# API token for yunohost-bot, with "delete_repo" right
|
||||||
|
g = Github(open(".github_token").read().strip())
|
||||||
|
u = g.get_user("yunohost-bot")
|
||||||
|
|
||||||
|
# Let's build a minimalistic summary table
|
||||||
|
print("| Repository ".ljust(22) + " | Decision |")
|
||||||
|
print("| ".ljust(22, '-') + " | -------- |")
|
||||||
|
|
||||||
|
# For each repositories belonging to the bot (user `u`)
|
||||||
|
for repo in u.get_repos():
|
||||||
|
# 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":
|
||||||
|
print("| "+repo.name.ljust(20) + " | Skipping |")
|
||||||
|
else:
|
||||||
|
# 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