From 3766ab07d7061e946329443ed9a073ad3b41f457 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Tue, 15 Aug 2023 21:54:52 +0200 Subject: [PATCH] More complete fix for dev release scripts to filter commit for PR (#33418) This is a more complete fix to #33411. This is also a follow up on earlier implementation of #33261 that addressed checking if PRs are merged. This one applies the same pattern to finding commit but also improves it by checking if the (#NNNNNN) ends the subject - so even if the PR is in the same form in the message, it will be filtered out. The previous "--reverse" quick fix in #33411 had potential of problem in case there were releated PRs merged before the original PR (which is quite posssible when you have a series of PRs referring to each other. --- dev/airflow-github | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/dev/airflow-github b/dev/airflow-github index 69ca8ec53cc0..8109521e4ab6 100755 --- a/dev/airflow-github +++ b/dev/airflow-github @@ -83,27 +83,31 @@ def get_issue_type(issue): def get_commit_in_main_associated_with_pr(repo: git.Repo, issue: Issue) -> str | None: """For a PR, find the associated merged commit & return its SHA""" if issue.pull_request: - commit = repo.git.log("--reverse", f"--grep=#{issue.number}", "origin/main", "--format=%H") - if commit: - # We only want the oldest commit that referenced this PR number - return commit.splitlines()[0] + log_output = repo.git.log(f"--grep=(#{issue.number})$", "origin/main", "--format=%H %s") + if log_output: + for commit_line in log_output.splitlines(): + # We only want the commit for the PR where squash-merge added (#PR) at the end of subject + if commit_line and commit_line.endswith(f"(#{issue.number})"): + return commit_line.split(" ")[0] + return None else: pr: PullRequest = issue.as_pull_request() if pr.is_merged(): - commit = pr.merge_commit_sha - return commit + return pr.merge_commit_sha return None def is_cherrypicked(repo: git.Repo, issue: Issue, previous_version: str | None = None) -> bool: """Check if a given issue is cherry-picked in the current branch or not""" - log_args = ["--format=%H", f"--grep=(#{issue.number})$"] + log_args = ["--format=%H %s", f"--grep=(#{issue.number})$"] if previous_version: log_args.append(previous_version + "..") - log = repo.git.log(*log_args) + log_output = repo.git.log(*log_args) - if log: - return True + for commit_line in log_output.splitlines(): + # We only want the commit for the PR where squash-merge added (#PR) at the end of subject + if commit_line and commit_line.endswith(f"(#{issue.number})"): + return True return False