fix(ci): avoid dependency warnings from unrelated main updates (#156040)

This commit is contained in:
Josh Avant 2026-09-22 19:52:41 -05:00 • committed by GitHub
parent 469b35a80b
commit e6bd12b4cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 96 additions and 2 deletions

View file

@ -437,14 +437,31 @@ async function readBase64FileAtRef(api, { owner, repo, path, ref }) {
async function collectDependencyManifestChanges(api, { owner, repo, pullRequest, files }) {
const { isDependencyManifest } = loadSecurityReviewPolicy();
const changes = [];
let mergeBaseSha;
for (const file of files) {
const basePath = file.previous_filename ?? file.filename;
const headPath = file.filename;
if (!isDependencyManifest(basePath) && !isDependencyManifest(headPath)) {
continue;
}
if (!mergeBaseSha) {
// Match the PR diff: unrelated dependency updates on the target branch
// must neither invent nor hide manifest changes introduced by this PR.
// Page two omits file patches; only the comparison metadata is needed.
const baseSha = pullRequest.base?.sha;
const comparison = await api.request(
`/repos/${owner}/${repo}/compare/${baseSha}...${pullRequest.head?.sha}?per_page=1&page=2`,
);
if (
comparison?.base_commit?.sha !== baseSha ||
!/^[a-f0-9]{40}$/u.test(comparison?.merge_base_commit?.sha ?? "")
) {
throw new GitHubDiffDataError("GitHub returned an invalid dependency manifest merge base.");
}
mergeBaseSha = comparison.merge_base_commit.sha;
}
const baseManifest = isDependencyManifest(basePath)
? await readJsonFileAtRef(api, { owner, repo, path: basePath, ref: pullRequest.base?.sha })
? await readJsonFileAtRef(api, { owner, repo, path: basePath, ref: mergeBaseSha })
: null;
const headManifest = isDependencyManifest(headPath)
? await readJsonFileAtRef(api, { owner, repo, path: headPath, ref: pullRequest.head?.sha })