mirror of
https://github.com/github/codeql-action.git
synced 2026-10-29 17:17:15 +00:00
Test the branch patterns work both ways
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user