Skip to content

Commit 44ed1c6

Browse files
author
Simon Engledew
committed
Remove pull request warnings
1 parent 7400463 commit 44ed1c6

File tree

6 files changed

+33
-74
lines changed

6 files changed

+33
-74
lines changed

lib/actions-util.js

Lines changed: 6 additions & 27 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: 9 additions & 9 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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
232232
actionsutil.getWorkflowErrors({
233233
on: 1,
234234
} as any),
235-
[actionsutil.WorkflowErrors.MissingHooks]
235+
[]
236236
)
237237
);
238238

@@ -242,7 +242,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
242242
on: 1,
243243
jobs: 1,
244244
} as any),
245-
[actionsutil.WorkflowErrors.MissingHooks]
245+
[]
246246
)
247247
);
248248

@@ -252,7 +252,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
252252
on: 1,
253253
jobs: [1],
254254
} as any),
255-
[actionsutil.WorkflowErrors.MissingHooks]
255+
[]
256256
)
257257
);
258258

@@ -262,7 +262,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
262262
on: 1,
263263
jobs: { 1: 1 },
264264
} as any),
265-
[actionsutil.WorkflowErrors.MissingHooks]
265+
[]
266266
)
267267
);
268268

@@ -272,7 +272,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
272272
on: 1,
273273
jobs: { test: 1 },
274274
} as any),
275-
[actionsutil.WorkflowErrors.MissingHooks]
275+
[]
276276
)
277277
);
278278

@@ -282,7 +282,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
282282
on: 1,
283283
jobs: { test: [1] },
284284
} as any),
285-
[actionsutil.WorkflowErrors.MissingHooks]
285+
[]
286286
)
287287
);
288288

@@ -292,7 +292,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
292292
on: 1,
293293
jobs: { test: { steps: 1 } },
294294
} as any),
295-
[actionsutil.WorkflowErrors.MissingHooks]
295+
[]
296296
)
297297
);
298298

@@ -302,7 +302,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
302302
on: 1,
303303
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
304304
} as any),
305-
[actionsutil.WorkflowErrors.MissingHooks]
305+
[]
306306
)
307307
);
308308

@@ -312,7 +312,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
312312
on: 1,
313313
jobs: { test: [undefined] },
314314
} as any),
315-
[actionsutil.WorkflowErrors.MissingHooks]
315+
[]
316316
)
317317
);
318318

src/actions-util.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,11 @@ function branchesToArray(branches?: string | null | string[]): string[] | "**" {
177177
}
178178
return "**";
179179
}
180-
181-
enum MissingTriggers {
182-
None = 0,
183-
Push = 1,
184-
PullRequest = 2,
185-
}
186-
187180
export interface CodedError {
188181
message: string;
189182
code: string;
190183
}
184+
191185
function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
192186
return Object.entries(errors).reduce((acc, [key, value]) => {
193187
acc[key] = { message: value, code: key };
@@ -199,8 +193,6 @@ function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
199193
// message to add as a warning annotation to the run
200194
export const WorkflowErrors = toCodedErrors({
201195
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
202-
MissingHooks: `Please specify on.push and on.pull_request hooks so that Code Scanning can compare pull requests against the state of the base branch.`,
203-
MissingPullRequestHook: `Please specify an on.pull_request hook so that Code Scanning is explicitly run against pull requests. This will be required to see results on pull requests from January 31 2021.`,
204196
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
205197
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
206198
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
@@ -232,19 +224,19 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
232224
}
233225
}
234226

235-
let missing = MissingTriggers.None;
227+
let missingPush = false;
236228

237229
if (doc.on === undefined) {
238230
// this is not a valid config
239231
} else if (typeof doc.on === "string") {
240232
if (doc.on === "pull_request") {
241-
missing = MissingTriggers.Push;
233+
missingPush = true;
242234
}
243235
} else if (Array.isArray(doc.on)) {
244236
const hasPush = doc.on.includes("push");
245237
const hasPullRequest = doc.on.includes("pull_request");
246238
if (hasPullRequest && !hasPush) {
247-
missing = missing | MissingTriggers.Push;
239+
missingPush = true;
248240
}
249241
} else if (isObject(doc.on)) {
250242
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
@@ -254,7 +246,7 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
254246
);
255247

256248
if (!hasPush && hasPullRequest) {
257-
missing = missing | MissingTriggers.Push;
249+
missingPush = true;
258250
}
259251
if (hasPush && hasPullRequest) {
260252
const paths = doc.on.push?.paths;
@@ -295,22 +287,10 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
295287
}
296288
}
297289
}
298-
} else {
299-
// on is not a known type
300-
// this workflow is likely malformed
301-
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
302290
}
303291

304-
switch (missing) {
305-
case MissingTriggers.PullRequest | MissingTriggers.Push:
306-
errors.push(WorkflowErrors.MissingHooks);
307-
break;
308-
case MissingTriggers.PullRequest:
309-
errors.push(WorkflowErrors.MissingPullRequestHook);
310-
break;
311-
case MissingTriggers.Push:
312-
errors.push(WorkflowErrors.MissingPushHook);
313-
break;
292+
if (missingPush) {
293+
errors.push(WorkflowErrors.MissingPushHook);
314294
}
315295

316296
return errors;

0 commit comments

Comments
 (0)