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
|
|
@ -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