Skip to content

Commit d7a9747

Browse files
kaxilYour friendly bot
authored andcommitted
[v3-0-test] Fix cherry-pick detection in airflow-github script (#54287)
- Fix `is_cherrypicked` function to detect PRs with multiple reference numbers - Differentiate between Closed and Merged status for better PR state visibility - Add PEP 723 script dependencies for easier execution with 'uv run --no-project' The cherry-pick detection was failing for PRs that had additional PR numbers appended during cherry-picking (e.g., '(#53955) (#53964)'). This change improves release management workflow by providing clearer PR status information. (cherry picked from commit 29a1cb0) Co-authored-by: Kaxil Naik <[email protected]>
1 parent be5907a commit d7a9747

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

dev/airflow-github

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
#!/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+
# ///
212

313
# Licensed to the Apache Software Foundation (ASF) under one
414
# 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"
4353
pr_title_re = re.compile(r".*\((#[0-9]{1,6})\)$")
4454

4555
STATUS_COLOR_MAP = {
46-
"Closed": "green",
56+
"Closed": "yellow",
57+
"Merged": "green",
4758
"Open": "red",
4859
}
4960

@@ -102,14 +113,14 @@ def get_commit_in_main_associated_with_pr(repo: git.Repo, issue: Issue) -> str |
102113

103114
def is_cherrypicked(repo: git.Repo, issue: Issue, previous_version: str | None = None) -> bool:
104115
"""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})"]
106117
if previous_version:
107118
log_args.append(previous_version + "..")
108119
log_output = repo.git.log(*log_args)
109120

110121
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:
113124
return True
114125
return False
115126

@@ -270,9 +281,15 @@ def compare(target_version, github_token, previous_version=None, show_uncherrypi
270281
)
271282
for issue in milestone_issues:
272283
commit_in_main = get_commit_in_main_associated_with_pr(repo, issue)
273-
status = issue.state.capitalize()
274284
issue_is_pr = is_pr(issue)
275285

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+
276293
# Checks if commit was cherrypicked into branch.
277294
if is_cherrypicked(repo, issue, previous_version):
278295
num_cherrypicked += 1

0 commit comments

Comments
 (0)