-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-pull-request
executable file
·45 lines (42 loc) · 2.1 KB
/
process-pull-request
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
#!/usr/bin/env python
"""
Returns top commit of a PR (mostly used to comments)
"""
from __future__ import print_function
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
import os
SCRIPT_DIR = dirname(abspath(sys.argv[0]))
if __name__ == "__main__":
parser = OptionParser(usage="%prog <pull-request-id>")
parser.add_option("-c", "--commit", dest="commit", action="store_true", help="Get last commit of the PR", default=False)
parser.add_option("-a", "--all", dest="all", action="store_true", help="Get all commits of the PR", default=False)
parser.add_option("-n", "--dry-run", dest="dryRun", action="store_true", help="Do not modify Github", default=False)
parser.add_option("-f", "--force", dest="force", action="store_true", help="Force process the issue/PR even if it is ignored.", default=False)
parser.add_option("-r", "--repository", dest="repository", help="Github Repositoy name e.g. cms-sw/cmssw.", type=str, default="cms-sw/cmssw")
parser.add_option("-u", "--user", dest="user", help="Github user name used for reporting to PRs and issues", type=str, default="FNALbuild")
opts, args = parser.parse_args()
if len(args) != 1:
parser.error("Too many/few arguments")
prId = int(args[0]) # Positional argument is "Pull request ID"
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
gh = Github(login_or_token=os.environ['GITHUBTOKEN'], retry=3)
if not opts.commit: api_rate_limits(gh)
repo = gh.get_repo(opts.repository)
if opts.commit:
pr = repo.get_pull(prId)
if opts.all:
for c in pr.get_commits():
print(c.sha)
else:
print(pr.get_commits().reversed[0].commit.sha)
else:
from process_pr import process_pr
process_pr(repo_config, gh, repo, repo.get_issue(prId), opts.dryRun, cmsbuild_user=opts.user, force=opts.force)