gh-ls-org: Don't process untouched repos

A repo is considered untouched if it has >= 10 open PRs by flathubbot
and no pushes have been made to the default branch in the last 5
weeks
This commit is contained in:
bbhtt
2024-09-18 19:57:02 +05:30
parent 64aa0e9ac3
commit 1a30993f29
@@ -1,9 +1,11 @@
#!/usr/bin/python3
import argparse
import datetime
import os
import github
from github.GithubException import GithubException
if __name__ == "__main__":
usage = (
@@ -14,6 +16,10 @@ if __name__ == "__main__":
parser.add_argument("organization", help="name of github organization")
args = parser.parse_args()
earliest = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(
weeks=5
)
github_token = os.environ['GITHUB_TOKEN']
g = github.Github(github_token, per_page=200)
@@ -21,4 +27,24 @@ if __name__ == "__main__":
for repo in org.get_repos():
if not repo.archived:
try:
default_branch = repo.default_branch
branch = repo.get_branch(default_branch)
last_commit = repo.get_commit(branch.commit.sha)
last_commit_time = last_commit.commit.committer.date.astimezone(
datetime.timezone.utc
)
pr_count = [
pr
for pr in repo.get_pulls(state="open")
if pr.user.login == "flathubbot"
]
except GithubException:
pr_count = []
last_commit_time = datetime.datetime.now(
datetime.timezone.utc
) + datetime.timedelta(seconds=10)
pass
if len(pr_count) >= 10 and last_commit_time < earliest:
continue
print(repo.html_url)