Skip to content

Commit 535d0fd

Browse files
authored
Add set_milestone.py (#197)
* add set milestone script * black
1 parent 192f584 commit 535d0fd

3 files changed

Lines changed: 124 additions & 21 deletions

File tree

gh_review_project/cr_deadline.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# -----------------------------------------------------------------------------
2+
# (C) Crown copyright Met Office. All rights reserved.
3+
# The file LICENCE, distributed with this code, contains details of the terms
4+
# under which the code may be used.
5+
# -----------------------------------------------------------------------------
6+
7+
"""
8+
This script will update the pull requests and issues in the Simulation System
9+
Projects as required at the code review deadline.
10+
"""
11+
112
import argparse
213
from pathlib import Path
314
from review_project import ProjectData, ISSUE_ID

gh_review_project/finish_milestone.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pathlib import Path
1818
import argparse
1919
from review_project import ProjectData, REVIEW_ID, ISSUE_ID
20+
from set_milestone import add_milestone
2021

2122

2223
def print_banner(message: str) -> None:
@@ -26,26 +27,6 @@ def print_banner(message: str) -> None:
2627
print("=" * len(message))
2728

2829

29-
def closed_other(
30-
reviews: ProjectData, current_milestone: str, dry_run: bool = False
31-
) -> None:
32-
"""
33-
Set a milestone for closed PRs without one.
34-
35-
reviews: ProjectData from the Review Tracker Project
36-
current_milestone: Milestone being closed
37-
dry_run: If true, do not actually modify the milestone
38-
"""
39-
40-
print_banner(f"Setting pull requests with no milestone to {current_milestone}")
41-
42-
closed_prs = reviews.get_milestone(milestone="None", status="closed")
43-
44-
for repo in closed_prs:
45-
for pr in closed_prs[repo]:
46-
pr.modify_milestone(current_milestone, dry_run)
47-
48-
4930
def check_ready(
5031
reviews: ProjectData, issues: ProjectData, current_milestone: str
5132
) -> None:
@@ -200,7 +181,7 @@ def main(
200181
)
201182

202183
# Set a milestone on closed PRs
203-
closed_other(review_data, milestone, dry)
184+
add_milestone(review_data, milestone, dry)
204185

205186
# Process data and report on status
206187
check_ready(review_data, issue_data, milestone)

gh_review_project/set_milestone.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# -----------------------------------------------------------------------------
2+
# (C) Crown copyright Met Office. All rights reserved.
3+
# The file LICENCE, distributed with this code, contains details of the terms
4+
# under which the code may be used.
5+
# -----------------------------------------------------------------------------
6+
7+
"""
8+
This script will change the milestone on all closed pull requests that don't
9+
have one.
10+
"""
11+
12+
import argparse
13+
from pathlib import Path
14+
from review_project import ProjectData, REVIEW_ID
15+
16+
17+
def print_banner(message: str) -> None:
18+
print("\n")
19+
print("=" * len(message))
20+
print(message)
21+
print("=" * len(message))
22+
23+
24+
def add_milestone(
25+
reviews: ProjectData, current_milestone: str, dry_run: bool = False
26+
) -> None:
27+
"""
28+
Set a milestone for closed PRs without one.
29+
30+
reviews: ProjectData from the Review Tracker Project
31+
current_milestone: Milestone to set
32+
dry_run: If true, do not actually modify the milestone
33+
"""
34+
35+
print_banner(
36+
f"Setting closed pull requests with no milestone to {current_milestone}"
37+
)
38+
39+
closed_prs = reviews.get_milestone(milestone="None", status="closed")
40+
41+
if closed_prs:
42+
for repo in closed_prs:
43+
for pr in closed_prs[repo]:
44+
pr.modify_milestone(current_milestone, dry_run)
45+
else:
46+
print("No closed pull requests without a milestone.")
47+
48+
49+
def parse_args():
50+
"""
51+
Read command line args
52+
"""
53+
54+
testfile_path = Path(__file__).parent / "test"
55+
56+
parser = argparse.ArgumentParser(
57+
"Set all closed pull requests without a milestone to the requested milestone."
58+
)
59+
60+
parser.add_argument("--milestone", help="Milestone to set")
61+
parser.add_argument(
62+
"--test",
63+
action="store_true",
64+
help="Use test input files.",
65+
)
66+
parser.add_argument(
67+
"--capture_project",
68+
action="store_true",
69+
help="Capture the current project status into the test file",
70+
)
71+
parser.add_argument(
72+
"--file",
73+
default=testfile_path,
74+
help="Filepath to test data for either capturing the project status, "
75+
"or use as input data.",
76+
)
77+
parser.add_argument(
78+
"--dry",
79+
action="store_true",
80+
help="Dry run. Print commands, don't action them. Always true when "
81+
"running with test data.",
82+
)
83+
84+
args = parser.parse_args()
85+
86+
args.file = Path(args.file)
87+
args.file = args.file.expanduser().resolve()
88+
89+
if args.test:
90+
args.dry = True
91+
92+
return args
93+
94+
95+
def main(
96+
milestone: str, test: bool, capture_project: bool, file: Path, dry: bool
97+
) -> None:
98+
# Get milestone data
99+
if test:
100+
review_data = ProjectData.from_file(REVIEW_ID, file / "pr.json")
101+
else:
102+
review_data = ProjectData.from_github(
103+
REVIEW_ID, capture_project, file / "pr.json"
104+
)
105+
106+
add_milestone(review_data, milestone, dry)
107+
108+
109+
if __name__ == "__main__":
110+
args = parse_args()
111+
main(args.milestone, args.test, args.capture_project, args.file, args.dry)

0 commit comments

Comments
 (0)