|
37 | 37 | PR_JSON_FIELDS = ( |
38 | 38 | "number,title,url,author,createdAt,updatedAt,headRefName,headRefOid," |
39 | 39 | "baseRefName,isDraft,reviewDecision,reviewRequests,reviews,latestReviews," |
40 | | - "additions,deletions,changedFiles,labels,statusCheckRollup" |
| 40 | + "additions,deletions,changedFiles,labels,state,statusCheckRollup" |
41 | 41 | ) |
42 | 42 |
|
43 | 43 | # Allow enough time for large PR lists over slower networks. |
@@ -703,10 +703,10 @@ def normalize_pr( |
703 | 703 | now: datetime.datetime, |
704 | 704 | author_association: str = "", |
705 | 705 | ) -> PrSummary: |
706 | | - """Converts a single `gh pr list --json` item into a PrSummary. |
| 706 | + """Converts a single `gh pr list` or `gh pr view` JSON item into a PrSummary. |
707 | 707 |
|
708 | 708 | Args: |
709 | | - raw_pr: Parsed JSON object for one PR from `gh pr list`. |
| 709 | + raw_pr: Parsed JSON object for one PR from `gh pr list` or `gh pr view`. |
710 | 710 | repo: Repository slug in `owner/name` form. |
711 | 711 | viewer: Active GitHub login for viewer-scoped fields. |
712 | 712 | max_age_days: Days since last update after which PRs are marked stale. |
@@ -755,6 +755,7 @@ def normalize_pr( |
755 | 755 | ) |
756 | 756 |
|
757 | 757 | is_draft = bool(raw_pr.get("isDraft")) |
| 758 | + pr_state = str(raw_pr.get("state") or "OPEN").strip().upper() or "OPEN" |
758 | 759 | review_decision = str(raw_pr.get("reviewDecision") or "").upper() or "NONE" |
759 | 760 | is_my_pr = bool(viewer_lower and author_login.lower() == viewer_lower) |
760 | 761 |
|
@@ -801,6 +802,7 @@ def normalize_pr( |
801 | 802 | checks_total=checks_total, |
802 | 803 | action_needed=action_needed, |
803 | 804 | is_stale=is_stale, |
| 805 | + state=pr_state, |
804 | 806 | ) |
805 | 807 |
|
806 | 808 |
|
@@ -1136,7 +1138,7 @@ class FetchError(Exception): |
1136 | 1138 |
|
1137 | 1139 | @dataclasses.dataclass(frozen=True) |
1138 | 1140 | class PrSummary: |
1139 | | - """Normalized summary of an open GitHub pull request.""" |
| 1141 | + """Normalized summary of a GitHub pull request.""" |
1140 | 1142 |
|
1141 | 1143 | # GitHub repository in owner/name format. |
1142 | 1144 | repo: str |
@@ -1204,6 +1206,8 @@ class PrSummary: |
1204 | 1206 | action_needed: str |
1205 | 1207 | # Whether the PR exceeds max_age_days since updated_at. |
1206 | 1208 | is_stale: bool |
| 1209 | + # PR lifecycle state from GitHub (OPEN, CLOSED, or MERGED). |
| 1210 | + state: str = "OPEN" |
1207 | 1211 |
|
1208 | 1212 | def to_dict(self) -> dict[str, object]: |
1209 | 1213 | """Serializes this summary into a JSON-compatible dict.""" |
|
0 commit comments