Test the branch patterns work both ways
This commit is contained in:
parent
f99af1c014
commit
b1be00db57
6 changed files with 24 additions and 13 deletions
13
lib/actions-util.js
generated
13
lib/actions-util.js
generated
|
|
@ -120,16 +120,14 @@ function considerToken(a, b) {
|
|||
return { advance: a === b, consume: a === b };
|
||||
}
|
||||
}
|
||||
function patternsOverlap(patternA, patternB) {
|
||||
const patternATokens = tokenize(patternA);
|
||||
const patternBTokens = tokenize(patternB);
|
||||
function tokensMatch(tokensA, tokensB) {
|
||||
let indexA = 0;
|
||||
let indexB = 0;
|
||||
let advance;
|
||||
let consume = true;
|
||||
while (advance || consume) {
|
||||
const currentA = patternATokens[indexA];
|
||||
const currentB = patternBTokens[indexB];
|
||||
const currentA = tokensA[indexA];
|
||||
const currentB = tokensB[indexB];
|
||||
if (currentB === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -148,6 +146,11 @@ function patternsOverlap(patternA, patternB) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
function patternsOverlap(patternA, patternB) {
|
||||
const tokensA = tokenize(patternA);
|
||||
const tokensB = tokenize(patternB);
|
||||
return tokensMatch(tokensA, tokensB) && tokensMatch(tokensA.reverse(), tokensB.reverse());
|
||||
}
|
||||
exports.patternsOverlap = patternsOverlap;
|
||||
function branchesToArray(branches) {
|
||||
if (typeof branches === "string") {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
2
lib/actions-util.test.js
generated
2
lib/actions-util.test.js
generated
|
|
@ -223,6 +223,8 @@ ava_1.default("patternsOverlap()", (t) => {
|
|||
t.false(actionsutil.patternsOverlap("*", "feature/*"));
|
||||
t.true(actionsutil.patternsOverlap("**", "feature/*"));
|
||||
t.false(actionsutil.patternsOverlap("feature-*", "**"));
|
||||
t.false(actionsutil.patternsOverlap("a/**/c", "a/**/d"));
|
||||
t.false(actionsutil.patternsOverlap("a/**/c", "a/**"));
|
||||
t.true(actionsutil.patternsOverlap("/robin/*/release/*", "/robin/moose/release/goose"));
|
||||
t.false(actionsutil.patternsOverlap("/robin/moose/release/goose", "/robin/*/release/*"));
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -279,6 +279,8 @@ test("patternsOverlap()", (t) => {
|
|||
t.false(actionsutil.patternsOverlap("*", "feature/*"));
|
||||
t.true(actionsutil.patternsOverlap("**", "feature/*"));
|
||||
t.false(actionsutil.patternsOverlap("feature-*", "**"));
|
||||
t.false(actionsutil.patternsOverlap("a/**/c", "a/**/d"));
|
||||
t.false(actionsutil.patternsOverlap("a/**/c", "a/**"));
|
||||
t.true(
|
||||
actionsutil.patternsOverlap(
|
||||
"/robin/*/release/*",
|
||||
|
|
|
|||
|
|
@ -159,10 +159,7 @@ function considerToken(
|
|||
}
|
||||
}
|
||||
|
||||
export function patternsOverlap(patternA: string, patternB: string): boolean {
|
||||
const patternATokens = tokenize(patternA);
|
||||
const patternBTokens = tokenize(patternB);
|
||||
|
||||
function tokensMatch(tokensA: string[], tokensB: string[]) {
|
||||
let indexA = 0;
|
||||
let indexB = 0;
|
||||
|
||||
|
|
@ -170,8 +167,8 @@ export function patternsOverlap(patternA: string, patternB: string): boolean {
|
|||
let consume = true;
|
||||
|
||||
while (advance || consume) {
|
||||
const currentA = patternATokens[indexA];
|
||||
const currentB = patternBTokens[indexB];
|
||||
const currentA = tokensA[indexA];
|
||||
const currentB = tokensB[indexB];
|
||||
|
||||
if (currentB === undefined) {
|
||||
return true;
|
||||
|
|
@ -195,6 +192,13 @@ export function patternsOverlap(patternA: string, patternB: string): boolean {
|
|||
return false;
|
||||
}
|
||||
|
||||
export function patternsOverlap(patternA: string, patternB: string): boolean {
|
||||
const tokensA = tokenize(patternA);
|
||||
const tokensB = tokenize(patternB);
|
||||
|
||||
return tokensMatch(tokensA, tokensB) && tokensMatch(tokensA.reverse(), tokensB.reverse());
|
||||
}
|
||||
|
||||
function branchesToArray(branches?: string | null | string[]): string[] | "**" {
|
||||
if (typeof branches === "string") {
|
||||
return [branches];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue