forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-future-commits-prs.py
executable file
·61 lines (54 loc) · 1.66 KB
/
check-future-commits-prs.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
from datetime import datetime
from github import Github
from os.path import expanduser, dirname, abspath, join, exists
from optparse import OptionParser
from socket import setdefaulttimeout
from github_utils import api_rate_limits
setdefaulttimeout(120)
import sys
SCRIPT_DIR = dirname(abspath(sys.argv[0]))
parser = OptionParser(usage="%prog")
parser.add_option(
"-n",
"--dry-run",
dest="dryRun",
action="store_true",
help="Do not modify Github",
default=False,
)
parser.add_option(
"-r",
"--repository",
dest="repository",
help="Github Repositoy name e.g. cms-sw/cmssw.",
type=str,
default="cms-sw/cmssw",
)
opts, args = parser.parse_args()
if len(args) != 0:
parser.error("Too many/few arguments")
repo_dir = join(SCRIPT_DIR, "repos", opts.repository.replace("-", "_"))
if exists(join(repo_dir, "repo_config.py")):
sys.path.insert(0, repo_dir)
import repo_config
from github_utils import get_last_commit
gh = Github(login_or_token=open(expanduser(repo_config.GH_TOKEN)).read().strip())
api_rate_limits(gh)
repo = gh.get_repo(opts.repository)
label = [repo.get_label("future-commit")]
cnt = 0
for issue in repo.get_issues(state="open", sort="updated", labels=label):
pr = issue.pull_request
if not pr:
continue
last_commit = get_last_commit(pr)
if last_commit is None:
continue
if last_commit.commit.committer.date > datetime.utcnow():
continue
cnt += 1
with open("cms-bot-%s-%s.txt" % (repo.name, cnt), "w") as prop:
prop.write("FORCE_PULL_REQUEST=%s\n" % issue.number)
prop.write("REPOSITORY=%s\n" % opts.repository)
api_rate_limits(gh)