mirror of
https://github.com/actions/labeler.git
synced 2025-12-12 20:51:42 +00:00
Update the matching to use a regexp rather than minimatch
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
test-branch:
|
test-branch:
|
||||||
- branch: "test/**"
|
- branch: "^test/"
|
||||||
|
|
||||||
feature-branch:
|
feature-branch:
|
||||||
- branch: "*/feature/*"
|
- branch: "/feature/"
|
||||||
|
|
||||||
bug-branch:
|
bug-branch:
|
||||||
- branch: "{bug,fix}/*"
|
- branch: "^bug/|fix/"
|
||||||
|
|
||||||
array-branch:
|
array-branch:
|
||||||
- branch: ["array/*"]
|
- branch: ["^array/"]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {Minimatch, IMinimatch} from 'minimatch';
|
|||||||
interface MatchConfig {
|
interface MatchConfig {
|
||||||
all?: string[];
|
all?: string[];
|
||||||
any?: string[];
|
any?: string[];
|
||||||
branch?: string | string[];
|
branch?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringOrMatchConfig = string | MatchConfig;
|
type StringOrMatchConfig = string | MatchConfig;
|
||||||
@@ -156,6 +156,11 @@ function toMatchConfig(config: StringOrMatchConfig): MatchConfig {
|
|||||||
return {
|
return {
|
||||||
any: [config]
|
any: [config]
|
||||||
};
|
};
|
||||||
|
} else if (typeof config.branch === 'string') {
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
branch: [config.branch]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
@@ -223,18 +228,18 @@ function checkAll(changedFiles: string[], globs: string[]): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchBranchPattern(matcher: IMinimatch, branchName: string): boolean {
|
function matchBranchPattern(matcher: RegExp, branchName: string): boolean {
|
||||||
core.debug(` - ${printPattern(matcher)}`);
|
core.debug(` - ${matcher}`);
|
||||||
if (matcher.match(branchName)) {
|
if (matcher.test(branchName)) {
|
||||||
core.debug(` "branch" pattern matched`);
|
core.debug(` "branch" pattern matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(` ${printPattern(matcher)} did not match`);
|
core.debug(` ${matcher} did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBranch(glob: string | string[]): boolean {
|
function checkBranch(glob: string[]): boolean {
|
||||||
const branchName = getHeadBranchName();
|
const branchName = getHeadBranchName();
|
||||||
if (!branchName) {
|
if (!branchName) {
|
||||||
core.debug(` no branch name`);
|
core.debug(` no branch name`);
|
||||||
@@ -242,21 +247,16 @@ function checkBranch(glob: string | string[]): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.debug(` checking "branch" pattern against ${branchName}`);
|
core.debug(` checking "branch" pattern against ${branchName}`);
|
||||||
if (Array.isArray(glob)) {
|
const matchers = glob.map(g => new RegExp(g));
|
||||||
const matchers = glob.map(g => new Minimatch(g));
|
for (const matcher of matchers) {
|
||||||
for (const matcher of matchers) {
|
if (matchBranchPattern(matcher, branchName)) {
|
||||||
if (matchBranchPattern(matcher, branchName)) {
|
core.debug(` "branch" patterns matched against ${branchName}`);
|
||||||
core.debug(` "branch" patterns matched against ${branchName}`);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(` "branch" patterns did not match against ${branchName}`);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
const matcher = new Minimatch(glob);
|
|
||||||
return matchBranchPattern(matcher, branchName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug(` "branch" patterns did not match against ${branchName}`);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user