Skip to content

Commit

Permalink
Pick target branch from first commit's suggestedTargetBranches in non…
Browse files Browse the repository at this point in the history
…-interactive mode (#493)
  • Loading branch information
karolkpl authored Apr 4, 2024
1 parent bea96d0 commit 35141ba
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/lib/getTargetBranches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,49 @@ describe('getTargetBranches', () => {
});
});
});

describe('when `commit.suggestedTargetBranches` is not empty and non-interactive mode', () => {
let branches: string[];

beforeEach(async () => {
const options = {
interactive: false,
} as ValidConfigOptions;

const commits: Commit[] = [
{
author: { email: '[email protected]', name: 'Søren Louv-Jansen' },
sourceCommit: {
branchLabelMapping: {},
committedDate: 'aaa',
message: 'hey',
sha: 'abcd',
},
sourceBranch: '7.x',
suggestedTargetBranches: ['release/targetBranch'],
targetPullRequestStates: [],
},
{
author: { email: '[email protected]', name: 'Søren Louv-Jansen' },
sourceCommit: {
branchLabelMapping: {},
committedDate: 'aaa',
message: 'hey',
sha: 'abcd',
},
sourceBranch: '7.x',
suggestedTargetBranches: ['release/targetBranch'],
targetPullRequestStates: [],
},
];

branches = await getTargetBranches(options, commits);
});

it('should return branches from commit', () => {
expect(branches).toEqual(['release/targetBranch']);
});
});
});

describe('getTargetBranchChoices', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/getTargetBranches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function getTargetBranches(

// target branches from the first commit
const suggestedTargetBranches =
commits.length === 1 ? commits[0].suggestedTargetBranches : [];
commits.length > 0 ? commits[0].suggestedTargetBranches : [];

// require target branches to be specified when when in non-interactive mode
if (!options.interactive) {
Expand Down

0 comments on commit 35141ba

Please sign in to comment.