From 32c06c6161e64c9d9910c2a2dac64767b8af44d5 Mon Sep 17 00:00:00 2001 From: jennyhickson <61183013+jennyhickson@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:26:22 +0000 Subject: [PATCH 1/3] add merge check --- gh_review_project/review_project.py | 16 ++++++++++++++-- gh_review_project/set_milestone.py | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gh_review_project/review_project.py b/gh_review_project/review_project.py index 1c07b74d..31e166fe 100644 --- a/gh_review_project/review_project.py +++ b/gh_review_project/review_project.py @@ -142,7 +142,7 @@ def _extract_data(cls, raw_data: dict) -> list: if "milestone" in item_data: item.milestone = item_data["milestone"]["title"] - if "assignee" in item_data: + if "assignees" in item_data: item.assignee = item_data["assignees"] item_list.append(item) @@ -309,7 +309,8 @@ class ProjectItem: number: number of the item in the repository title: title of the item repo: repository where the item is located - status: status of the item + status: status of the item in the project + state: item state (draft, open, merged, closed) milestone: title of the milestone """ @@ -325,6 +326,7 @@ def __init__( self.repo = repo self.status = None + self.state = None self.milestone = "None" self.assignee = None @@ -388,6 +390,16 @@ def add_comment(self, text: str, dry_run: bool = False) -> None: print(message) run_command(command) + def check_state(self) -> str: + """ + Fetch item state from gh and store to object + """ + command = f"gh {self.command_type} view {self.number} --repo='{PROJECT_OWNER}/{self.repo}' --json state" + output = run_command(command) + self.state = json.loads(output.stdout)["state"] + + return self.state + class PullRequest(ProjectItem): """ diff --git a/gh_review_project/set_milestone.py b/gh_review_project/set_milestone.py index 3abf209b..61912df9 100644 --- a/gh_review_project/set_milestone.py +++ b/gh_review_project/set_milestone.py @@ -33,15 +33,27 @@ def add_milestone( """ print_banner( - f"Setting closed pull requests with no milestone to {current_milestone}" + f"Setting merged pull requests with no milestone to {current_milestone}" ) closed_prs = reviews.get_milestone(milestone="None", status="closed") + archive_list = [] if closed_prs: for repo in closed_prs: for pr in closed_prs[repo]: - pr.modify_milestone(current_milestone, dry_run) + state = pr.check_state() + if state == "MERGED": + pr.modify_milestone(current_milestone, dry_run) + else: + archive_list.append(pr) + + if archive_list: + print( + "\nThe following PRs were closed without merging. Archive them from the project:" + ) + for pr in archive_list: + pr.archive(REVIEW_ID, dry_run) else: print("No closed pull requests without a milestone.") From ea4574d80845f06afce95da2744266d7bba9112e Mon Sep 17 00:00:00 2001 From: jennyhickson <61183013+jennyhickson@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:37:11 +0000 Subject: [PATCH 2/3] remove from project --- gh_review_project/set_milestone.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gh_review_project/set_milestone.py b/gh_review_project/set_milestone.py index 61912df9..c3f2cb1f 100644 --- a/gh_review_project/set_milestone.py +++ b/gh_review_project/set_milestone.py @@ -54,6 +54,7 @@ def add_milestone( ) for pr in archive_list: pr.archive(REVIEW_ID, dry_run) + reviews.project_items.remove(pr) else: print("No closed pull requests without a milestone.") From a535c4c7fe4457c48ddb799722a9f1f2d4f19b9b Mon Sep 17 00:00:00 2001 From: jennyhickson <61183013+jennyhickson@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:58:32 +0000 Subject: [PATCH 3/3] add error check --- gh_review_project/set_milestone.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gh_review_project/set_milestone.py b/gh_review_project/set_milestone.py index c3f2cb1f..1995326a 100644 --- a/gh_review_project/set_milestone.py +++ b/gh_review_project/set_milestone.py @@ -45,8 +45,13 @@ def add_milestone( state = pr.check_state() if state == "MERGED": pr.modify_milestone(current_milestone, dry_run) - else: + elif state == "CLOSED": archive_list.append(pr) + else: + print( + f"PR {pr.number} in {pr.repo} is in state {state} with " + f"status {pr.status}. Please manually check it." + ) if archive_list: print(