Make getBranchName argument non-optional

This commit is contained in:
Josh Dales
2023-03-03 11:15:48 -05:00
parent 2a5bc55cbf
commit 394a01bde3
2 changed files with 7 additions and 14 deletions

View File

@@ -23,13 +23,6 @@ describe('getBranchName', () => {
expect(result).toEqual('head-branch-name'); expect(result).toEqual('head-branch-name');
}); });
}); });
describe('when no branch is specified', () => {
it('returns the head branch name', () => {
const result = getBranchName();
expect(result).toEqual('head-branch-name');
});
});
}); });
describe('checkBranch', () => { describe('checkBranch', () => {
@@ -45,14 +38,14 @@ describe('checkBranch', () => {
describe('when a single pattern is provided', () => { describe('when a single pattern is provided', () => {
describe('and the pattern matches the head branch', () => { describe('and the pattern matches the head branch', () => {
it('returns true', () => { it('returns true', () => {
const result = checkBranch(['^test']); const result = checkBranch(['^test'], 'head');
expect(result).toBe(true); expect(result).toBe(true);
}); });
}); });
describe('and the pattern does not match the head branch', () => { describe('and the pattern does not match the head branch', () => {
it('returns false', () => { it('returns false', () => {
const result = checkBranch(['^feature/']); const result = checkBranch(['^feature/'], 'head');
expect(result).toBe(false); expect(result).toBe(false);
}); });
}); });
@@ -61,21 +54,21 @@ describe('checkBranch', () => {
describe('when multiple patterns are provided', () => { describe('when multiple patterns are provided', () => {
describe('and at least one pattern matches', () => { describe('and at least one pattern matches', () => {
it('returns true', () => { it('returns true', () => {
const result = checkBranch(['^test/', '^feature/']); const result = checkBranch(['^test/', '^feature/'], 'head');
expect(result).toBe(true); expect(result).toBe(true);
}); });
}); });
describe('and all patterns match', () => { describe('and all patterns match', () => {
it('returns true', () => { it('returns true', () => {
const result = checkBranch(['^test/', '/feature/']); const result = checkBranch(['^test/', '/feature/'], 'head');
expect(result).toBe(true); expect(result).toBe(true);
}); });
}); });
describe('and no patterns match', () => { describe('and no patterns match', () => {
it('returns false', () => { it('returns false', () => {
const result = checkBranch(['^feature/', '/test$']); const result = checkBranch(['^feature/', '/test$'], 'head');
expect(result).toBe(false); expect(result).toBe(false);
}); });
}); });

View File

@@ -35,7 +35,7 @@ export function toBranchMatchConfig(config: any): BranchMatchConfig {
return branchConfig; return branchConfig;
} }
export function getBranchName(branchBase?: BranchBase): string | undefined { export function getBranchName(branchBase: BranchBase): string | undefined {
const pullRequest = github.context.payload.pull_request; const pullRequest = github.context.payload.pull_request;
if (!pullRequest) { if (!pullRequest) {
return undefined; return undefined;
@@ -50,7 +50,7 @@ export function getBranchName(branchBase?: BranchBase): string | undefined {
export function checkBranch( export function checkBranch(
regexps: string[], regexps: string[],
branchBase?: BranchBase branchBase: BranchBase
): boolean { ): boolean {
const branchName = getBranchName(branchBase); const branchName = getBranchName(branchBase);
if (!branchName) { if (!branchName) {