From 6153ac26644169c0a25b07b4145502d52d1cacda Mon Sep 17 00:00:00 2001 From: Datpmt Date: Fri, 10 Jan 2025 11:09:39 +0700 Subject: [PATCH] Implement case-insensitive matching for head branch name --- __tests__/branch.test.ts | 28 ++++++++++++++++++++++++++++ dist/index.js | 2 +- src/branch.ts | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/__tests__/branch.test.ts b/__tests__/branch.test.ts index 4bd203053..60f3206cf 100644 --- a/__tests__/branch.test.ts +++ b/__tests__/branch.test.ts @@ -24,6 +24,34 @@ describe('getBranchName', () => { expect(result).toEqual('head-branch-name'); }); }); + + describe('Branch name matching', () => { + describe('when checking for case-insensitive match', () => { + // Test case 1: with mixed case in the branch name + beforeEach(() => { + github.context.payload.pull_request!.head = { + ref: 'feature-123-Refactor' + }; + }); + + it('returns the head branch name in lowercase', () => { + const result = getBranchName('head'); + expect(result).toEqual('feature-123-refactor'); + }); + + // Test case 2: with uppercase in the branch name + beforeEach(() => { + github.context.payload.pull_request!.head = { + ref: 'feature-123-REFACTOR' + }; + }); + + it('returns the head branch name in lowercase', () => { + const result = getBranchName('head'); + expect(result).toEqual('feature-123-refactor'); + }); + }); + }); }); describe('checkAllBranch', () => { diff --git a/dist/index.js b/dist/index.js index 2e4759da5..7012eb545 100644 --- a/dist/index.js +++ b/dist/index.js @@ -531,7 +531,7 @@ function getBranchName(branchBase) { return (_a = pullRequest.base) === null || _a === void 0 ? void 0 : _a.ref; } else { - return (_b = pullRequest.head) === null || _b === void 0 ? void 0 : _b.ref; + return (_b = pullRequest.head) === null || _b === void 0 ? void 0 : _b.ref.toLowerCase(); } } function checkAnyBranch(regexps, branchBase) { diff --git a/src/branch.ts b/src/branch.ts index 92c78186f..52b77e2bb 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -36,7 +36,7 @@ export function getBranchName(branchBase: BranchBase): string | undefined { if (branchBase === 'base') { return pullRequest.base?.ref; } else { - return pullRequest.head?.ref; + return pullRequest.head?.ref.toLowerCase(); } }