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

View File

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