From 074b1ffc43197eeded82aa26d9c19a5873b73d6d Mon Sep 17 00:00:00 2001 From: Bugale Date: Fri, 21 Aug 2026 20:11:00 +0300 Subject: [PATCH] fix: take the pull request SHAs from the event payload The JSON pulls.get call was used only to obtain the base/head SHAs for the uncapped compare request, but on GHES 3.18 it fails with 422 "The request could not be processed because too many files changed" when the workflow's GITHUB_TOKEN queries a sufficiently large pull request (a PAT querying the same pull request succeeds). The SHAs are already present in the pull_request event payload, which is guaranteed to exist on every path that reaches getPrDiff, so use them instead. Co-Authored-By: Claude Fable 5 --- dist/index.js | 10 +++++++--- src/bugalint.ts | 10 +++++++--- src/index.ts | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index bcc8b32..60386a6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30274,9 +30274,13 @@ function decodeDiff(data) { } throw new Error(`The pull request diff was returned as ${typeof data} rather than text, so no issue can be matched against the pull request`); } -async function getPrDiff(githubToken, owner, repo, prNumber) { +async function getPrDiff(githubToken, owner, repo) { const octokit = (0, github_1.getOctokit)(githubToken); - const { base, head } = (await octokit.rest.pulls.get({ owner, repo, pull_number: prNumber })).data; + const pr = github_1.context.payload.pull_request; + if (pr == null) { + throw new Error('No pull request payload found.'); + } + const { base, head } = pr; return decodeDiff((await octokit.rest.repos.compareCommits({ owner, repo, base: base.sha, head: head.sha, mediaType: { format: 'diff' } })).data); } function parseDiffLines(diff) { @@ -32338,7 +32342,7 @@ async function run() { if (prNumber == null) { throw new Error('No pull request number found.'); } - pullRequest ??= [prNumber, await (0, bugalint_1.getPrDiff)(githubToken, github_1.context.repo.owner, github_1.context.repo.repo, prNumber)]; + pullRequest ??= [prNumber, await (0, bugalint_1.getPrDiff)(githubToken, github_1.context.repo.owner, github_1.context.repo.repo)]; return pullRequest; }; let issues = [...parser(input)]; diff --git a/src/bugalint.ts b/src/bugalint.ts index 8876e37..c6a4869 100644 --- a/src/bugalint.ts +++ b/src/bugalint.ts @@ -1,5 +1,5 @@ import type { Log, Region, ReportingDescriptor, Result } from 'sarif' -import { getOctokit } from '@actions/github' +import { context, getOctokit } from '@actions/github' import { debug, warning, summary } from '@actions/core' import path from 'path' import parseDiff from 'parse-diff' @@ -387,9 +387,13 @@ function decodeDiff(data: unknown): string { throw new Error(`The pull request diff was returned as ${typeof data} rather than text, so no issue can be matched against the pull request`) } -export async function getPrDiff(githubToken: string, owner: string, repo: string, prNumber: number): Promise { +export async function getPrDiff(githubToken: string, owner: string, repo: string): Promise { const octokit = getOctokit(githubToken) - const { base, head } = (await octokit.rest.pulls.get({ owner, repo, pull_number: prNumber })).data + const pr = context.payload.pull_request as ({ base: { sha: string } } & { head: { sha: string } }) | undefined + if (pr == null) { + throw new Error('No pull request payload found.') + } + const { base, head } = pr return decodeDiff((await octokit.rest.repos.compareCommits({ owner, repo, base: base.sha, head: head.sha, mediaType: { format: 'diff' } })).data) } diff --git a/src/index.ts b/src/index.ts index 91a4a0b..c526bc7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,7 +48,7 @@ export async function run(): Promise { if (prNumber == null) { throw new Error('No pull request number found.') } - pullRequest ??= [prNumber, await getPrDiff(githubToken, context.repo.owner, context.repo.repo, prNumber)] + pullRequest ??= [prNumber, await getPrDiff(githubToken, context.repo.owner, context.repo.repo)] return pullRequest }