Skip to content

Commit

Permalink
Add the option to define the target branch on pull requests (#1326)
Browse files Browse the repository at this point in the history
* feat: add target branch option to define the target branch when creating the pull requests instead of defaulting to the currently selected branch

* feat: add suggested changes

---------

Co-authored-by: Olivaw[bot] <olivaw@iterative.ai>
  • Loading branch information
dfinteligenz and iterative-olivaw committed Feb 13, 2023
1 parent b923f3e commit ee8834b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/cml/pr/create.js
Expand Up @@ -54,6 +54,10 @@ exports.options = kebabcaseKeys({
type: 'string',
description: 'Pull request branch name'
},
targetBranch: {
type: 'string',
description: 'Pull request target branch name'
},
title: {
type: 'string',
description: 'Pull request title'
Expand Down
21 changes: 20 additions & 1 deletion src/cml.js
Expand Up @@ -508,6 +508,7 @@ class CML {
md,
skipCi,
branch,
targetBranch,
message,
title,
body,
Expand Down Expand Up @@ -551,7 +552,25 @@ class CML {
const sha = await this.triggerSha();
const shaShort = sha.substr(0, 8);

const target = await this.branch();
let target = await this.branch();

if (targetBranch) {
try {
await exec(
'git',
'ls-remote',
'--exit-code',
await exec('git', 'config', '--get', `remote.${remote}.url`),
targetBranch
);

target = targetBranch;
} catch (error) {
winston.error('The target branch does not exist.');
process.exit(1);
}
}

const source = branch || `${target}-cml-pr-${shaShort}`;

const branchExists = (
Expand Down

0 comments on commit ee8834b

Please sign in to comment.