Skip to content

Commit 7892a43

Browse files
committed
fix: filter push events by PR branch to prevent timer reset
When a PR was merged to master, the push event affected the merge timer calculation for all other open PRs. This happened because getDates() was fetching all repository events and using the most recent PushEvent regardless of which branch it targeted. Now the code filters push events to only include those where payload.ref matches the PR's head branch (refs/heads/<branch-name>), preventing merges to master or other branches from resetting unrelated PR timers. Closes #752
1 parent 7c7a7ce commit 7892a43

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/helpers/pullRequest.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ async function getDates(githubClient, pull) {
3535
return Math.max(new Date(total), latestCommitDate);
3636
}, new Date('January 1, 1970 00:00:00 UTC'));
3737

38-
// Get push events
38+
// Get push events - filter to only include pushes to this PR's branch
39+
// The GitHub Events API returns all repo events, so we must filter by ref
40+
// to avoid other branch pushes (like merges to master) affecting this PR's timer
41+
const prBranchRef = `refs/heads/${pull.head.ref}`;
3942
const repoEvents = await githubClient.getBranchEvents(
4043
pull.head.repo.events_url
4144
);
@@ -44,6 +47,10 @@ async function getDates(githubClient, pull) {
4447
if (current.type !== 'PushEvent') {
4548
return new Date(total);
4649
}
50+
// Only consider push events to this PR's branch
51+
if (current.payload?.ref !== prBranchRef) {
52+
return new Date(total);
53+
}
4754
return new Date(
4855
Math.max(
4956
new Date(total).getTime(),

0 commit comments

Comments
 (0)