From 03fee19a327b183b094dd423f7d04ef2e20b0817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Wed, 8 Dec 2021 11:33:14 +0100 Subject: [PATCH] Added bulkclose feature to the githubPRs script --- dev-tools/scripts/githubPRs.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dev-tools/scripts/githubPRs.py b/dev-tools/scripts/githubPRs.py index 999b380d1cca..301cd4048ec3 100755 --- a/dev-tools/scripts/githubPRs.py +++ b/dev-tools/scripts/githubPRs.py @@ -33,6 +33,8 @@ def read_config(): parser = argparse.ArgumentParser(description='Find open Pull Requests that need attention') parser.add_argument('--json', action='store_true', default=False, help='Output as json') parser.add_argument('--token', help='Github access token in case you query too often anonymously') + parser.add_argument('--bulkclose', metavar='message', + help='To bulk close all open PRs with label "stale-closed", supply a PR comment message') newconf = parser.parse_args() return newconf @@ -60,6 +62,32 @@ def main(): out("Number of open Pull Requests: %s" % open_prs.totalCount) result['open_count'] = open_prs.totalCount + bulkclose = conf.bulkclose if conf.bulkclose is not None else None + if bulkclose: + if not token: + out("Need to supply a GitHub token to close PRs") + sys.exit(1) + out("Do you really want to bulk close %s open PRs with provided message?" % open_prs.totalCount) + a = None + while a not in ['y', 'n', 'l']: + out("\n") + a = input("Please choose Yes or No, or List (Y/N/L): ").lower() + if a == 'l': + for pr in open_prs: + out("#%s: %s" % (pr.number, pr.title)) + a = None + if a == 'n': + sys.exit(0) + if a == 'y': + for pr in open_prs: + out("Closing #%s: %s" % (pr.number, pr.title)) + pr.add_to_labels('stale-closed') + pr.create_issue_comment(bulkclose) + pr.edit(state='closed') + out("All open PRs now closed with comment and label 'stale-closed'") + sys.exit(1) + return + lack_jira = list(filter(lambda x: not re.match(r'.*\b(LUCENE|SOLR)-\d{3,6}\b', x.title), open_prs)) lack_jira_dict = {} for pr in lack_jira: