|
1 | 1 | #!/usr/bin/env python3
|
| 2 | +# /// script |
| 3 | +# requires-python = ">=3.10" |
| 4 | +# dependencies = [ |
| 5 | +# "GitPython", |
| 6 | +# "PyGithub", |
| 7 | +# "rich-click", |
| 8 | +# "packaging", |
| 9 | +# "rich", |
| 10 | +# ] |
| 11 | +# /// |
2 | 12 |
|
3 | 13 | # Licensed to the Apache Software Foundation (ASF) under one
|
4 | 14 | # or more contributor license agreements. See the NOTICE file
|
@@ -43,7 +53,8 @@ GIT_LOG_FORMAT = "%x1f".join(["%h", "%an", "%ae", "%ad", "%s", "%b"]) + "%x1e"
|
43 | 53 | pr_title_re = re.compile(r".*\((#[0-9]{1,6})\)$")
|
44 | 54 |
|
45 | 55 | STATUS_COLOR_MAP = {
|
46 |
| - "Closed": "green", |
| 56 | + "Closed": "yellow", |
| 57 | + "Merged": "green", |
47 | 58 | "Open": "red",
|
48 | 59 | }
|
49 | 60 |
|
@@ -102,14 +113,14 @@ def get_commit_in_main_associated_with_pr(repo: git.Repo, issue: Issue) -> str |
|
102 | 113 |
|
103 | 114 | def is_cherrypicked(repo: git.Repo, issue: Issue, previous_version: str | None = None) -> bool:
|
104 | 115 | """Check if a given issue is cherry-picked in the current branch or not"""
|
105 |
| - log_args = ["--format=%H %s", f"--grep=(#{issue.number})$"] |
| 116 | + log_args = ["--format=%H %s", f"--grep=(#{issue.number})"] |
106 | 117 | if previous_version:
|
107 | 118 | log_args.append(previous_version + "..")
|
108 | 119 | log_output = repo.git.log(*log_args)
|
109 | 120 |
|
110 | 121 | for commit_line in log_output.splitlines():
|
111 |
| - # We only want the commit for the PR where squash-merge added (#PR) at the end of subject |
112 |
| - if commit_line and commit_line.endswith(f"(#{issue.number})"): |
| 122 | + # Check if the PR number exists in the commit message (handles cherry-picked commits with multiple PR numbers) |
| 123 | + if commit_line and f"(#{issue.number})" in commit_line: |
113 | 124 | return True
|
114 | 125 | return False
|
115 | 126 |
|
@@ -270,9 +281,15 @@ def compare(target_version, github_token, previous_version=None, show_uncherrypi
|
270 | 281 | )
|
271 | 282 | for issue in milestone_issues:
|
272 | 283 | commit_in_main = get_commit_in_main_associated_with_pr(repo, issue)
|
273 |
| - status = issue.state.capitalize() |
274 | 284 | issue_is_pr = is_pr(issue)
|
275 | 285 |
|
| 286 | + # Determine status - differentiate between Closed and Merged for PRs |
| 287 | + if issue_is_pr and issue.state == "closed": |
| 288 | + pr = issue.as_pull_request() |
| 289 | + status = "Merged" if pr.is_merged() else "Closed" |
| 290 | + else: |
| 291 | + status = issue.state.capitalize() |
| 292 | + |
276 | 293 | # Checks if commit was cherrypicked into branch.
|
277 | 294 | if is_cherrypicked(repo, issue, previous_version):
|
278 | 295 | num_cherrypicked += 1
|
|
0 commit comments