Skip to content

Commit

Permalink
More complete fix for dev release scripts to filter commit for PR (#3…
Browse files Browse the repository at this point in the history
…3418)

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.
  • Loading branch information
potiuk authored Aug 15, 2023
1 parent 5b104a9 commit 3766ab0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions dev/airflow-github
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 3766ab0

Please sign in to comment.