Skip to content

Commit 914b568

Browse files
committed
Move PR branch detection into setupDiffInformedQueryRun()
1 parent f338ec8 commit 914b568

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/analyze-action.ts

Lines changed: 5 additions & 11 deletions
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

Lines changed: 10 additions & 8 deletions
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";
@@ -245,25 +246,26 @@ async function finalizeDatabaseCreation(
245246
/**
246247
* Set up the diff-informed analysis feature.
247248
*
248-
* @param baseRef The base branch name, used for calculating the diff range.
249-
* @param headLabel The label that uniquely identifies the head branch across
250-
* repositories, used for calculating the diff range.
251-
* @param codeql
252-
* @param logger
253-
* @param features
254249
* @returns Absolute path to the directory containing the extension pack for
255250
* the diff range information, or `undefined` if the feature is disabled.
256251
*/
257252
export async function setupDiffInformedQueryRun(
258-
baseRef: string,
259-
headLabel: string,
260253
codeql: CodeQL,
261254
logger: Logger,
262255
features: FeatureEnablement,
263256
): Promise<string | undefined> {
264257
if (!(await features.getValue(Feature.DiffInformedQueries, codeql))) {
265258
return undefined;
266259
}
260+
261+
const pull_request = github.context.payload.pull_request;
262+
if (!pull_request) {
263+
return undefined;
264+
}
265+
266+
const baseRef = pull_request.base.ref as string;
267+
const headLabel = pull_request.head.label as string;
268+
267269
return await withGroupAsync(
268270
"Generating diff range extension pack",
269271
async () => {

0 commit comments

Comments
 (0)