Skip to content

Commit

Permalink
Implement case-insensitive matching for head branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
datpmt committed Jan 10, 2025
1 parent d24f7f3 commit 6153ac2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions __tests__/branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 6153ac2

Please sign in to comment.