From 6bfdb362abd17b7c4a019068671636ef9edc93f2 Mon Sep 17 00:00:00 2001 From: jennyhickson <61183013+jennyhickson@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:11:38 +0000 Subject: [PATCH 1/3] add removing unmerged changes --- gh_review_project/finish_milestone.py | 44 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/gh_review_project/finish_milestone.py b/gh_review_project/finish_milestone.py index 67b5698d..b2780a56 100644 --- a/gh_review_project/finish_milestone.py +++ b/gh_review_project/finish_milestone.py @@ -33,7 +33,6 @@ def check_ready( """ Check if the milestone is ready to be closed by confirming that: * all pull requests for this milestone have been completed - * all closed pull requests in the project are in this milestone. * all In Review issues for this milestone have been completed Give the user the choice to continue regardless since there may be valid @@ -53,23 +52,10 @@ def check_ready( if total_issues_in_review == 0: print("No issues in review\n") - print_banner(f"Checking for closed pull requests not set to {current_milestone}") - total_other = 0 - for milestone in reviews.milestones: - if milestone == current_milestone: - continue - else: - total_other += reviews.count_items( - milestone=milestone, status="closed", message="closed pull requests" - ) - if total_other == 0: - print("All closed pull requests are in this milestone\n") - - if total_open or total_other or total_issues_in_review: + if total_open or total_issues_in_review: print("=" * 50) print( f"{total_open} open pull request(s) in {current_milestone}. \n" - f"{total_other} closed pull request(s) not in {current_milestone}. \n" f"{total_issues_in_review} issues in {current_milestone} with status In Review. " ) cont = input("Would you like to continue with closing this milestone? (y/n) ") @@ -78,6 +64,7 @@ def check_ready( exit(0) elif cont != "y": print("Unrecognised input, please select y or n") + exit(0) def report(data: ProjectData, milestone: str) -> None: @@ -97,6 +84,29 @@ def report(data: ProjectData, milestone: str) -> None: print(f"{total} pull requests completed in {milestone}") +def tidy_unmerged(review_data: ProjectData, milestone: str, dry_run: bool = False): + """ + Confirm that all PRs closed at this milestone were actually merged, not just + closed. If there are any then remove them from the milestone and archive + them from the project. + """ + + print_banner(f"Removing closed but not merged pull requests from {milestone}") + total = 0 + reviews = review_data.get_milestone(milestone, status="closed") + for repo in reviews: + for pr in reviews[repo]: + if pr.check_state() == "CLOSED": + pr.modify_milestone(milestone=None, dry_run=dry_run) + pr.archive(REVIEW_ID, dry_run) + review_data.project_items.remove(pr) + total+=1 + + if total: + print(f"{total} pull requests removed from {milestone} and archived.") + else: + print(f"All pull requests have been merged.") + def tidy_issues(issue_data: ProjectData, milestone: str, dry_run: bool = False) -> None: """ @@ -180,8 +190,10 @@ def main( ISSUE_ID, capture_project, file / "issue.json" ) - # Set a milestone on closed PRs + # Tidy closed PRs by setting milestones on those merged and removing + # those closed but not merged. add_milestone(review_data, milestone, dry) + tidy_unmerged(review_data, milestone, dry) # Process data and report on status check_ready(review_data, issue_data, milestone) From a3f7555cc2856817a874c222c9e58298ad8e7449 Mon Sep 17 00:00:00 2001 From: jennyhickson <61183013+jennyhickson@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:15:01 +0000 Subject: [PATCH 2/3] reinstate check --- gh_review_project/finish_milestone.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gh_review_project/finish_milestone.py b/gh_review_project/finish_milestone.py index b2780a56..dc5ee14b 100644 --- a/gh_review_project/finish_milestone.py +++ b/gh_review_project/finish_milestone.py @@ -33,6 +33,7 @@ def check_ready( """ Check if the milestone is ready to be closed by confirming that: * all pull requests for this milestone have been completed + * all closed pull requests in the project are in this milestone. * all In Review issues for this milestone have been completed Give the user the choice to continue regardless since there may be valid @@ -52,10 +53,23 @@ def check_ready( if total_issues_in_review == 0: print("No issues in review\n") - if total_open or total_issues_in_review: + print_banner(f"Checking for closed pull requests not set to {current_milestone}") + total_other = 0 + for milestone in reviews.milestones: + if milestone == current_milestone: + continue + else: + total_other += reviews.count_items( + milestone=milestone, status="closed", message="closed pull requests" + ) + if total_other == 0: + print("All closed pull requests are in this milestone\n") + + if total_open or total_other or total_issues_in_review: print("=" * 50) print( f"{total_open} open pull request(s) in {current_milestone}. \n" + f"{total_other} closed pull request(s) not in {current_milestone}. \n" f"{total_issues_in_review} issues in {current_milestone} with status In Review. " ) cont = input("Would you like to continue with closing this milestone? (y/n) ") From 4de2fab163656d803d95bdfaccf4d77c981a6bcf Mon Sep 17 00:00:00 2001 From: jennyhickson <61183013+jennyhickson@users.noreply.github.com> Date: Fri, 6 Mar 2026 08:27:08 +0000 Subject: [PATCH 3/3] lint things --- gh_review_project/finish_milestone.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gh_review_project/finish_milestone.py b/gh_review_project/finish_milestone.py index dc5ee14b..0ffedaf8 100644 --- a/gh_review_project/finish_milestone.py +++ b/gh_review_project/finish_milestone.py @@ -98,6 +98,7 @@ def report(data: ProjectData, milestone: str) -> None: print(f"{total} pull requests completed in {milestone}") + def tidy_unmerged(review_data: ProjectData, milestone: str, dry_run: bool = False): """ Confirm that all PRs closed at this milestone were actually merged, not just @@ -114,12 +115,12 @@ def tidy_unmerged(review_data: ProjectData, milestone: str, dry_run: bool = Fals pr.modify_milestone(milestone=None, dry_run=dry_run) pr.archive(REVIEW_ID, dry_run) review_data.project_items.remove(pr) - total+=1 + total += 1 if total: print(f"{total} pull requests removed from {milestone} and archived.") else: - print(f"All pull requests have been merged.") + print("All pull requests have been merged.") def tidy_issues(issue_data: ProjectData, milestone: str, dry_run: bool = False) -> None: