Move PR branch detection into setupDiffInformedQueryRun()

This commit is contained in:
Chuan-kai Lin 2025-03-14 10:40:47 -07:00
parent c50c157cc3
commit 6adda79888
2 changed files with 15 additions and 19 deletions

View file

@ -3,7 +3,6 @@ import path from "path";
import { performance } from "perf_hooks"; import { performance } from "perf_hooks";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as github from "@actions/github";
import * as actionsUtil from "./actions-util"; import * as actionsUtil from "./actions-util";
import { import {
@ -272,16 +271,11 @@ async function run() {
logger, logger,
); );
const pull_request = github.context.payload.pull_request; const diffRangePackDir = await setupDiffInformedQueryRun(
const diffRangePackDir = codeql,
pull_request && logger,
(await setupDiffInformedQueryRun( features,
pull_request.base.ref as string, );
pull_request.head.label as string,
codeql,
logger,
features,
));
await warnIfGoInstalledAfterInit(config, logger); await warnIfGoInstalledAfterInit(config, logger);
await runAutobuildIfLegacyGoWorkflow(config, logger); await runAutobuildIfLegacyGoWorkflow(config, logger);

View file

@ -2,6 +2,7 @@ import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { performance } from "perf_hooks"; import { performance } from "perf_hooks";
import * as github from "@actions/github";
import * as io from "@actions/io"; import * as io from "@actions/io";
import del from "del"; import del from "del";
import * as yaml from "js-yaml"; import * as yaml from "js-yaml";
@ -256,18 +257,10 @@ async function finalizeDatabaseCreation(
/** /**
* Set up the diff-informed analysis feature. * 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 * @returns Absolute path to the directory containing the extension pack for
* the diff range information, or `undefined` if the feature is disabled. * the diff range information, or `undefined` if the feature is disabled.
*/ */
export async function setupDiffInformedQueryRun( export async function setupDiffInformedQueryRun(
baseRef: string,
headLabel: string,
codeql: CodeQL, codeql: CodeQL,
logger: Logger, logger: Logger,
features: FeatureEnablement, features: FeatureEnablement,
@ -275,6 +268,15 @@ export async function setupDiffInformedQueryRun(
if (!(await features.getValue(Feature.DiffInformedQueries, codeql))) { if (!(await features.getValue(Feature.DiffInformedQueries, codeql))) {
return undefined; 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( return await withGroupAsync(
"Generating diff range extension pack", "Generating diff range extension pack",
async () => { async () => {