From 09f085373a3a0851facc68652e4bc89ea775346c Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sun, 19 Feb 2023 12:17:15 -0500 Subject: [PATCH] Fix some typos in the branch checks --- __tests__/branch.test.ts | 4 ++-- __tests__/main.test.ts | 4 ++-- dist/index.js | 20 ++++++++++---------- src/branch.ts | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/__tests__/branch.test.ts b/__tests__/branch.test.ts index a9d60c81..71386b90 100644 --- a/__tests__/branch.test.ts +++ b/__tests__/branch.test.ts @@ -21,8 +21,8 @@ describe('getBranchName', () => { describe('when no branch is specified', () => { it('returns the head branch name', () => { - const result = getBranchName('base'); - expect(result).toEqual('base-branch-name'); + const result = getBranchName(); + expect(result).toEqual('head-branch-name'); }); }); }); diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b9d56aec..ead8f29c 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -104,7 +104,7 @@ describe('run', () => { expect(removeLabelMock).toHaveBeenCalledTimes(0); }); - it('adds labels based on the branch names that match the glob pattern', async () => { + it('adds labels based on the branch names that match the regexp pattern', async () => { github.context.payload.pull_request!.head = {ref: 'test/testing-time'}; usingLabelerConfigYaml('branches.yml'); await run(); @@ -118,7 +118,7 @@ describe('run', () => { }); }); - it('adds multiple labels based on branch names that match different glob patterns', async () => { + it('adds multiple labels based on branch names that match different regexp patterns', async () => { github.context.payload.pull_request!.head = { ref: 'test/feature/123' }; diff --git a/dist/index.js b/dist/index.js index ca9a2563..4533491d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34,7 +34,7 @@ exports.checkBranch = exports.getBranchName = exports.toBranchMatchConfig = void const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); function toBranchMatchConfig(config) { - if (!config['head-branch'] || config['base-branch']) { + if (!config['head-branch'] && !config['base-branch']) { return {}; } const branchConfig = { @@ -340,26 +340,26 @@ function checkAll(changedFiles, globs) { function checkMatch(changedFiles, matchConfig) { var _a, _b; if (((_a = matchConfig.changedFiles) === null || _a === void 0 ? void 0 : _a.all) !== undefined) { - if (!checkAll(changedFiles, matchConfig.changedFiles.all)) { - return false; + if (checkAll(changedFiles, matchConfig.changedFiles.all)) { + return true; } } if (((_b = matchConfig.changedFiles) === null || _b === void 0 ? void 0 : _b.any) !== undefined) { - if (!checkAny(changedFiles, matchConfig.changedFiles.any)) { - return false; + if (checkAny(changedFiles, matchConfig.changedFiles.any)) { + return true; } } if (matchConfig.headBranch !== undefined) { - if (!(0, branch_1.checkBranch)(matchConfig.headBranch, 'head')) { - return false; + if ((0, branch_1.checkBranch)(matchConfig.headBranch, 'head')) { + return true; } } if (matchConfig.baseBranch !== undefined) { - if (!(0, branch_1.checkBranch)(matchConfig.baseBranch, 'base')) { - return false; + if ((0, branch_1.checkBranch)(matchConfig.baseBranch, 'base')) { + return true; } } - return true; + return false; } function addLabels(client, prNumber, labels) { return __awaiter(this, void 0, void 0, function* () { diff --git a/src/branch.ts b/src/branch.ts index 1804a37d..e4edd524 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -9,7 +9,7 @@ export interface BranchMatchConfig { type BranchBase = 'base' | 'head'; export function toBranchMatchConfig(config: any): BranchMatchConfig { - if (!config['head-branch'] || config['base-branch']) { + if (!config['head-branch'] && !config['base-branch']) { return {}; }