Skip to content

Commit 7610dfd

Browse files
author
Simon Engledew
committed
Implement PR feedback
1 parent 0853901 commit 7610dfd

File tree

6 files changed

+74
-34
lines changed

6 files changed

+74
-34
lines changed

lib/actions-util.js

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

lib/actions-util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.test.js

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

lib/actions-util.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.test.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ test("prepareEnvironment() when a local run", (t) => {
9090
t.deepEqual(process.env.CODEQL_ACTION_ANALYSIS_KEY, "LOCAL-RUN:UNKNOWN-JOB");
9191
});
9292

93-
test("validateWorkflow() when on.push is missing", (t) => {
93+
test("validateWorkflow() when on is empty", (t) => {
9494
const errors = actionsutil.validateWorkflow({ on: {} });
9595

9696
t.deepEqual(
97-
...errorCodes(errors, [actionsutil.WorkflowErrors.MissingPushHook])
97+
...errorCodes(errors, [])
9898
);
9999
});
100100

@@ -549,6 +549,45 @@ name: "CodeQL"
549549
t.deepEqual(...errorCodes(errors, []));
550550
});
551551

552+
test("validateWorkflow() with a different on setup", (t) => {
553+
t.deepEqual(
554+
...errorCodes(
555+
actionsutil.validateWorkflow(
556+
yaml.safeLoad(`
557+
name: "CodeQL"
558+
on: "workflow_dispatch"
559+
`)
560+
),
561+
[]
562+
)
563+
);
564+
565+
t.deepEqual(
566+
...errorCodes(
567+
actionsutil.validateWorkflow(
568+
yaml.safeLoad(`
569+
name: "CodeQL"
570+
on: [workflow_dispatch]
571+
`)
572+
),
573+
[]
574+
)
575+
);
576+
577+
t.deepEqual(
578+
...errorCodes(
579+
actionsutil.validateWorkflow(
580+
yaml.safeLoad(`
581+
name: "CodeQL"
582+
on:
583+
workflow_dispatch: {}
584+
`)
585+
),
586+
[]
587+
)
588+
);
589+
});
590+
552591
test("validateWorkflow() should not report an error if PRs are totally unconfigured", (t) => {
553592
t.deepEqual(
554593
...errorCodes(

src/actions-util.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,10 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
236236
let missing = MissingTriggers.None;
237237

238238
if (doc.on === undefined) {
239-
// codeql will scan the default branch
239+
// this is not a valid config
240240
} else if (typeof doc.on === "string") {
241-
switch (doc.on) {
242-
case "push":
243-
// valid configuration
244-
break;
245-
case "pull_request":
246-
missing = MissingTriggers.Push;
247-
break;
248-
default:
249-
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
250-
break;
241+
if (doc.on == "pull_request") {
242+
missing = MissingTriggers.Push;
251243
}
252244
} else if (Array.isArray(doc.on)) {
253245
const hasPush = doc.on.includes("push");
@@ -262,7 +254,7 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
262254
"pull_request"
263255
);
264256

265-
if (!hasPush) {
257+
if (!hasPush && hasPullRequest) {
266258
missing = missing | MissingTriggers.Push;
267259
}
268260
if (hasPush && hasPullRequest) {
@@ -279,8 +271,9 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
279271
}
280272
}
281273

282-
// check the user is scanning PRs right now
283-
// if not the warning does not apply
274+
// if doc.on.pull_request is null that means 'all branches'
275+
// if doc.on.pull_request is undefined that means 'off'
276+
// we only want to check for mismatched branches if pull_request is on.
284277
if (doc.on.pull_request !== undefined) {
285278
const push = branchesToArray(doc.on.push?.branches);
286279

0 commit comments

Comments
 (0)