File: github-check-prs.py

package info (click to toggle)
coq 8.16.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 40,596 kB
  • sloc: ml: 219,376; sh: 3,545; python: 3,231; ansic: 2,529; makefile: 767; lisp: 279; javascript: 63; xml: 24; sed: 2
file content (47 lines) | stat: -rwxr-xr-x 1,504 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3

# Requires PyGithub https://pypi.python.org/pypi/PyGithub, for instance
# debian package: python3-github
# nix: nix-shell -p python3 python3Packages.PyGithub --run ./github-check-rebase.py
from github import Github
import argparse

REPO = "coq/coq"
REBASE_LABEL="needs: rebase"

parser = argparse.ArgumentParser()
parser.add_argument("--token-file", type=argparse.FileType('r'))
args = parser.parse_args()

if args.token_file is None:
    token = input("Github access token: ").strip()
else:
    token = args.token_file.read().rstrip("\n")
    args.token_file.close()

if token == "":
    print ("Warning: using the GitHub API without a token")
    print ("We may run into rate limit issues")
    g = Github()
else:
    g = Github(token)

repo = g.get_repo(REPO)

for pull in repo.get_pulls():
    # if conflicts then dirty
    # otherwise blocked (because I have no rights)
    dirty = pull.mergeable_state == "dirty"
    labelled = False
    for label in repo.get_issue(pull.number).get_labels():
        if label.name == REBASE_LABEL:
            labelled = True
    if labelled and not dirty:
        print ("PR #" + str(pull.number) + " is not dirty but is labelled")
        print ("("+ pull.html_url +")")
    elif dirty and not labelled:
        print ("PR #" + str(pull.number) + " is dirty and not labelled")
        print ("("+ pull.html_url +")")
    else:
        # give some feedback so the user can see we didn't crash
        print ("PR #" + str(pull.number) + " OK")