From e51b118725500b72d92b7c7f76b8545057e53118 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Fri, 24 Mar 2023 21:08:59 -0400 Subject: [PATCH 01/19] Change the structure of the config --- src/changedFiles.ts | 60 +++------------------ src/labeler.ts | 125 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 114 insertions(+), 71 deletions(-) diff --git a/src/changedFiles.ts b/src/changedFiles.ts index 0b8da0f8..526977e6 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -3,10 +3,7 @@ import * as github from '@actions/github'; import {Minimatch} from 'minimatch'; export interface ChangedFilesMatchConfig { - changedFiles?: { - all?: string[]; - any?: string[]; - }; + changedFiles?: string[]; } type ClientType = ReturnType; @@ -35,60 +32,17 @@ export async function getChangedFiles( export function toChangedFilesMatchConfig( config: any ): ChangedFilesMatchConfig { - if (!config['changed-files']) { + if (!config['changed-files'] || !config['changed-files'].length) { return {}; } + const changedFilesConfig = config['changed-files']; - // If the value provided is a string or an array of strings then default to `any` matching - if (typeof changedFilesConfig === 'string') { - return { - changedFiles: { - any: [changedFilesConfig] - } - }; - } - - const changedFilesMatchConfig = { - changedFiles: {} + return { + changedFiles: Array.isArray(changedFilesConfig) + ? changedFilesConfig + : [changedFilesConfig] }; - - if (Array.isArray(changedFilesConfig)) { - if ( - changedFilesConfig.length && - changedFilesConfig.every(entry => typeof entry === 'string') - ) { - changedFilesMatchConfig.changedFiles = { - any: changedFilesConfig - }; - } else { - // If it is not an array of strings then it should be array of further config options - // so assign them to our `changedFilesMatchConfig` - changedFilesMatchConfig.changedFiles = changedFilesConfig.reduce( - (updatedMatchConfig, configValue) => { - if (!configValue) { - return updatedMatchConfig; - } - - Object.entries(configValue).forEach(([key, value]) => { - if (key === 'any' || key === 'all') { - updatedMatchConfig[key] = Array.isArray(value) ? value : [value]; - } - }); - - return updatedMatchConfig; - }, - {} - ); - } - } - - // If no items were added to `changedFiles` then return an empty object - if (!Object.keys(changedFilesMatchConfig.changedFiles).length) { - return {}; - } - - return changedFilesMatchConfig; } function printPattern(matcher: Minimatch): string { diff --git a/src/labeler.ts b/src/labeler.ts index 8ea24d29..3fb95495 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -5,13 +5,16 @@ import * as yaml from 'js-yaml'; import { ChangedFilesMatchConfig, getChangedFiles, - toChangedFilesMatchConfig, - checkAny, - checkAll + toChangedFilesMatchConfig } from './changedFiles'; import {checkBranch, toBranchMatchConfig, BranchMatchConfig} from './branch'; -export type MatchConfig = ChangedFilesMatchConfig & BranchMatchConfig; +export type BaseMatchConfig = BranchMatchConfig & ChangedFilesMatchConfig; + +export type MatchConfig = { + any?: BaseMatchConfig[]; + all?: BaseMatchConfig[]; +}; type ClientType = ReturnType; @@ -105,7 +108,7 @@ async function fetchContent( return Buffer.from(response.data.content, response.data.encoding).toString(); } -function getLabelConfigMapFromObject( +export function getLabelConfigMapFromObject( configObject: any ): Map { const labelMap: Map = new Map(); @@ -119,15 +122,51 @@ function getLabelConfigMapFromObject( `found unexpected type for label ${label} (should be array of config options)` ); } + const matchConfigs = configOptions.reduce( + (updatedConfig, configValue) => { + if (!configValue) { + return updatedConfig; + } + + Object.entries(configValue).forEach(([key, value]) => { + // If the top level `any` or `all` keys are provided then set them, and convert their values to + // our config objects. + if (key === 'any' || key === 'all') { + if (Array.isArray(value)) { + const newConfigs = value.map(toMatchConfig); + updatedConfig.push({[key]: newConfigs}); + } + } else if ( + // These are the keys that we accept and know how to process + ['changed-files', 'head-branch', 'base-branch'].includes(key) + ) { + const newMatchConfig = toMatchConfig({[key]: value}); + // Find or set the `any` key so that we can add these properties to that rule, + // Or create a new `any` key and add that to our array of configs. + const indexOfAny = updatedConfig.findIndex(mc => !!mc['any']); + if (indexOfAny >= 0) { + updatedConfig[indexOfAny].any?.push(newMatchConfig); + } else { + updatedConfig.push({any: [newMatchConfig]}); + } + } else { + // Log the key that we don't know what to do with. + core.info(`An unknown config option was under ${label}: ${key}`); + } + }); + + return updatedConfig; + }, + [] + ); - const matchConfigs = configOptions.map(toMatchConfig); labelMap.set(label, matchConfigs); } return labelMap; } -export function toMatchConfig(config: any): MatchConfig { +export function toMatchConfig(config: any): BaseMatchConfig { const changedFilesConfig = toChangedFilesMatchConfig(config); const branchConfig = toBranchMatchConfig(config); @@ -156,30 +195,80 @@ function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { return false; } - if (matchConfig.changedFiles?.all) { - if (!checkAll(changedFiles, matchConfig.changedFiles.all)) { + if (matchConfig.all) { + // check the options and if anything fails then return false + if (!checkAll(matchConfig.all, changedFiles)) { return false; } } - if (matchConfig.changedFiles?.any) { - if (!checkAny(changedFiles, matchConfig.changedFiles.any)) { - return false; + if (matchConfig.any) { + // Check all the various options if any pass return true + if (checkAny(matchConfig.any, changedFiles)) { + return true; } } - if (matchConfig.headBranch) { - if (!checkBranch(matchConfig.headBranch, 'head')) { - return false; + return true; +} + +// equivalent to "Array.some()" but expanded for debugging and clarity +export function checkAny( + matchConfigs: BaseMatchConfig[], + _changedFiles: string[] +): boolean { + core.debug(` checking "any" patterns`); + for (const matchConfig of matchConfigs) { + if (matchConfig.baseBranch) { + if (checkBranch(matchConfig.baseBranch, 'base')) { + return true; + } + } + + // if (matchConfig.changedFiles) { + // if (checkFiles(matchConfig.changedFiles, changedFiles)) { + // return true; + // } + // } + + if (matchConfig.headBranch) { + if (checkBranch(matchConfig.headBranch, 'head')) { + return true; + } } } - if (matchConfig.baseBranch) { - if (!checkBranch(matchConfig.baseBranch, 'base')) { - return false; + core.debug(` "any" patterns did not match any configs`); + return false; +} + +// equivalent to "Array.every()" but expanded for debugging and clarity +export function checkAll( + matchConfigs: BaseMatchConfig[], + _changedFiles: string[] +): boolean { + core.debug(` checking "all" patterns`); + for (const matchConfig of matchConfigs) { + if (matchConfig.baseBranch) { + if (!checkBranch(matchConfig.baseBranch, 'base')) { + return false; + } + } + + // if (matchConfig.changedFiles) { + // if (checkFiles(matchConfig.changedFiles, changedFiles)) { + // return true; + // } + // } + + if (matchConfig.headBranch) { + if (!checkBranch(matchConfig.headBranch, 'head')) { + return false; + } } } + core.debug(` "all" patterns matched all files`); return true; } From a9e07ce8ffdac59ef2f3becf3404a61ab4987bd0 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Fri, 24 Mar 2023 21:09:16 -0400 Subject: [PATCH 02/19] Add some new tests --- __tests__/changedFiles.test.ts | 102 ++++------------------------- __tests__/fixtures/all_options.yml | 14 ++++ __tests__/fixtures/only_pdfs.yml | 3 +- __tests__/labeler.test.ts | 63 +++++++++++++++--- 4 files changed, 81 insertions(+), 101 deletions(-) create mode 100644 __tests__/fixtures/all_options.yml diff --git a/__tests__/changedFiles.test.ts b/__tests__/changedFiles.test.ts index d529b82f..9efa2193 100644 --- a/__tests__/changedFiles.test.ts +++ b/__tests__/changedFiles.test.ts @@ -63,72 +63,13 @@ describe('toChangedFilesMatchConfig', () => { }); describe(`when there is a 'changed-files' key in the config`, () => { - describe(`and both 'any' and 'all' keys are present`, () => { - const config = {'changed-files': [{all: 'testing'}, {any: 'testing'}]}; + describe('and the value is an array of strings', () => { + const config = {'changed-files': ['testing']}; - it('sets both values in the config object', () => { + it('sets the value in the config object', () => { const result = toChangedFilesMatchConfig(config); expect(result).toEqual({ - changedFiles: { - any: ['testing'], - all: ['testing'] - } - }); - }); - }); - - describe(`and it contains a 'all' key`, () => { - describe('with a value of a string', () => { - const config = {'changed-files': [{all: 'testing'}]}; - - it('sets the value to be an array of strings in the config object', () => { - const result = toChangedFilesMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - all: ['testing'] - } - }); - }); - }); - - describe('with a value of an array of strings', () => { - const config = {'changed-files': [{all: ['testing']}]}; - - it('sets the value in the config object', () => { - const result = toChangedFilesMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - all: ['testing'] - } - }); - }); - }); - }); - - describe(`and it contains a 'any' key`, () => { - describe('with a value of a string', () => { - const config = {'changed-files': [{any: 'testing'}]}; - - it('sets the value to be an array of strings on the config object', () => { - const result = toChangedFilesMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - any: ['testing'] - } - }); - }); - }); - - describe('with a value of an array of strings', () => { - const config = {'changed-files': [{any: ['testing']}]}; - - it('sets the value in the config object', () => { - const result = toChangedFilesMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - any: ['testing'] - } - }); + changedFiles: ['testing'] }); }); }); @@ -136,31 +77,16 @@ describe('toChangedFilesMatchConfig', () => { describe('and the value is a string', () => { const config = {'changed-files': 'testing'}; - it(`sets the string as an array under an 'any' key`, () => { + it(`sets the string as an array in the config object`, () => { const result = toChangedFilesMatchConfig(config); expect(result).toEqual({ - changedFiles: { - any: ['testing'] - } + changedFiles: ['testing'] }); }); }); - describe('and the value is an array of strings', () => { - const config = {'changed-files': ['testing']}; - - it(`sets the array under an 'any' key`, () => { - const result = toChangedFilesMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - any: ['testing'] - } - }); - }); - }); - - describe('but it has empty values', () => { - const config = {'changed-files': []}; + describe('but the value is an empty string', () => { + const config = {'changed-files': ''}; it(`returns an empty object`, () => { const result = toChangedFilesMatchConfig(config); @@ -168,16 +94,12 @@ describe('toChangedFilesMatchConfig', () => { }); }); - describe('and there is an unknown value in the config', () => { - const config = {'changed-files': [{any: 'testing'}, {sneaky: 'test'}]}; + describe('but the value is an empty array', () => { + const config = {'changed-files': []}; - it(`does not set the value in the match config`, () => { + it(`returns an empty object`, () => { const result = toChangedFilesMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - any: ['testing'] - } - }); + expect(result).toEqual({}); }); }); }); diff --git a/__tests__/fixtures/all_options.yml b/__tests__/fixtures/all_options.yml new file mode 100644 index 00000000..f4d5ecc5 --- /dev/null +++ b/__tests__/fixtures/all_options.yml @@ -0,0 +1,14 @@ +label1: + - any: + - changed-files: ['glob'] + - head-branch: ['regexp'] + - base-branch: ['regexp'] + - all: + - changed-files: ['glob'] + - head-branch: ['regexp'] + - base-branch: ['regexp'] + +label2: + - changed-files: ['glob'] + - head-branch: ['regexp'] + - base-branch: ['regexp'] diff --git a/__tests__/fixtures/only_pdfs.yml b/__tests__/fixtures/only_pdfs.yml index 2909dce7..a645acfc 100644 --- a/__tests__/fixtures/only_pdfs.yml +++ b/__tests__/fixtures/only_pdfs.yml @@ -1,3 +1,2 @@ touched-a-pdf-file: - - changed-files: - - any: ['*.pdf'] + - changed-files: ['*.pdf'] diff --git a/__tests__/labeler.test.ts b/__tests__/labeler.test.ts index 28768651..d5ac569b 100644 --- a/__tests__/labeler.test.ts +++ b/__tests__/labeler.test.ts @@ -1,6 +1,13 @@ -import {checkMatchConfigs, MatchConfig, toMatchConfig} from '../src/labeler'; - +import { + checkMatchConfigs, + MatchConfig, + toMatchConfig, + getLabelConfigMapFromObject, + BaseMatchConfig +} from '../src/labeler'; +import * as yaml from 'js-yaml'; import * as core from '@actions/core'; +import * as fs from 'fs'; jest.mock('@actions/core'); @@ -10,18 +17,56 @@ beforeAll(() => { }); }); +const loadYaml = (filepath: string) => { + const loadedFile = fs.readFileSync(filepath); + const content = Buffer.from(loadedFile).toString(); + return yaml.load(content); +}; + +describe('getLabelConfigMapFromObject', () => { + const yamlObject = loadYaml('__tests__/fixtures/all_options.yml'); + const expected = new Map(); + expected.set('label1', [ + { + any: [ + {changedFiles: ['glob']}, + {baseBranch: undefined, headBranch: ['regexp']}, + {baseBranch: ['regexp'], headBranch: undefined} + ] + }, + { + all: [ + {changedFiles: ['glob']}, + {baseBranch: undefined, headBranch: ['regexp']}, + {baseBranch: ['regexp'], headBranch: undefined} + ] + } + ]); + expected.set('label2', [ + { + any: [ + {changedFiles: ['glob']}, + {baseBranch: undefined, headBranch: ['regexp']}, + {baseBranch: ['regexp'], headBranch: undefined} + ] + } + ]); + + it('returns a MatchConfig', () => { + const result = getLabelConfigMapFromObject(yamlObject); + expect(result).toEqual(expected); + }); +}); + describe('toMatchConfig', () => { describe('when all expected config options are present', () => { const config = { - 'changed-files': [{any: ['testing-any']}, {all: ['testing-all']}], + 'changed-files': ['testing-files'], 'head-branch': ['testing-head'], 'base-branch': ['testing-base'] }; - const expected: MatchConfig = { - changedFiles: { - all: ['testing-all'], - any: ['testing-any'] - }, + const expected: BaseMatchConfig = { + changedFiles: ['testing-files'], headBranch: ['testing-head'], baseBranch: ['testing-base'] }; @@ -43,7 +88,7 @@ describe('toMatchConfig', () => { }); describe('checkMatchConfigs', () => { - const matchConfig: MatchConfig[] = [{changedFiles: {any: ['*.txt']}}]; + const matchConfig: MatchConfig[] = [{any: [{changedFiles: ['*.txt']}]}]; it('returns true when our pattern does match changed files', () => { const changedFiles = ['foo.txt', 'bar.txt']; From 3bec9227d184c7576c616843e68fa18107c84ee6 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Fri, 24 Mar 2023 21:44:26 -0400 Subject: [PATCH 03/19] Add any and all functions for both checks --- __tests__/branch.test.ts | 16 ++++++------- __tests__/changedFiles.test.ts | 16 ++++++------- src/branch.ts | 25 +++++++++++++++++++- src/changedFiles.ts | 10 ++++++-- src/labeler.ts | 43 ++++++++++++++++++++-------------- 5 files changed, 73 insertions(+), 37 deletions(-) diff --git a/__tests__/branch.test.ts b/__tests__/branch.test.ts index 1085c1b2..d9c904cf 100644 --- a/__tests__/branch.test.ts +++ b/__tests__/branch.test.ts @@ -1,6 +1,6 @@ import { getBranchName, - checkBranch, + checkAnyBranch, toBranchMatchConfig, BranchMatchConfig } from '../src/branch'; @@ -25,7 +25,7 @@ describe('getBranchName', () => { }); }); -describe('checkBranch', () => { +describe('checkAnyBranch', () => { beforeEach(() => { github.context.payload.pull_request!.head = { ref: 'test/feature/123' @@ -38,14 +38,14 @@ describe('checkBranch', () => { describe('when a single pattern is provided', () => { describe('and the pattern matches the head branch', () => { it('returns true', () => { - const result = checkBranch(['^test'], 'head'); + const result = checkAnyBranch(['^test'], 'head'); expect(result).toBe(true); }); }); describe('and the pattern does not match the head branch', () => { it('returns false', () => { - const result = checkBranch(['^feature/'], 'head'); + const result = checkAnyBranch(['^feature/'], 'head'); expect(result).toBe(false); }); }); @@ -54,21 +54,21 @@ describe('checkBranch', () => { describe('when multiple patterns are provided', () => { describe('and at least one pattern matches', () => { it('returns true', () => { - const result = checkBranch(['^test/', '^feature/'], 'head'); + const result = checkAnyBranch(['^test/', '^feature/'], 'head'); expect(result).toBe(true); }); }); describe('and all patterns match', () => { it('returns true', () => { - const result = checkBranch(['^test/', '/feature/'], 'head'); + const result = checkAnyBranch(['^test/', '/feature/'], 'head'); expect(result).toBe(true); }); }); describe('and no patterns match', () => { it('returns false', () => { - const result = checkBranch(['^feature/', '/test$'], 'head'); + const result = checkAnyBranch(['^feature/', '/test$'], 'head'); expect(result).toBe(false); }); }); @@ -77,7 +77,7 @@ describe('checkBranch', () => { describe('when the branch to check is specified as the base branch', () => { describe('and the pattern matches the base branch', () => { it('returns true', () => { - const result = checkBranch(['^main$'], 'base'); + const result = checkAnyBranch(['^main$'], 'base'); expect(result).toBe(true); }); }); diff --git a/__tests__/changedFiles.test.ts b/__tests__/changedFiles.test.ts index 9efa2193..983b0e75 100644 --- a/__tests__/changedFiles.test.ts +++ b/__tests__/changedFiles.test.ts @@ -1,21 +1,21 @@ import { ChangedFilesMatchConfig, - checkAll, - checkAny, + checkAllChangedFiles, + checkAnyChangedFiles, toChangedFilesMatchConfig } from '../src/changedFiles'; jest.mock('@actions/core'); jest.mock('@actions/github'); -describe('checkAll', () => { +describe('checkAllChangedFiles', () => { const changedFiles = ['foo.txt', 'bar.txt']; describe('when the globs match every file that has changed', () => { const globs = ['*.txt']; it('returns true', () => { - const result = checkAll(changedFiles, globs); + const result = checkAllChangedFiles(changedFiles, globs); expect(result).toBe(true); }); }); @@ -24,20 +24,20 @@ describe('checkAll', () => { const globs = ['foo.txt']; it('returns false', () => { - const result = checkAll(changedFiles, globs); + const result = checkAllChangedFiles(changedFiles, globs); expect(result).toBe(false); }); }); }); -describe('checkAny', () => { +describe('checkAnyChangedFiles', () => { const changedFiles = ['foo.txt', 'bar.txt']; describe('when the globs match any of the files that have changed', () => { const globs = ['foo.txt']; it('returns true', () => { - const result = checkAny(changedFiles, globs); + const result = checkAnyChangedFiles(changedFiles, globs); expect(result).toBe(true); }); }); @@ -46,7 +46,7 @@ describe('checkAny', () => { const globs = ['*.md']; it('returns false', () => { - const result = checkAny(changedFiles, globs); + const result = checkAnyChangedFiles(changedFiles, globs); expect(result).toBe(false); }); }); diff --git a/src/branch.ts b/src/branch.ts index a8609608..39ccce0e 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -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)) { diff --git a/src/changedFiles.ts b/src/changedFiles.ts index 526977e6..d82877b8 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -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) { diff --git a/src/labeler.ts b/src/labeler.ts index 3fb95495..ec0da0d2 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -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; } } From 432b275f711b9f2208011042fc6a3a484c058f6a Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Fri, 24 Mar 2023 22:29:41 -0400 Subject: [PATCH 04/19] Get all the tests passings --- src/changedFiles.ts | 2 -- src/labeler.ts | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/changedFiles.ts b/src/changedFiles.ts index d82877b8..70dbcb0a 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -63,7 +63,6 @@ function isMatch(changedFile: string, matchers: Minimatch[]): boolean { return true; } -// equivalent to "Array.some()" but expanded for debugging and clarity export function checkAnyChangedFiles( changedFiles: string[], globs: string[] @@ -81,7 +80,6 @@ export function checkAnyChangedFiles( return false; } -// equivalent to "Array.every()" but expanded for debugging and clarity export function checkAllChangedFiles( changedFiles: string[], globs: string[] diff --git a/src/labeler.ts b/src/labeler.ts index ec0da0d2..328d120a 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -167,7 +167,9 @@ export function getLabelConfigMapFromObject( [] ); - labelMap.set(label, matchConfigs); + if (matchConfigs.length) { + labelMap.set(label, matchConfigs); + } } return labelMap; @@ -203,16 +205,14 @@ function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { } if (matchConfig.all) { - // check the options and if anything fails then return false if (!checkAll(matchConfig.all, changedFiles)) { return false; } } if (matchConfig.any) { - // Check all the various options if any pass return true - if (checkAny(matchConfig.any, changedFiles)) { - return true; + if (!checkAny(matchConfig.any, changedFiles)) { + return false; } } @@ -225,6 +225,11 @@ export function checkAny( changedFiles: string[] ): boolean { core.debug(` checking "any" patterns`); + if (!Object.keys(matchConfigs).length) { + core.debug(` no "any" patterns to check`); + return false; + } + for (const matchConfig of matchConfigs) { if (matchConfig.baseBranch) { if (checkAnyBranch(matchConfig.baseBranch, 'base')) { @@ -255,6 +260,11 @@ export function checkAll( changedFiles: string[] ): boolean { core.debug(` checking "all" patterns`); + if (!Object.keys(matchConfigs).length) { + core.debug(` no "all" patterns to check`); + return false; + } + for (const matchConfig of matchConfigs) { if (matchConfig.baseBranch) { if (!checkAllBranch(matchConfig.baseBranch, 'base')) { From 49676461cbd3a75736d5afd2baa5352ff07c89b1 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Fri, 24 Mar 2023 22:29:57 -0400 Subject: [PATCH 05/19] Run the build command --- dist/index.js | 198 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 131 insertions(+), 67 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5f074481..fda0b69d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30,7 +30,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.checkBranch = exports.getBranchName = exports.toBranchMatchConfig = void 0; +exports.checkAllBranch = exports.checkAnyBranch = exports.getBranchName = exports.toBranchMatchConfig = void 0; const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); function toBranchMatchConfig(config) { @@ -63,7 +63,7 @@ function getBranchName(branchBase) { } } exports.getBranchName = getBranchName; -function checkBranch(regexps, branchBase) { +function checkAnyBranch(regexps, branchBase) { const branchName = getBranchName(branchBase); if (!branchName) { core.debug(` no branch name`); @@ -80,7 +80,25 @@ function checkBranch(regexps, branchBase) { core.debug(` "branch" patterns did not match against ${branchName}`); return false; } -exports.checkBranch = checkBranch; +exports.checkAnyBranch = checkAnyBranch; +function checkAllBranch(regexps, branchBase) { + 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; +} +exports.checkAllBranch = checkAllBranch; function matchBranchPattern(matcher, branchName) { core.debug(` - ${matcher}`); if (matcher.test(branchName)) { @@ -132,7 +150,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.checkAll = exports.checkAny = exports.toChangedFilesMatchConfig = exports.getChangedFiles = void 0; +exports.checkAllChangedFiles = exports.checkAnyChangedFiles = exports.toChangedFilesMatchConfig = exports.getChangedFiles = void 0; const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); const minimatch_1 = __nccwpck_require__(2002); @@ -154,49 +172,15 @@ function getChangedFiles(client, prNumber) { } exports.getChangedFiles = getChangedFiles; function toChangedFilesMatchConfig(config) { - if (!config['changed-files']) { + if (!config['changed-files'] || !config['changed-files'].length) { return {}; } const changedFilesConfig = config['changed-files']; - // If the value provided is a string or an array of strings then default to `any` matching - if (typeof changedFilesConfig === 'string') { - return { - changedFiles: { - any: [changedFilesConfig] - } - }; - } - const changedFilesMatchConfig = { - changedFiles: {} + return { + changedFiles: Array.isArray(changedFilesConfig) + ? changedFilesConfig + : [changedFilesConfig] }; - if (Array.isArray(changedFilesConfig)) { - if (changedFilesConfig.length && - changedFilesConfig.every(entry => typeof entry === 'string')) { - changedFilesMatchConfig.changedFiles = { - any: changedFilesConfig - }; - } - else { - // If it is not an array of strings then it should be array of further config options - // so assign them to our `changedFilesMatchConfig` - changedFilesMatchConfig.changedFiles = changedFilesConfig.reduce((updatedMatchConfig, configValue) => { - if (!configValue) { - return updatedMatchConfig; - } - Object.entries(configValue).forEach(([key, value]) => { - if (key === 'any' || key === 'all') { - updatedMatchConfig[key] = Array.isArray(value) ? value : [value]; - } - }); - return updatedMatchConfig; - }, {}); - } - } - // If no items were added to `changedFiles` then return an empty object - if (!Object.keys(changedFilesMatchConfig.changedFiles).length) { - return {}; - } - return changedFilesMatchConfig; } exports.toChangedFilesMatchConfig = toChangedFilesMatchConfig; function printPattern(matcher) { @@ -214,8 +198,7 @@ function isMatch(changedFile, matchers) { core.debug(` all patterns matched`); return true; } -// equivalent to "Array.some()" but expanded for debugging and clarity -function checkAny(changedFiles, globs) { +function checkAnyChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { @@ -227,9 +210,8 @@ function checkAny(changedFiles, globs) { core.debug(` "any" patterns did not match any files`); return false; } -exports.checkAny = checkAny; -// equivalent to "Array.every()" but expanded for debugging and clarity -function checkAll(changedFiles, globs) { +exports.checkAnyChangedFiles = checkAnyChangedFiles; +function checkAllChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { @@ -241,7 +223,7 @@ function checkAll(changedFiles, globs) { core.debug(` "all" patterns matched all files`); return true; } -exports.checkAll = checkAll; +exports.checkAllChangedFiles = checkAllChangedFiles; /***/ }), @@ -284,7 +266,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.checkMatchConfigs = exports.toMatchConfig = exports.run = void 0; +exports.checkAll = exports.checkAny = exports.checkMatchConfigs = exports.toMatchConfig = exports.getLabelConfigMapFromObject = exports.run = void 0; const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); const yaml = __importStar(__nccwpck_require__(1917)); @@ -370,11 +352,48 @@ function getLabelConfigMapFromObject(configObject) { !configOptions.every(opts => typeof opts === 'object')) { throw Error(`found unexpected type for label ${label} (should be array of config options)`); } - const matchConfigs = configOptions.map(toMatchConfig); - labelMap.set(label, matchConfigs); + const matchConfigs = configOptions.reduce((updatedConfig, configValue) => { + if (!configValue) { + return updatedConfig; + } + Object.entries(configValue).forEach(([key, value]) => { + var _a; + // If the top level `any` or `all` keys are provided then set them, and convert their values to + // our config objects. + if (key === 'any' || key === 'all') { + if (Array.isArray(value)) { + const newConfigs = value.map(toMatchConfig); + updatedConfig.push({ [key]: newConfigs }); + } + } + else if ( + // These are the keys that we accept and know how to process + ['changed-files', 'head-branch', 'base-branch'].includes(key)) { + const newMatchConfig = toMatchConfig({ [key]: value }); + // Find or set the `any` key so that we can add these properties to that rule, + // Or create a new `any` key and add that to our array of configs. + const indexOfAny = updatedConfig.findIndex(mc => !!mc['any']); + if (indexOfAny >= 0) { + (_a = updatedConfig[indexOfAny].any) === null || _a === void 0 ? void 0 : _a.push(newMatchConfig); + } + else { + updatedConfig.push({ any: [newMatchConfig] }); + } + } + else { + // Log the key that we don't know what to do with. + core.info(`An unknown config option was under ${label}: ${key}`); + } + }); + return updatedConfig; + }, []); + if (matchConfigs.length) { + labelMap.set(label, matchConfigs); + } } return labelMap; } +exports.getLabelConfigMapFromObject = getLabelConfigMapFromObject; function toMatchConfig(config) { const changedFilesConfig = (0, changedFiles_1.toChangedFilesMatchConfig)(config); const branchConfig = (0, branch_1.toBranchMatchConfig)(config); @@ -392,32 +411,77 @@ function checkMatchConfigs(changedFiles, matchConfigs) { } exports.checkMatchConfigs = checkMatchConfigs; function checkMatch(changedFiles, matchConfig) { - var _a, _b; if (!Object.keys(matchConfig).length) { return false; } - if ((_a = matchConfig.changedFiles) === null || _a === void 0 ? void 0 : _a.all) { - if (!(0, changedFiles_1.checkAll)(changedFiles, matchConfig.changedFiles.all)) { + if (matchConfig.all) { + if (!checkAll(matchConfig.all, changedFiles)) { return false; } } - if ((_b = matchConfig.changedFiles) === null || _b === void 0 ? void 0 : _b.any) { - if (!(0, changedFiles_1.checkAny)(changedFiles, matchConfig.changedFiles.any)) { - return false; - } - } - if (matchConfig.headBranch) { - if (!(0, branch_1.checkBranch)(matchConfig.headBranch, 'head')) { - return false; - } - } - if (matchConfig.baseBranch) { - if (!(0, branch_1.checkBranch)(matchConfig.baseBranch, 'base')) { + if (matchConfig.any) { + if (!checkAny(matchConfig.any, changedFiles)) { return false; } } return true; } +// equivalent to "Array.some()" but expanded for debugging and clarity +function checkAny(matchConfigs, changedFiles) { + core.debug(` checking "any" patterns`); + if (!Object.keys(matchConfigs).length) { + core.debug(` no "any" patterns to check`); + return false; + } + for (const matchConfig of matchConfigs) { + if (matchConfig.baseBranch) { + if ((0, branch_1.checkAnyBranch)(matchConfig.baseBranch, 'base')) { + return true; + } + } + if (matchConfig.changedFiles) { + if ((0, changedFiles_1.checkAnyChangedFiles)(changedFiles, matchConfig.changedFiles)) { + return true; + } + } + if (matchConfig.headBranch) { + if ((0, branch_1.checkAnyBranch)(matchConfig.headBranch, 'head')) { + return true; + } + } + } + core.debug(` "any" patterns did not match any configs`); + return false; +} +exports.checkAny = checkAny; +// equivalent to "Array.every()" but expanded for debugging and clarity +function checkAll(matchConfigs, changedFiles) { + core.debug(` checking "all" patterns`); + if (!Object.keys(matchConfigs).length) { + core.debug(` no "all" patterns to check`); + return false; + } + for (const matchConfig of matchConfigs) { + if (matchConfig.baseBranch) { + if (!(0, branch_1.checkAllBranch)(matchConfig.baseBranch, 'base')) { + return false; + } + } + if (matchConfig.changedFiles) { + if ((0, changedFiles_1.checkAllChangedFiles)(changedFiles, matchConfig.changedFiles)) { + return true; + } + } + if (matchConfig.headBranch) { + if (!(0, branch_1.checkAllBranch)(matchConfig.headBranch, 'head')) { + return false; + } + } + } + core.debug(` "all" patterns matched all files`); + return true; +} +exports.checkAll = checkAll; function addLabels(client, prNumber, labels) { return __awaiter(this, void 0, void 0, function* () { yield client.rest.issues.addLabels({ From 4554c0d1af28505bdbcbeaf38802478bc3b65226 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 16:07:56 -0400 Subject: [PATCH 06/19] Add a bunch more tests --- __tests__/branch.test.ts | 60 +++++++++++++++++++++++++++++++++++++++ __tests__/labeler.test.ts | 52 +++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 9 deletions(-) diff --git a/__tests__/branch.test.ts b/__tests__/branch.test.ts index d9c904cf..4bd20305 100644 --- a/__tests__/branch.test.ts +++ b/__tests__/branch.test.ts @@ -1,6 +1,7 @@ import { getBranchName, checkAnyBranch, + checkAllBranch, toBranchMatchConfig, BranchMatchConfig } from '../src/branch'; @@ -25,6 +26,65 @@ describe('getBranchName', () => { }); }); +describe('checkAllBranch', () => { + beforeEach(() => { + github.context.payload.pull_request!.head = { + ref: 'test/feature/123' + }; + github.context.payload.pull_request!.base = { + ref: 'main' + }; + }); + + describe('when a single pattern is provided', () => { + describe('and the pattern matches the head branch', () => { + it('returns true', () => { + const result = checkAllBranch(['^test'], 'head'); + expect(result).toBe(true); + }); + }); + + describe('and the pattern does not match the head branch', () => { + it('returns false', () => { + const result = checkAllBranch(['^feature/'], 'head'); + expect(result).toBe(false); + }); + }); + }); + + describe('when multiple patterns are provided', () => { + describe('and not all patterns matched', () => { + it('returns false', () => { + const result = checkAllBranch(['^test/', '^feature/'], 'head'); + expect(result).toBe(false); + }); + }); + + describe('and all patterns match', () => { + it('returns true', () => { + const result = checkAllBranch(['^test/', '/feature/'], 'head'); + expect(result).toBe(true); + }); + }); + + describe('and no patterns match', () => { + it('returns false', () => { + const result = checkAllBranch(['^feature/', '/test$'], 'head'); + expect(result).toBe(false); + }); + }); + }); + + describe('when the branch to check is specified as the base branch', () => { + describe('and the pattern matches the base branch', () => { + it('returns true', () => { + const result = checkAllBranch(['^main$'], 'base'); + expect(result).toBe(true); + }); + }); + }); +}); + describe('checkAnyBranch', () => { beforeEach(() => { github.context.payload.pull_request!.head = { diff --git a/__tests__/labeler.test.ts b/__tests__/labeler.test.ts index d5ac569b..0b9fb307 100644 --- a/__tests__/labeler.test.ts +++ b/__tests__/labeler.test.ts @@ -88,19 +88,53 @@ describe('toMatchConfig', () => { }); describe('checkMatchConfigs', () => { - const matchConfig: MatchConfig[] = [{any: [{changedFiles: ['*.txt']}]}]; + describe('when a single match config is provided', () => { + const matchConfig: MatchConfig[] = [{any: [{changedFiles: ['*.txt']}]}]; - it('returns true when our pattern does match changed files', () => { - const changedFiles = ['foo.txt', 'bar.txt']; - const result = checkMatchConfigs(changedFiles, matchConfig); + it('returns true when our pattern does match changed files', () => { + const changedFiles = ['foo.txt', 'bar.txt']; + const result = checkMatchConfigs(changedFiles, matchConfig); - expect(result).toBeTruthy(); + expect(result).toBeTruthy(); + }); + + it('returns false when our pattern does not match changed files', () => { + const changedFiles = ['foo.docx']; + const result = checkMatchConfigs(changedFiles, matchConfig); + + expect(result).toBeFalsy(); + }); + + it('returns true when either the branch or changed files patter matches', () => { + const matchConfig: MatchConfig[] = [ + {any: [{changedFiles: ['*.txt']}, {headBranch: ['some-branch']}]} + ]; + const changedFiles = ['foo.txt', 'bar.txt']; + + const result = checkMatchConfigs(changedFiles, matchConfig); + expect(result).toBe(true); + }); }); - it('returns false when our pattern does not match changed files', () => { - const changedFiles = ['foo.docx']; - const result = checkMatchConfigs(changedFiles, matchConfig); + describe('when multiple MatchConfigs are supplied', () => { + const matchConfig: MatchConfig[] = [ + {any: [{changedFiles: ['*.txt']}]}, + {any: [{headBranch: ['some-branch']}]} + ]; + const changedFiles = ['foo.txt', 'bar.md']; - expect(result).toBeFalsy(); + it('returns false when only one config matches', () => { + const result = checkMatchConfigs(changedFiles, matchConfig); + expect(result).toBe(false); + }); + + it('returns true when only both config matches', () => { + const matchConfig: MatchConfig[] = [ + {any: [{changedFiles: ['*.txt']}]}, + {any: [{headBranch: ['head-branch']}]} + ]; + const result = checkMatchConfigs(changedFiles, matchConfig); + expect(result).toBe(true); + }); }); }); From 5ac9519cbf2aa3d14df8abdf9c66203b52bdeb66 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 16:31:45 -0400 Subject: [PATCH 07/19] Update the README --- README.md | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fc936173..56cff48d 100644 --- a/README.md +++ b/README.md @@ -14,27 +14,36 @@ The key is the name of the label in your repository that you want to add (eg: "m #### Match Object -The match object allows control over the matching options, you can specify the label to be applied based on the files that have changed or the name of the branch. For the changed files options you provide a [path glob](https://github.com/isaacs/minimatch#minimatch), and a regexp for the branch names. -The match object is defined as: +The match object allows control over the matching options, you can specify the label to be applied based on the files that have changed or the name of either the base branch or the head branch. For the changed files options you provide a [path glob](https://github.com/isaacs/minimatch#minimatch), and for the branches you provide a regexp to match against the branch name. +The base match object is defined as: ```yml -- changed-files: - - any: ['list', 'of', 'globs'] - - all: ['list', 'of', 'globs'] +- changed-files: ['list', 'of', 'globs'] - base-branch: ['list', 'of', 'regexps'] - head-branch: ['list', 'of', 'regexps'] ``` -One or all fields can be provided for fine-grained matching. Unlike the top-level list, the list of path globs provided to `any` and `all` must ALL match against a path for the label to be applied. +There are two top level keys of `any` and `all`, which both accept the same config options: +```yml +- any: + - changed-files: ['list', 'of', 'globs'] + - base-branch: ['list', 'of', 'regexps'] + - head-branch: ['list', 'of', 'regexps'] +- all: + - changed-files: ['list', 'of', 'globs'] + - base-branch: ['list', 'of', 'regexps'] + - head-branch: ['list', 'of', 'regexps'] +``` +One or all fields can be provided for fine-grained matching. The fields are defined as follows: -* `changed-files` - * `any`: match ALL globs against ANY changed path - * `all`: match ALL globs against ALL changed paths +* `all`: all of the provided options must match in order for the label to be applied +* `any`: if any of the provided options match then a label will be applied * `base-branch`: match a regexp against the base branch name +* `changed-files`: match a glob against the changed paths * `head-branch`: match a regexp against the head branch name -A simple path glob is the equivalent to `any: ['glob']`. More specifically, the following two configurations are equivalent: +If a base option is provided without a top-level key then it will default to `any`. More specifically, the following two configurations are equivalent: ```yml label1: - changed-files: example1/* @@ -42,11 +51,11 @@ label1: and ```yml label1: -- changed-files: - - any: ['example1/*'] +- any: + - changed-files: ['example1/*'] ``` -From a boolean logic perspective, top-level match objects are `OR`-ed together and individual match rules within an object are `AND`-ed. Combined with `!` negation, you can write complex matching rules. +From a boolean logic perspective, top-level match objects are `AND`-ed together and individual match rules within an object are `OR`-ed. If path globs are combined with `!` negation, you can write complex matching rules. #### Basic Examples @@ -96,9 +105,10 @@ source: # Add 'frontend` label to any change to *.js files as long as the `main.js` hasn't changed frontend: -- changed-files: - - any: ['src/**/*.js'] - all: ['!src/main.js'] +- any: + - changed-files: ['src/**/*.js'] +- all: + - changed-files: ['!src/main.js'] # Add 'feature' label to any PR where the head branch name starts with `feature` or has a `feature` section in the name feature: From ef6ab1b64a2b7d5f5adc7a02302623dc06f30762 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 17:22:04 -0400 Subject: [PATCH 08/19] Add function for checking if any path matches --- src/changedFiles.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/changedFiles.ts b/src/changedFiles.ts index 70dbcb0a..cc154e78 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -49,7 +49,21 @@ function printPattern(matcher: Minimatch): string { return (matcher.negate ? '!' : '') + matcher.pattern; } -function isMatch(changedFile: string, matchers: Minimatch[]): boolean { +function isAnyMatch(changedFile: string, matchers: Minimatch[]): boolean { + core.debug(` matching patterns against file ${changedFile}`); + for (const matcher of matchers) { + core.debug(` - ${printPattern(matcher)}`); + if (matcher.match(changedFile)) { + core.debug(` ${printPattern(matcher)} matched`); + return true; + } + } + + core.debug(` no patterns matched`); + return false; +} + +function isAllMatch(changedFile: string, matchers: Minimatch[]): boolean { core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { core.debug(` - ${printPattern(matcher)}`); @@ -70,7 +84,7 @@ export function checkAnyChangedFiles( const matchers = globs.map(g => new Minimatch(g)); core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { - if (isMatch(changedFile, matchers)) { + if (isAnyMatch(changedFile, matchers)) { core.debug(` "any" patterns matched against ${changedFile}`); return true; } @@ -87,7 +101,7 @@ export function checkAllChangedFiles( const matchers = globs.map(g => new Minimatch(g)); core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { - if (!isMatch(changedFile, matchers)) { + if (!isAllMatch(changedFile, matchers)) { core.debug(` "all" patterns did not match against ${changedFile}`); return false; } From 62f22bdebe66c808baa915a3f9a0a74e80ae82e2 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 17:24:52 -0400 Subject: [PATCH 09/19] Run the build command --- dist/index.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index fda0b69d..8de593f7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -186,7 +186,19 @@ exports.toChangedFilesMatchConfig = toChangedFilesMatchConfig; function printPattern(matcher) { return (matcher.negate ? '!' : '') + matcher.pattern; } -function isMatch(changedFile, matchers) { +function isAnyMatch(changedFile, matchers) { + core.debug(` matching patterns against file ${changedFile}`); + for (const matcher of matchers) { + core.debug(` - ${printPattern(matcher)}`); + if (matcher.match(changedFile)) { + core.debug(` ${printPattern(matcher)} matched`); + return true; + } + } + core.debug(` no patterns matched`); + return false; +} +function isAllMatch(changedFile, matchers) { core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { core.debug(` - ${printPattern(matcher)}`); @@ -202,7 +214,7 @@ function checkAnyChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { - if (isMatch(changedFile, matchers)) { + if (isAnyMatch(changedFile, matchers)) { core.debug(` "any" patterns matched against ${changedFile}`); return true; } @@ -215,7 +227,7 @@ function checkAllChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { - if (!isMatch(changedFile, matchers)) { + if (!isAllMatch(changedFile, matchers)) { core.debug(` "all" patterns did not match against ${changedFile}`); return false; } From 0b2cfb01d7198490dfa78fc209d4f5a0f28b5fa9 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 17:42:17 -0400 Subject: [PATCH 10/19] Im an idiot, bad copy pasta --- src/branch.ts | 4 ++-- src/labeler.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/branch.ts b/src/branch.ts index 39ccce0e..4cf9cac4 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -77,12 +77,12 @@ export function checkAllBranch( const matchers = regexps.map(regexp => new RegExp(regexp)); for (const matcher of matchers) { if (!matchBranchPattern(matcher, branchName)) { - core.debug(` "branch" patterns matched against ${branchName}`); + core.debug(` "branch" patterns did not match against ${branchName}`); return false; } } - core.debug(` "branch" patterns did not match against ${branchName}`); + core.debug(` "branch" patterns matched against ${branchName}`); return true; } diff --git a/src/labeler.ts b/src/labeler.ts index 328d120a..0352ce86 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -274,7 +274,7 @@ export function checkAll( if (matchConfig.changedFiles) { if (checkAllChangedFiles(changedFiles, matchConfig.changedFiles)) { - return true; + return false; } } From 29382eb4ff95ea4d15d2ddd19059575282ce34d1 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 17:42:44 -0400 Subject: [PATCH 11/19] Build command --- dist/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8de593f7..b87e01d7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -91,11 +91,11 @@ function checkAllBranch(regexps, branchBase) { const matchers = regexps.map(regexp => new RegExp(regexp)); for (const matcher of matchers) { if (!matchBranchPattern(matcher, branchName)) { - core.debug(` "branch" patterns matched against ${branchName}`); + core.debug(` "branch" patterns did not match against ${branchName}`); return false; } } - core.debug(` "branch" patterns did not match against ${branchName}`); + core.debug(` "branch" patterns matched against ${branchName}`); return true; } exports.checkAllBranch = checkAllBranch; @@ -481,7 +481,7 @@ function checkAll(matchConfigs, changedFiles) { } if (matchConfig.changedFiles) { if ((0, changedFiles_1.checkAllChangedFiles)(changedFiles, matchConfig.changedFiles)) { - return true; + return false; } } if (matchConfig.headBranch) { From fa7f98c785ad758a7529ccda0fdafd191a7ab1fd Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 19:09:06 -0400 Subject: [PATCH 12/19] Yikes, still missed that --- src/labeler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/labeler.ts b/src/labeler.ts index 0352ce86..aa1b4c13 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -273,7 +273,7 @@ export function checkAll( } if (matchConfig.changedFiles) { - if (checkAllChangedFiles(changedFiles, matchConfig.changedFiles)) { + if (!checkAllChangedFiles(changedFiles, matchConfig.changedFiles)) { return false; } } From 210043eed1f8b066a6e110dbc01cc5d22c2a9ecd Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 25 Mar 2023 19:09:30 -0400 Subject: [PATCH 13/19] Run the build command --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index b87e01d7..7338ee46 100644 --- a/dist/index.js +++ b/dist/index.js @@ -480,7 +480,7 @@ function checkAll(matchConfigs, changedFiles) { } } if (matchConfig.changedFiles) { - if ((0, changedFiles_1.checkAllChangedFiles)(changedFiles, matchConfig.changedFiles)) { + if (!(0, changedFiles_1.checkAllChangedFiles)(changedFiles, matchConfig.changedFiles)) { return false; } } From 938f9c989307616e7bcdc297e729796068dded54 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sun, 26 Mar 2023 09:46:29 -0400 Subject: [PATCH 14/19] Update the readme a little more --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56cff48d..734a61f8 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ label1: - changed-files: ['example1/*'] ``` -From a boolean logic perspective, top-level match objects are `AND`-ed together and individual match rules within an object are `OR`-ed. If path globs are combined with `!` negation, you can write complex matching rules. +From a boolean logic perspective, top-level match objects, and options within `all` are `AND`-ed together and individual match rules within the `any` object are `OR`-ed. If path globs are combined with `!` negation, you can write complex matching rules. #### Basic Examples From 3ddce51a657998e19ff46b2b3cb11fe49f72c70d Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Mon, 27 Mar 2023 16:15:03 -0400 Subject: [PATCH 15/19] Update the debug values --- src/changedFiles.ts | 2 -- src/labeler.ts | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/changedFiles.ts b/src/changedFiles.ts index cc154e78..35697b87 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -82,7 +82,6 @@ export function checkAnyChangedFiles( globs: string[] ): boolean { const matchers = globs.map(g => new Minimatch(g)); - core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { if (isAnyMatch(changedFile, matchers)) { core.debug(` "any" patterns matched against ${changedFile}`); @@ -99,7 +98,6 @@ export function checkAllChangedFiles( globs: string[] ): boolean { const matchers = globs.map(g => new Minimatch(g)); - core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { if (!isAllMatch(changedFile, matchers)) { core.debug(` "all" patterns did not match against ${changedFile}`); diff --git a/src/labeler.ts b/src/labeler.ts index aa1b4c13..aa55596a 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -201,6 +201,7 @@ export function checkMatchConfigs( function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { if (!Object.keys(matchConfig).length) { + core.debug(` no "any" or "all" patterns to check`); return false; } From 4be192c7d6f4a40fbae6c7916ee951159577e574 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Mon, 27 Mar 2023 16:23:04 -0400 Subject: [PATCH 16/19] Run the build command --- dist/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7338ee46..ac64e973 100644 --- a/dist/index.js +++ b/dist/index.js @@ -212,7 +212,6 @@ function isAllMatch(changedFile, matchers) { } function checkAnyChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); - core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { if (isAnyMatch(changedFile, matchers)) { core.debug(` "any" patterns matched against ${changedFile}`); @@ -225,7 +224,6 @@ function checkAnyChangedFiles(changedFiles, globs) { exports.checkAnyChangedFiles = checkAnyChangedFiles; function checkAllChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); - core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { if (!isAllMatch(changedFile, matchers)) { core.debug(` "all" patterns did not match against ${changedFile}`); @@ -424,6 +422,7 @@ function checkMatchConfigs(changedFiles, matchConfigs) { exports.checkMatchConfigs = checkMatchConfigs; function checkMatch(changedFiles, matchConfig) { if (!Object.keys(matchConfig).length) { + core.debug(` no "any" or "all" patterns to check`); return false; } if (matchConfig.all) { From 67604ee82210393c927796c1cb02316c6a748b19 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Mon, 27 Mar 2023 16:26:58 -0400 Subject: [PATCH 17/19] Update more debugging statements --- dist/index.js | 8 ++++---- src/changedFiles.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index ac64e973..85f84a75 100644 --- a/dist/index.js +++ b/dist/index.js @@ -187,9 +187,9 @@ function printPattern(matcher) { return (matcher.negate ? '!' : '') + matcher.pattern; } function isAnyMatch(changedFile, matchers) { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (matcher.match(changedFile)) { core.debug(` ${printPattern(matcher)} matched`); return true; @@ -199,9 +199,9 @@ function isAnyMatch(changedFile, matchers) { return false; } function isAllMatch(changedFile, matchers) { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (!matcher.match(changedFile)) { core.debug(` ${printPattern(matcher)} did not match`); return false; diff --git a/src/changedFiles.ts b/src/changedFiles.ts index 35697b87..dc82dc81 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -50,9 +50,9 @@ function printPattern(matcher: Minimatch): string { } function isAnyMatch(changedFile: string, matchers: Minimatch[]): boolean { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (matcher.match(changedFile)) { core.debug(` ${printPattern(matcher)} matched`); return true; @@ -64,9 +64,9 @@ function isAnyMatch(changedFile: string, matchers: Minimatch[]): boolean { } function isAllMatch(changedFile: string, matchers: Minimatch[]): boolean { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (!matcher.match(changedFile)) { core.debug(` ${printPattern(matcher)} did not match`); return false; From b1a2f85ed8d2158aee03b3efe896cc23685cdf83 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Mon, 27 Mar 2023 16:37:55 -0400 Subject: [PATCH 18/19] Update debugging indentation on the branch checks --- dist/index.js | 18 +++++++++--------- src/branch.ts | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index 85f84a75..8a0e2801 100644 --- a/dist/index.js +++ b/dist/index.js @@ -69,15 +69,15 @@ function checkAnyBranch(regexps, branchBase) { core.debug(` no branch name`); return false; } - core.debug(` checking "branch" pattern against ${branchName}`); + 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}`); + core.debug(` "branch" patterns matched against ${branchName}`); return true; } } - core.debug(` "branch" patterns did not match against ${branchName}`); + core.debug(` "branch" patterns did not match against ${branchName}`); return false; } exports.checkAnyBranch = checkAnyBranch; @@ -87,25 +87,25 @@ function checkAllBranch(regexps, branchBase) { core.debug(` no branch name`); return false; } - core.debug(` checking "branch" pattern against ${branchName}`); + 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 did not match against ${branchName}`); + core.debug(` "branch" patterns did not match against ${branchName}`); return false; } } - core.debug(` "branch" patterns matched against ${branchName}`); + core.debug(` "branch" patterns matched against ${branchName}`); return true; } exports.checkAllBranch = checkAllBranch; function matchBranchPattern(matcher, branchName) { - core.debug(` - ${matcher}`); + core.debug(` - ${matcher}`); if (matcher.test(branchName)) { - core.debug(` "branch" pattern matched`); + core.debug(` "branch" pattern matched`); return true; } - core.debug(` ${matcher} did not match`); + core.debug(` ${matcher} did not match`); return false; } diff --git a/src/branch.ts b/src/branch.ts index 4cf9cac4..fd6cca28 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -50,16 +50,16 @@ export function checkAnyBranch( return false; } - core.debug(` checking "branch" pattern against ${branchName}`); + 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}`); + core.debug(` "branch" patterns matched against ${branchName}`); return true; } } - core.debug(` "branch" patterns did not match against ${branchName}`); + core.debug(` "branch" patterns did not match against ${branchName}`); return false; } @@ -73,26 +73,26 @@ export function checkAllBranch( return false; } - core.debug(` checking "branch" pattern against ${branchName}`); + 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 did not match against ${branchName}`); + core.debug(` "branch" patterns did not match against ${branchName}`); return false; } } - core.debug(` "branch" patterns matched against ${branchName}`); + core.debug(` "branch" patterns matched against ${branchName}`); return true; } function matchBranchPattern(matcher: RegExp, branchName: string): boolean { - core.debug(` - ${matcher}`); + core.debug(` - ${matcher}`); if (matcher.test(branchName)) { - core.debug(` "branch" pattern matched`); + core.debug(` "branch" pattern matched`); return true; } - core.debug(` ${matcher} did not match`); + core.debug(` ${matcher} did not match`); return false; } From 2f1dfd1ef0dc8a663bf8621d42990cc21271f8ac Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Mon, 27 Mar 2023 16:52:42 -0400 Subject: [PATCH 19/19] Adjust the indenting again --- dist/index.js | 32 ++++++++++++++++---------------- src/branch.ts | 4 ++-- src/changedFiles.ts | 24 ++++++++++++------------ src/labeler.ts | 4 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8a0e2801..77ed5bd4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -66,7 +66,7 @@ exports.getBranchName = getBranchName; function checkAnyBranch(regexps, branchBase) { const branchName = getBranchName(branchBase); if (!branchName) { - core.debug(` no branch name`); + core.debug(` no branch name`); return false; } core.debug(` checking "branch" pattern against ${branchName}`); @@ -84,7 +84,7 @@ exports.checkAnyBranch = checkAnyBranch; function checkAllBranch(regexps, branchBase) { const branchName = getBranchName(branchBase); if (!branchName) { - core.debug(` no branch name`); + core.debug(` no branch name`); return false; } core.debug(` checking "branch" pattern against ${branchName}`); @@ -187,38 +187,38 @@ function printPattern(matcher) { return (matcher.negate ? '!' : '') + matcher.pattern; } function isAnyMatch(changedFile, matchers) { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (matcher.match(changedFile)) { - core.debug(` ${printPattern(matcher)} matched`); + core.debug(` ${printPattern(matcher)} matched`); return true; } } - core.debug(` no patterns matched`); + core.debug(` no patterns matched`); return false; } function isAllMatch(changedFile, matchers) { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (!matcher.match(changedFile)) { - core.debug(` ${printPattern(matcher)} did not match`); + core.debug(` ${printPattern(matcher)} did not match`); return false; } } - core.debug(` all patterns matched`); + core.debug(` all patterns matched`); return true; } function checkAnyChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); for (const changedFile of changedFiles) { if (isAnyMatch(changedFile, matchers)) { - core.debug(` "any" patterns matched against ${changedFile}`); + core.debug(` "any" patterns matched against ${changedFile}`); return true; } } - core.debug(` "any" patterns did not match any files`); + core.debug(` "any" patterns did not match any files`); return false; } exports.checkAnyChangedFiles = checkAnyChangedFiles; @@ -226,11 +226,11 @@ function checkAllChangedFiles(changedFiles, globs) { const matchers = globs.map(g => new minimatch_1.Minimatch(g)); for (const changedFile of changedFiles) { if (!isAllMatch(changedFile, matchers)) { - core.debug(` "all" patterns did not match against ${changedFile}`); + core.debug(` "all" patterns did not match against ${changedFile}`); return false; } } - core.debug(` "all" patterns matched all files`); + core.debug(` "all" patterns matched all files`); return true; } exports.checkAllChangedFiles = checkAllChangedFiles; @@ -467,7 +467,7 @@ function checkAny(matchConfigs, changedFiles) { exports.checkAny = checkAny; // equivalent to "Array.every()" but expanded for debugging and clarity function checkAll(matchConfigs, changedFiles) { - core.debug(` checking "all" patterns`); + core.debug(` checking "all" patterns`); if (!Object.keys(matchConfigs).length) { core.debug(` no "all" patterns to check`); return false; @@ -489,7 +489,7 @@ function checkAll(matchConfigs, changedFiles) { } } } - core.debug(` "all" patterns matched all files`); + core.debug(` "all" patterns matched all configs`); return true; } exports.checkAll = checkAll; diff --git a/src/branch.ts b/src/branch.ts index fd6cca28..9c197741 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -46,7 +46,7 @@ export function checkAnyBranch( ): boolean { const branchName = getBranchName(branchBase); if (!branchName) { - core.debug(` no branch name`); + core.debug(` no branch name`); return false; } @@ -69,7 +69,7 @@ export function checkAllBranch( ): boolean { const branchName = getBranchName(branchBase); if (!branchName) { - core.debug(` no branch name`); + core.debug(` no branch name`); return false; } diff --git a/src/changedFiles.ts b/src/changedFiles.ts index dc82dc81..cd83f3d6 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -50,30 +50,30 @@ function printPattern(matcher: Minimatch): string { } function isAnyMatch(changedFile: string, matchers: Minimatch[]): boolean { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (matcher.match(changedFile)) { - core.debug(` ${printPattern(matcher)} matched`); + core.debug(` ${printPattern(matcher)} matched`); return true; } } - core.debug(` no patterns matched`); + core.debug(` no patterns matched`); return false; } function isAllMatch(changedFile: string, matchers: Minimatch[]): boolean { - core.debug(` matching patterns against file ${changedFile}`); + core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); + core.debug(` - ${printPattern(matcher)}`); if (!matcher.match(changedFile)) { - core.debug(` ${printPattern(matcher)} did not match`); + core.debug(` ${printPattern(matcher)} did not match`); return false; } } - core.debug(` all patterns matched`); + core.debug(` all patterns matched`); return true; } @@ -84,12 +84,12 @@ export function checkAnyChangedFiles( const matchers = globs.map(g => new Minimatch(g)); for (const changedFile of changedFiles) { if (isAnyMatch(changedFile, matchers)) { - core.debug(` "any" patterns matched against ${changedFile}`); + core.debug(` "any" patterns matched against ${changedFile}`); return true; } } - core.debug(` "any" patterns did not match any files`); + core.debug(` "any" patterns did not match any files`); return false; } @@ -100,11 +100,11 @@ export function checkAllChangedFiles( const matchers = globs.map(g => new Minimatch(g)); for (const changedFile of changedFiles) { if (!isAllMatch(changedFile, matchers)) { - core.debug(` "all" patterns did not match against ${changedFile}`); + core.debug(` "all" patterns did not match against ${changedFile}`); return false; } } - core.debug(` "all" patterns matched all files`); + core.debug(` "all" patterns matched all files`); return true; } diff --git a/src/labeler.ts b/src/labeler.ts index aa55596a..26db5ede 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -260,7 +260,7 @@ export function checkAll( matchConfigs: BaseMatchConfig[], changedFiles: string[] ): boolean { - core.debug(` checking "all" patterns`); + core.debug(` checking "all" patterns`); if (!Object.keys(matchConfigs).length) { core.debug(` no "all" patterns to check`); return false; @@ -286,7 +286,7 @@ export function checkAll( } } - core.debug(` "all" patterns matched all files`); + core.debug(` "all" patterns matched all configs`); return true; }