Skip to content

Commit 6153ac2

Browse files
committed
Implement case-insensitive matching for head branch name
1 parent d24f7f3 commit 6153ac2

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

__tests__/branch.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,34 @@ describe('getBranchName', () => {
2424
expect(result).toEqual('head-branch-name');
2525
});
2626
});
27+
28+
describe('Branch name matching', () => {
29+
describe('when checking for case-insensitive match', () => {
30+
// Test case 1: with mixed case in the branch name
31+
beforeEach(() => {
32+
github.context.payload.pull_request!.head = {
33+
ref: 'feature-123-Refactor'
34+
};
35+
});
36+
37+
it('returns the head branch name in lowercase', () => {
38+
const result = getBranchName('head');
39+
expect(result).toEqual('feature-123-refactor');
40+
});
41+
42+
// Test case 2: with uppercase in the branch name
43+
beforeEach(() => {
44+
github.context.payload.pull_request!.head = {
45+
ref: 'feature-123-REFACTOR'
46+
};
47+
});
48+
49+
it('returns the head branch name in lowercase', () => {
50+
const result = getBranchName('head');
51+
expect(result).toEqual('feature-123-refactor');
52+
});
53+
});
54+
});
2755
});
2856

2957
describe('checkAllBranch', () => {

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ function getBranchName(branchBase) {
531531
return (_a = pullRequest.base) === null || _a === void 0 ? void 0 : _a.ref;
532532
}
533533
else {
534-
return (_b = pullRequest.head) === null || _b === void 0 ? void 0 : _b.ref;
534+
return (_b = pullRequest.head) === null || _b === void 0 ? void 0 : _b.ref.toLowerCase();
535535
}
536536
}
537537
function checkAnyBranch(regexps, branchBase) {

src/branch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function getBranchName(branchBase: BranchBase): string | undefined {
3636
if (branchBase === 'base') {
3737
return pullRequest.base?.ref;
3838
} else {
39-
return pullRequest.head?.ref;
39+
return pullRequest.head?.ref.toLowerCase();
4040
}
4141
}
4242

0 commit comments

Comments
 (0)