diff --git a/bin/cml/pr/create.js b/bin/cml/pr/create.js index 035937c40..953a1b536 100755 --- a/bin/cml/pr/create.js +++ b/bin/cml/pr/create.js @@ -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' diff --git a/src/cml.js b/src/cml.js index 42bb0043e..f00e6c549 100644 --- a/src/cml.js +++ b/src/cml.js @@ -508,6 +508,7 @@ class CML { md, skipCi, branch, + targetBranch, message, title, body, @@ -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 = (