Skip to content

Commit 4d86261

Browse files
author
Simon Engledew
committed
First iteration on feedback
1 parent 56b1ead commit 4d86261

7 files changed

Lines changed: 50 additions & 41 deletions

File tree

lib/actions-util.js

Lines changed: 5 additions & 5 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: 16 additions & 14 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: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,28 @@ test("formatWorkflowCause()", (t) => {
269269
t.deepEqual(actionsutil.formatWorkflowCause([]), undefined);
270270
});
271271

272-
test("patternsOverlap()", (t) => {
273-
t.false(actionsutil.patternsOverlap("main-*", "main"));
274-
t.true(actionsutil.patternsOverlap("*", "*"));
275-
t.true(actionsutil.patternsOverlap("*", "main-*"));
276-
t.false(actionsutil.patternsOverlap("main-*", "*"));
277-
t.false(actionsutil.patternsOverlap("main-*", "main"));
278-
t.true(actionsutil.patternsOverlap("main", "main"));
279-
t.false(actionsutil.patternsOverlap("*", "feature/*"));
280-
t.true(actionsutil.patternsOverlap("**", "feature/*"));
281-
t.false(actionsutil.patternsOverlap("feature-*", "**"));
282-
t.false(actionsutil.patternsOverlap("a/**/c", "a/**/d"));
283-
t.false(actionsutil.patternsOverlap("a/**/c", "a/**"));
272+
test("patternIsSuperset()", (t) => {
273+
t.false(actionsutil.patternIsSuperset("main-*", "main"));
274+
t.true(actionsutil.patternIsSuperset("*", "*"));
275+
t.true(actionsutil.patternIsSuperset("*", "main-*"));
276+
t.false(actionsutil.patternIsSuperset("main-*", "*"));
277+
t.false(actionsutil.patternIsSuperset("main-*", "main"));
278+
t.true(actionsutil.patternIsSuperset("main", "main"));
279+
t.false(actionsutil.patternIsSuperset("*", "feature/*"));
280+
t.true(actionsutil.patternIsSuperset("**", "feature/*"));
281+
t.false(actionsutil.patternIsSuperset("feature-*", "**"));
282+
t.false(actionsutil.patternIsSuperset("a/**/c", "a/**/d"));
283+
t.false(actionsutil.patternIsSuperset("a/**/c", "a/**"));
284+
t.true(actionsutil.patternIsSuperset("a/**/c", "a/main-**/c"));
285+
t.false(actionsutil.patternIsSuperset("a/main-**/c", "a/**/c"));
284286
t.true(
285-
actionsutil.patternsOverlap(
287+
actionsutil.patternIsSuperset(
286288
"/robin/*/release/*",
287289
"/robin/moose/release/goose"
288290
)
289291
);
290292
t.false(
291-
actionsutil.patternsOverlap(
293+
actionsutil.patternIsSuperset(
292294
"/robin/moose/release/goose",
293295
"/robin/*/release/*"
294296
)

src/actions-util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function considerToken(
159159
}
160160
}
161161

162-
function tokensMatch(tokensA: string[], tokensB: string[]) {
162+
function tokensAreSuperset(tokensA: string[], tokensB: string[]) {
163163
let indexA = 0;
164164
let indexB = 0;
165165

@@ -192,11 +192,11 @@ function tokensMatch(tokensA: string[], tokensB: string[]) {
192192
return false;
193193
}
194194

195-
export function patternsOverlap(patternA: string, patternB: string): boolean {
195+
export function patternIsSuperset(patternA: string, patternB: string): boolean {
196196
const tokensA = tokenize(patternA);
197197
const tokensB = tokenize(patternB);
198198

199-
return tokensMatch(tokensA, tokensB) && tokensMatch(tokensA.reverse(), tokensB.reverse());
199+
return tokensAreSuperset(tokensA, tokensB) && tokensAreSuperset(tokensA.reverse(), tokensB.reverse());
200200
}
201201

202202
function branchesToArray(branches?: string | null | string[]): string[] | "**" {
@@ -306,7 +306,7 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
306306

307307
if (pull_request !== "**") {
308308
const difference = pull_request.filter(
309-
(value) => !push.some((o) => patternsOverlap(o, value))
309+
(value) => !push.some((o) => patternIsSuperset(o, value))
310310
);
311311
if (difference.length > 0) {
312312
// there are branches in pull_request that may not have a baseline

src/init-action.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ async function run() {
9898

9999
const workflowErrors = await actionsUtil.getWorkflowErrors();
100100

101-
if (workflowErrors.filter(o => o.code !== 'LintFailed').length > 0) {
102-
core.warning(actionsUtil.formatWorkflowErrors(workflowErrors));
101+
// we do not want to worry users if linting is failing
102+
// but we do want to send a status report containing this error code
103+
// below
104+
const userWorkflowErrors = workflowErrors.filter(o => o.code !== 'LintFailed');
105+
106+
if (userWorkflowErrors.length > 0) {
107+
core.warning(actionsUtil.formatWorkflowErrors(userWorkflowErrors));
103108
}
104109

105110
if (

0 commit comments

Comments
 (0)