mirror of
https://github.com/actions/labeler.git
synced 2025-12-15 06:27:13 +00:00
Add any and all functions for both checks
This commit is contained in:
@@ -40,7 +40,7 @@ export function getBranchName(branchBase: BranchBase): string | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
export function checkBranch(
|
||||
export function checkAnyBranch(
|
||||
regexps: string[],
|
||||
branchBase: BranchBase
|
||||
): boolean {
|
||||
@@ -63,6 +63,29 @@ export function checkBranch(
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkAllBranch(
|
||||
regexps: string[],
|
||||
branchBase: BranchBase
|
||||
): boolean {
|
||||
const branchName = getBranchName(branchBase);
|
||||
if (!branchName) {
|
||||
core.debug(` no branch name`);
|
||||
return false;
|
||||
}
|
||||
|
||||
core.debug(` checking "branch" pattern against ${branchName}`);
|
||||
const matchers = regexps.map(regexp => new RegExp(regexp));
|
||||
for (const matcher of matchers) {
|
||||
if (!matchBranchPattern(matcher, branchName)) {
|
||||
core.debug(` "branch" patterns matched against ${branchName}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "branch" patterns did not match against ${branchName}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
function matchBranchPattern(matcher: RegExp, branchName: string): boolean {
|
||||
core.debug(` - ${matcher}`);
|
||||
if (matcher.test(branchName)) {
|
||||
|
||||
@@ -64,7 +64,10 @@ function isMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
||||
}
|
||||
|
||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||
export function checkAny(changedFiles: string[], globs: string[]): boolean {
|
||||
export function checkAnyChangedFiles(
|
||||
changedFiles: string[],
|
||||
globs: string[]
|
||||
): boolean {
|
||||
const matchers = globs.map(g => new Minimatch(g));
|
||||
core.debug(` checking "any" patterns`);
|
||||
for (const changedFile of changedFiles) {
|
||||
@@ -79,7 +82,10 @@ export function checkAny(changedFiles: string[], globs: string[]): boolean {
|
||||
}
|
||||
|
||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||
export function checkAll(changedFiles: string[], globs: string[]): boolean {
|
||||
export function checkAllChangedFiles(
|
||||
changedFiles: string[],
|
||||
globs: string[]
|
||||
): boolean {
|
||||
const matchers = globs.map(g => new Minimatch(g));
|
||||
core.debug(` checking "all" patterns`);
|
||||
for (const changedFile of changedFiles) {
|
||||
|
||||
@@ -5,9 +5,16 @@ import * as yaml from 'js-yaml';
|
||||
import {
|
||||
ChangedFilesMatchConfig,
|
||||
getChangedFiles,
|
||||
toChangedFilesMatchConfig
|
||||
toChangedFilesMatchConfig,
|
||||
checkAllChangedFiles,
|
||||
checkAnyChangedFiles
|
||||
} from './changedFiles';
|
||||
import {checkBranch, toBranchMatchConfig, BranchMatchConfig} from './branch';
|
||||
import {
|
||||
checkAnyBranch,
|
||||
checkAllBranch,
|
||||
toBranchMatchConfig,
|
||||
BranchMatchConfig
|
||||
} from './branch';
|
||||
|
||||
export type BaseMatchConfig = BranchMatchConfig & ChangedFilesMatchConfig;
|
||||
|
||||
@@ -215,24 +222,24 @@ function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||
export function checkAny(
|
||||
matchConfigs: BaseMatchConfig[],
|
||||
_changedFiles: string[]
|
||||
changedFiles: string[]
|
||||
): boolean {
|
||||
core.debug(` checking "any" patterns`);
|
||||
for (const matchConfig of matchConfigs) {
|
||||
if (matchConfig.baseBranch) {
|
||||
if (checkBranch(matchConfig.baseBranch, 'base')) {
|
||||
if (checkAnyBranch(matchConfig.baseBranch, 'base')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// if (matchConfig.changedFiles) {
|
||||
// if (checkFiles(matchConfig.changedFiles, changedFiles)) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
if (matchConfig.changedFiles) {
|
||||
if (checkAnyChangedFiles(changedFiles, matchConfig.changedFiles)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.headBranch) {
|
||||
if (checkBranch(matchConfig.headBranch, 'head')) {
|
||||
if (checkAnyBranch(matchConfig.headBranch, 'head')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -245,24 +252,24 @@ export function checkAny(
|
||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||
export function checkAll(
|
||||
matchConfigs: BaseMatchConfig[],
|
||||
_changedFiles: string[]
|
||||
changedFiles: string[]
|
||||
): boolean {
|
||||
core.debug(` checking "all" patterns`);
|
||||
for (const matchConfig of matchConfigs) {
|
||||
if (matchConfig.baseBranch) {
|
||||
if (!checkBranch(matchConfig.baseBranch, 'base')) {
|
||||
if (!checkAllBranch(matchConfig.baseBranch, 'base')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// if (matchConfig.changedFiles) {
|
||||
// if (checkFiles(matchConfig.changedFiles, changedFiles)) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
if (matchConfig.changedFiles) {
|
||||
if (checkAllChangedFiles(changedFiles, matchConfig.changedFiles)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.headBranch) {
|
||||
if (!checkBranch(matchConfig.headBranch, 'head')) {
|
||||
if (!checkAllBranch(matchConfig.headBranch, 'head')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user