Skip to content

Commit 6adda79

Browse files
committed
Move PR branch detection into setupDiffInformedQueryRun()
1 parent c50c157 commit 6adda79

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/analyze-action.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from "path";
33
import { performance } from "perf_hooks";
44

55
import * as core from "@actions/core";
6-
import * as github from "@actions/github";
76

87
import * as actionsUtil from "./actions-util";
98
import {
@@ -272,16 +271,11 @@ async function run() {
272271
logger,
273272
);
274273

275-
const pull_request = github.context.payload.pull_request;
276-
const diffRangePackDir =
277-
pull_request &&
278-
(await setupDiffInformedQueryRun(
279-
pull_request.base.ref as string,
280-
pull_request.head.label as string,
281-
codeql,
282-
logger,
283-
features,
284-
));
274+
const diffRangePackDir = await setupDiffInformedQueryRun(
275+
codeql,
276+
logger,
277+
features,
278+
);
285279

286280
await warnIfGoInstalledAfterInit(config, logger);
287281
await runAutobuildIfLegacyGoWorkflow(config, logger);

src/analyze.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from "fs";
22
import * as path from "path";
33
import { performance } from "perf_hooks";
44

5+
import * as github from "@actions/github";
56
import * as io from "@actions/io";
67
import del from "del";
78
import * as yaml from "js-yaml";
@@ -256,25 +257,26 @@ async function finalizeDatabaseCreation(
256257
/**
257258
* Set up the diff-informed analysis feature.
258259
*
259-
* @param baseRef The base branch name, used for calculating the diff range.
260-
* @param headLabel The label that uniquely identifies the head branch across
261-
* repositories, used for calculating the diff range.
262-
* @param codeql
263-
* @param logger
264-
* @param features
265260
* @returns Absolute path to the directory containing the extension pack for
266261
* the diff range information, or `undefined` if the feature is disabled.
267262
*/
268263
export async function setupDiffInformedQueryRun(
269-
baseRef: string,
270-
headLabel: string,
271264
codeql: CodeQL,
272265
logger: Logger,
273266
features: FeatureEnablement,
274267
): Promise<string | undefined> {
275268
if (!(await features.getValue(Feature.DiffInformedQueries, codeql))) {
276269
return undefined;
277270
}
271+
272+
const pull_request = github.context.payload.pull_request;
273+
if (!pull_request) {
274+
return undefined;
275+
}
276+
277+
const baseRef = pull_request.base.ref as string;
278+
const headLabel = pull_request.head.label as string;
279+
278280
return await withGroupAsync(
279281
"Generating diff range extension pack",
280282
async () => {

0 commit comments

Comments
 (0)