-
Notifications
You must be signed in to change notification settings - Fork 245
/
create-gh-pr.py
executable file
·58 lines (56 loc) · 1.64 KB
/
create-gh-pr.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
#!/usr/bin/env python3
from github import Github
from os.path import expanduser
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument(
"-r", "--repository", dest="repo", help="Github Repositoy name e.g cms-sw/cms-bot", type=str
)
parser.add_argument(
"-b",
"--base_branch",
dest="base_branch",
help="Repository branch against which new Pull request should be created",
type=str,
)
parser.add_argument(
"-f",
"--feature_branch",
dest="feature_branch",
help="New feature branch to be merged",
type=str,
)
parser.add_argument("-t", "--title", dest="title", help="Pull request title", type=str)
parser.add_argument(
"-d", "--body", dest="body", help="Pull request body text, optional", type=str, default=""
)
parser.add_argument(
"-c",
"--comment",
dest="comment",
help="Extra comment after creating Pull requests e.g. please tests",
type=str,
default="",
)
args = parser.parse_args()
if not args.repo:
parser.error("Missing Repo")
if not args.base_branch:
parser.error("Missing base branch name.")
if not args.feature_branch:
parser.error("Missing feature branch name.")
if not args.title:
parser.error("Missing PR title")
print("Authenticating to Github and connecting to repo")
gh = Github(login_or_token=open(expanduser("~/.github-token")).read().strip())
print("Authentication succeeded")
gh_repo = gh.get_repo(args.repo)
print("Creating pull request")
pr = gh_repo.create_pull(
title=args.title,
body=args.body.replace("@N@", "\n"),
base=args.base_branch,
head=args.feature_branch,
)
if args.comment:
pr.create_issue_comment(body=args.comment)