Skip to content

Commit 6fc7723

Browse files
committed
pkg_in_pipe: keep PRs merged by rebase or squash
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 81859cd commit 6fc7723

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

scripts/pkg_in_pipe/pkg_in_pipe.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def find_pull_requests(repo, start_sha, end_sha):
246246
"""Find the pull requests for the commits in the [start_sha,end_sha[ range."""
247247
prs = set()
248248
for commit in find_commits(GITHUB, repo, start_sha, end_sha):
249-
cache_key = f'commit-prs-4-{commit.sha}'
249+
cache_key = f'commit-prs-6-{commit.sha}'
250250
if not args.re_cache and cache_key in CACHE:
251251
prs.update(cast(list[PullRequest], CACHE[cache_key]))
252252
elif GITHUB:
@@ -258,9 +258,12 @@ def find_pull_requests(repo, start_sha, end_sha):
258258
if group:
259259
pr = GITHUB.get_repo(repo).get_pull(int(group[1]))
260260
prs.add(pr)
261-
# github sometimes return a PR which doesn't match the given commit, so we check if the commit
262-
# is actually in the PR
263-
commit_prs = [pr for pr in commit_prs if commit in pr.get_commits()]
261+
# github sometimes returns a PR which is only related to the commit through its branch
262+
# history, e.g. a PR whose branch was created from this commit, so we check that the
263+
# commit is actually part of the PR: it must be one of its commits, or its merge
264+
# commit. The latter is needed for the PRs merged by rebase or squash, whose merge
265+
# commit on the base branch is not one of the PR commits.
266+
commit_prs = [pr for pr in commit_prs if commit in pr.get_commits() or commit.sha == pr.merge_commit_sha]
264267
CACHE.set(cache_key, commit_prs, expire=RETENTION_TIME)
265268
prs.update(commit_prs)
266269
return sorted(prs, key=lambda p: p.number, reverse=True)

0 commit comments

Comments
 (0)