Skip to content

Commit 3eaf000

Browse files
committed
Add isCCR helper, and update isDefaultSetup
1 parent 1512f40 commit 3eaf000

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/actions-util.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
fixCodeQualityCategory,
66
getPullRequestBranches,
77
isAnalyzingPullRequest,
8+
isCCR,
9+
isDefaultSetup,
10+
isDynamicWorkflow,
811
} from "./actions-util";
912
import { computeAutomationID } from "./api-client";
1013
import { EnvVar } from "./environment";
@@ -246,3 +249,25 @@ test("fixCodeQualityCategory", (t) => {
246249
},
247250
);
248251
});
252+
253+
test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => {
254+
process.env.GITHUB_EVENT_NAME = "dynamic";
255+
t.assert(isDynamicWorkflow());
256+
process.env.GITHUB_EVENT_NAME = "push";
257+
t.false(isDynamicWorkflow());
258+
});
259+
260+
test("isCCR() returns true when expected", (t) => {
261+
process.env.GITHUB_EVENT_NAME = "dynamic";
262+
process.env.CODEQL_ACTION_ANALYSIS_KEY =
263+
"dynamic/copilot-pull-request-reviewer";
264+
t.assert(isCCR());
265+
t.false(isDefaultSetup());
266+
});
267+
268+
test("isDefaultSetup() returns true when expected", (t) => {
269+
process.env.GITHUB_EVENT_NAME = "dynamic";
270+
process.env.CODEQL_ACTION_ANALYSIS_KEY = "dynamic/github-code-scanning";
271+
t.assert(isDefaultSetup());
272+
t.false(isCCR());
273+
});

src/actions-util.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,18 @@ export function isDynamicWorkflow(): boolean {
254254

255255
/** Determines whether we are running in default setup. */
256256
export function isDefaultSetup(): boolean {
257-
return isDynamicWorkflow();
257+
return isDynamicWorkflow() && !isCCR();
258+
}
259+
260+
/** Determines whether we are running in CCR. */
261+
export function isCCR(): boolean {
262+
return (
263+
(isDynamicWorkflow() &&
264+
process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith(
265+
"dynamic/copilot-pull-request-reviewer",
266+
)) ||
267+
false
268+
);
258269
}
259270

260271
export function prettyPrintInvocation(cmd: string, args: string[]): string {

0 commit comments

Comments
 (0)