From 0954debb1a0b485e3fd77002366e83c1b47eaa9b Mon Sep 17 00:00:00 2001 From: Br1an67 <932039080@qq.com> Date: Sun, 1 Mar 2026 23:10:48 +0800 Subject: [PATCH] fix: use event.before SHA for synchronize diff instead of last two commits On synchronize events, the previous fallback only compared the last two commits in the PR. This misses changes when multiple commits are pushed at once. Now uses context.payload.before (the HEAD SHA before the push) to correctly capture all new changes. --- src/bot.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 6d44258..71eb783 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -87,7 +87,7 @@ export const robot = (app: Probot) => { head: context.payload.pull_request.head.sha, }); - let { files: changedFiles, commits } = data.data; + let { files: changedFiles } = data.data; if (context.payload.action === 'synchronize') { // Try to detect the last commit we reviewed (by looking for our previous review) @@ -107,7 +107,7 @@ export const robot = (app: Probot) => { if (botReview?.commit_id) { const { - data: { files, commits: newCommits }, + data: { files }, } = await context.octokit.repos.compareCommits({ owner: repo.owner, repo: repo.repo, @@ -116,30 +116,30 @@ export const robot = (app: Probot) => { }); changedFiles = files; - commits = newCommits; - } else if (commits.length >= 2) { - // fallback: compare last two commits in the PR + } else if (context.payload.before) { + // Use the 'before' SHA from the synchronize event to capture + // all commits in the push, not just the last one. const { data: { files }, } = await context.octokit.repos.compareCommits({ owner: repo.owner, repo: repo.repo, - base: commits[commits.length - 2].sha, - head: commits[commits.length - 1].sha, + base: context.payload.before, + head: context.payload.pull_request.head.sha, }); changedFiles = files; } } catch (err) { log.debug('failed to detect previous bot review, falling back', err); - if (commits.length >= 2) { + if (context.payload.before) { const { data: { files }, } = await context.octokit.repos.compareCommits({ owner: repo.owner, repo: repo.repo, - base: commits[commits.length - 2].sha, - head: commits[commits.length - 1].sha, + base: context.payload.before, + head: context.payload.pull_request.head.sha, }); changedFiles = files;