From 1a30993f2917e30860f0c6fcde81508d2fae99e0 Mon Sep 17 00:00:00 2001 From: bbhtt Date: Wed, 18 Sep 2024 09:53:06 +0530 Subject: [PATCH] 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 --- .../flatpak-external-data-checker/gh-ls-org | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/actions/flatpak-external-data-checker/gh-ls-org b/.github/actions/flatpak-external-data-checker/gh-ls-org index 3c99dda..f0172c0 100755 --- a/.github/actions/flatpak-external-data-checker/gh-ls-org +++ b/.github/actions/flatpak-external-data-checker/gh-ls-org @@ -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)