Skip to content

Commit 4b164db

Browse files
committed
Add CODE_SCANNING_* vars to EnvVar enum
1 parent 97b52d1 commit 4b164db

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

lib/entry-points.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,10 @@ export function getPullRequestBranches(
429429

430430
// PR analysis under Default Setup does not have the pull_request context,
431431
// but it should set CODE_SCANNING_REF and CODE_SCANNING_BASE_BRANCH.
432-
const codeScanningRef = env.getOptional("CODE_SCANNING_REF");
433-
const codeScanningBaseBranch = env.getOptional("CODE_SCANNING_BASE_BRANCH");
432+
const codeScanningRef = env.getOptional(EnvVar.CODE_SCANNING_REF);
433+
const codeScanningBaseBranch = env.getOptional(
434+
EnvVar.CODE_SCANNING_BASE_BRANCH,
435+
);
434436
if (codeScanningRef && codeScanningBaseBranch) {
435437
return {
436438
base: codeScanningBaseBranch,

src/environment.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ export enum EnvVar {
1717
*/
1818
CLI_VERBOSITY = "CODEQL_VERBOSITY",
1919

20+
/**
21+
* Set by Default Setup to the base branch of the PR being analysed, if analysing a PR.
22+
* This is needed because the `pull_request` context is not available for `dynamic` events.
23+
*/
24+
CODE_SCANNING_BASE_BRANCH = "CODE_SCANNING_BASE_BRANCH",
25+
26+
/**
27+
* Set by Default Setup to the full ref being analysed, if analysing a PR.
28+
* This is needed because the `pull_request` context is not available for `dynamic` events.
29+
*/
30+
CODE_SCANNING_REF = "CODE_SCANNING_REF",
31+
2032
/**
2133
* `PersistedVersionInfo` for the CodeQL CLI, so later Actions steps can reuse it instead of
2234
* invoking `codeql version` again.

src/setup-codeql.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as sinon from "sinon";
77

88
import * as actionsUtil from "./actions-util";
99
import * as api from "./api-client";
10+
import { EnvVar } from "./environment";
1011
import { Feature } from "./feature-flags";
1112
import { getRunnerLogger } from "./logging";
1213
import { getCacheRestoreKeyPrefix } from "./overlay/caching";
@@ -637,8 +638,8 @@ test.serial(
637638
async (t) => {
638639
await withTmpDir(async (tmpDir) => {
639640
setupActionsVars(tmpDir, tmpDir);
640-
process.env["CODE_SCANNING_REF"] = "refs/heads/feature-branch";
641-
process.env["CODE_SCANNING_BASE_BRANCH"] = "main";
641+
process.env[EnvVar.CODE_SCANNING_REF] = "refs/heads/feature-branch";
642+
process.env[EnvVar.CODE_SCANNING_BASE_BRANCH] = "main";
642643

643644
sinon.stub(api, "getAutomationID").resolves("test/");
644645
const listStub = sinon.stub(api, "listActionsCaches").resolves([

0 commit comments

Comments
 (0)