-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_pull_request.py
More file actions
executable file
·68 lines (60 loc) · 1.86 KB
/
create_pull_request.py
File metadata and controls
executable file
·68 lines (60 loc) · 1.86 KB
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
62
63
64
65
66
67
68
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "github-rest-api>=0.29.0",
# ]
# ///
"""Create a PR from the specified branch to dev.
The branch is updated (using dev) before creating the PR.
"""
from argparse import ArgumentParser, Namespace
import os
from github_rest_api import Repository
def parse_args(args=None, namespace=None) -> Namespace:
"""Parse command-line arguments.
:param args: The arguments to parse.
If None, the arguments from command-line are parsed.
:param namespace: An inital Namespace object.
:return: A namespace object containing parsed options.
"""
parser = ArgumentParser(description="Create pull requests to the dev branch.")
parser.add_argument(
"--token",
dest="token",
required=True,
help="The personal access token for authentication.",
)
parser.add_argument(
"--head-branch",
dest="head_branch",
required=True,
help="The head branch containing changes to merge.",
)
parser.add_argument(
"--base-branch",
dest="base_branch",
required=True,
help="The base branch to merge changes into.",
)
return parser.parse_args(args=args, namespace=namespace)
def main():
"""Main entrance of the script,
which creates a PR from the specified branch to dev.
The branch is updated (using dev) before creating the PR.
"""
args = parse_args()
# skip branches with the pattern _*
if args.head_branch.startswith("_"):
return
repo = Repository(args.token, os.getenv("GITHUB_REPOSITORY"))
repo.create_pull_request(
{
"base": args.base_branch,
"head": args.head_branch,
"title": f"Merge {args.head_branch} Into {args.base_branch}",
},
)
if __name__ == "__main__":
main()