@@ -4,7 +4,7 @@ import { fileURLToPath } from 'url';
44import { Worker } from 'bullmq' ;
55import { redis , scanQueue } from './queue.js' ;
66import { getInstallationToken } from './auth.js' ;
7- import { startCheckRun , completeCheckRun , ensureLabelsExist , setLabels } from './github.js' ;
7+ import { startCheckRun , completeCheckRun , ensureLabelsExist , setLabels , getMergeBaseSha } from './github.js' ;
88import { createWorkspace , setupRepo , getChangedFiles , checkoutFiles , cleanupWorkspace } from './fetcher.js' ;
99import { dispatch } from './dispatcher.js' ;
1010import { buildAnnotations } from './reporter.js' ;
@@ -144,10 +144,17 @@ async function runScan(job) {
144144 const token = await getInstallationToken ( installationId ) ;
145145 debug ( 'worker' , 'installation token acquired' ) ;
146146
147+ // Resolve the merge base so the diff matches GitHub's PR view (three-dot diff).
148+ // pull_request.base.sha is the tip of the base branch, which may have advanced
149+ // since the PR was opened — diffing directly against it would include files
150+ // changed in the base branch that the PR never touched.
151+ const mergeBaseSha = await getMergeBaseSha ( { installationId, owner, repo, base : baseSha , head : headSha } ) ;
152+ debug ( 'worker' , `merge base resolved: ${ mergeBaseSha } ` ) ;
153+
147154 workspacePath = await createWorkspace ( job . id ) ;
148155
149- await setupRepo ( { token, cloneUrl, headSha, baseSha, workspacePath } ) ;
150- const rawChanged = await getChangedFiles ( { workspacePath, baseSha, headSha } ) ;
156+ await setupRepo ( { token, cloneUrl, headSha, baseSha : mergeBaseSha , workspacePath } ) ;
157+ const rawChanged = await getChangedFiles ( { workspacePath, baseSha : mergeBaseSha , headSha } ) ;
151158 const changedFiles = await checkoutFiles ( { workspacePath, headSha, files : rawChanged } ) ;
152159 debug ( 'worker' , `dispatching ${ changedFiles . length } file(s) to scanners` ) ;
153160
0 commit comments