Skip to content

Commit d02475c

Browse files
authored
BCR PR reviewer: Verify the PR isn't updated before approval/merge (#2312)
1 parent c055431 commit d02475c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

actions/bcr-pr-reviewer/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ async function reviewPR(octokit, owner, repo, prNumber) {
333333
const prAuthor = prInfo.data.user.login;
334334
const allModulesApproved = await checkIfAllModifiedModulesApproved(modifiedModules, maintainersMap, approvers, prAuthor);
335335

336+
// Re-fetch PR information to check if new commits were pushed since analysis started
337+
const initialHeadSha = prInfo.data.head.sha;
338+
const latestPrInfoForShaCheck = await octokit.rest.pulls.get({
339+
owner,
340+
repo,
341+
pull_number: prNumber,
342+
});
343+
const currentHeadSha = latestPrInfoForShaCheck.data.head.sha;
344+
345+
if (initialHeadSha !== currentHeadSha) {
346+
console.log(`PR #${prNumber} has been updated since the review process began. Initial SHA: ${initialHeadSha}, Current SHA: ${currentHeadSha}. Aborting approval/merge actions as the analysis may be stale.`);
347+
return; // Exit reviewPR for this PR to prevent actions on stale data
348+
}
349+
336350
const { data } = await octokit.rest.users.getAuthenticated();
337351
const myLogin = data.login;
338352

0 commit comments

Comments
 (0)