Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions gh_review_project/review_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
"""

Expand All @@ -325,6 +326,7 @@ def __init__(
self.repo = repo

self.status = None
self.state = None
self.milestone = "None"
self.assignee = None

Expand Down Expand Up @@ -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):
"""
Expand Down
22 changes: 20 additions & 2 deletions gh_review_project/set_milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,33 @@ 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)
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(
"\nThe following PRs were closed without merging. Archive them from the project:"
)
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.")

Expand Down