-
Notifications
You must be signed in to change notification settings - Fork 7
/
comment-github-pullrequest
executable file
·52 lines (43 loc) · 1.21 KB
/
comment-github-pullrequest
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
#!/usr/bin/env python
"""
Makes a comment on Pull request on Github
"""
import os
import sys
import argparse
from socket import setdefaulttimeout
from github import Github
from Mu2eCI import config
from Mu2eCI.logger import log
from Mu2eCI.comment_gh_pr import comment_gh_pr
setdefaulttimeout(120)
parser = argparse.ArgumentParser(
description="Process a pull request given a repository and PR number."
)
parser.add_argument("-p", "--pullrequest", type=int, help="The Pull Request ID.")
parser.add_argument(
"-r",
"--repository",
type=str,
help="The GitHub repository. Must be in the format e.g. Mu2e/Offline",
choices=config.main["supported_repos"],
)
parser.add_argument(
"-R",
"--report-file",
type=str,
help="The report file e.g. gh-report.md",
default="",
)
args = parser.parse_args()
if __name__ == "__main__":
gh = Github(login_or_token=os.environ["GITHUBTOKEN"], retry=3)
try:
msg = ""
if len(args.report_file) > 0:
with open(args.report_file, "r") as f:
msg = f.read()
comment_gh_pr(gh, args.repository, args.pullrequest, msg)
except Exception:
log.exception("Failed to add comment")
sys.exit(1)