Skip to content

Commit 5399708

Browse files
jennyhicksonr-sharp
authored andcommitted
Unmerged things (MetOffice#205)
* add removing unmerged changes * reinstate check * lint things
1 parent 33de615 commit 5399708

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

gh_review_project/finish_milestone.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def check_ready(
7878
exit(0)
7979
elif cont != "y":
8080
print("Unrecognised input, please select y or n")
81+
exit(0)
8182

8283

8384
def report(data: ProjectData, milestone: str) -> None:
@@ -98,6 +99,30 @@ def report(data: ProjectData, milestone: str) -> None:
9899
print(f"{total} pull requests completed in {milestone}")
99100

100101

102+
def tidy_unmerged(review_data: ProjectData, milestone: str, dry_run: bool = False):
103+
"""
104+
Confirm that all PRs closed at this milestone were actually merged, not just
105+
closed. If there are any then remove them from the milestone and archive
106+
them from the project.
107+
"""
108+
109+
print_banner(f"Removing closed but not merged pull requests from {milestone}")
110+
total = 0
111+
reviews = review_data.get_milestone(milestone, status="closed")
112+
for repo in reviews:
113+
for pr in reviews[repo]:
114+
if pr.check_state() == "CLOSED":
115+
pr.modify_milestone(milestone=None, dry_run=dry_run)
116+
pr.archive(REVIEW_ID, dry_run)
117+
review_data.project_items.remove(pr)
118+
total += 1
119+
120+
if total:
121+
print(f"{total} pull requests removed from {milestone} and archived.")
122+
else:
123+
print("All pull requests have been merged.")
124+
125+
101126
def tidy_issues(issue_data: ProjectData, milestone: str, dry_run: bool = False) -> None:
102127
"""
103128
Remove any outstanding open issues from the current milestone.
@@ -180,8 +205,10 @@ def main(
180205
ISSUE_ID, capture_project, file / "issue.json"
181206
)
182207

183-
# Set a milestone on closed PRs
208+
# Tidy closed PRs by setting milestones on those merged and removing
209+
# those closed but not merged.
184210
add_milestone(review_data, milestone, dry)
211+
tidy_unmerged(review_data, milestone, dry)
185212

186213
# Process data and report on status
187214
check_ready(review_data, issue_data, milestone)

0 commit comments

Comments
 (0)