diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 249e38191..efcc8a014 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -3,7 +3,6 @@ import path from "path"; import { performance } from "perf_hooks"; import * as core from "@actions/core"; -import * as github from "@actions/github"; import * as actionsUtil from "./actions-util"; import { @@ -272,16 +271,11 @@ async function run() { logger, ); - const pull_request = github.context.payload.pull_request; - const diffRangePackDir = - pull_request && - (await setupDiffInformedQueryRun( - pull_request.base.ref as string, - pull_request.head.label as string, - codeql, - logger, - features, - )); + const diffRangePackDir = await setupDiffInformedQueryRun( + codeql, + logger, + features, + ); await warnIfGoInstalledAfterInit(config, logger); await runAutobuildIfLegacyGoWorkflow(config, logger); diff --git a/src/analyze.ts b/src/analyze.ts index d82541ec7..343039fe8 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -2,6 +2,7 @@ import * as fs from "fs"; import * as path from "path"; import { performance } from "perf_hooks"; +import * as github from "@actions/github"; import * as io from "@actions/io"; import del from "del"; import * as yaml from "js-yaml"; @@ -256,18 +257,10 @@ async function finalizeDatabaseCreation( /** * Set up the diff-informed analysis feature. * - * @param baseRef The base branch name, used for calculating the diff range. - * @param headLabel The label that uniquely identifies the head branch across - * repositories, used for calculating the diff range. - * @param codeql - * @param logger - * @param features * @returns Absolute path to the directory containing the extension pack for * the diff range information, or `undefined` if the feature is disabled. */ export async function setupDiffInformedQueryRun( - baseRef: string, - headLabel: string, codeql: CodeQL, logger: Logger, features: FeatureEnablement, @@ -275,6 +268,15 @@ export async function setupDiffInformedQueryRun( if (!(await features.getValue(Feature.DiffInformedQueries, codeql))) { return undefined; } + + const pull_request = github.context.payload.pull_request; + if (!pull_request) { + return undefined; + } + + const baseRef = pull_request.base.ref as string; + const headLabel = pull_request.head.label as string; + return await withGroupAsync( "Generating diff range extension pack", async () => {