From 51ca6953293c7282602cd99480390d09d24e17e1 Mon Sep 17 00:00:00 2001 From: "Olivaw[bot]" Date: Mon, 23 Jan 2023 13:20:42 +0100 Subject: [PATCH 1/2] feat: add target branch option to define the target branch when creating the pull requests instead of defaulting to the currently selected branch --- bin/cml/pr/create.js | 4 ++++ src/cml.js | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 4c1507cd5..f40efc126 100644 --- a/src/cml.js +++ b/src/cml.js @@ -508,6 +508,7 @@ class CML { md, skipCi, branch, + targetBranch, message, title, body, @@ -545,7 +546,22 @@ class CML { const sha = await this.triggerSha(); const shaShort = sha.substr(0, 8); - const target = await this.branch(); + let target = await this.branch(); + const targetBranchExists = + targetBranch && + ( + await exec( + 'git', + 'ls-remote', + await exec('git', 'config', '--get', `remote.${remote}.url`), + targetBranch + ) + ).includes(targetBranch); + + if (targetBranchExists) { + target = targetBranch; + } + const source = branch || `${target}-cml-pr-${shaShort}`; const branchExists = ( From 66c9a81c481cee29e3b201c13adc38bd08ab22dc Mon Sep 17 00:00:00 2001 From: "Olivaw[bot]" Date: Fri, 27 Jan 2023 12:33:47 +0100 Subject: [PATCH 2/2] feat: add suggested changes --- src/cml.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cml.js b/src/cml.js index f40efc126..003aeae63 100644 --- a/src/cml.js +++ b/src/cml.js @@ -547,19 +547,22 @@ class CML { const shaShort = sha.substr(0, 8); let target = await this.branch(); - const targetBranchExists = - targetBranch && - ( + + if (targetBranch) { + try { await exec( 'git', 'ls-remote', + '--exit-code', await exec('git', 'config', '--get', `remote.${remote}.url`), targetBranch - ) - ).includes(targetBranch); + ); - if (targetBranchExists) { - target = targetBranch; + target = targetBranch; + } catch (error) { + winston.error('The target branch does not exist.'); + process.exit(1); + } } const source = branch || `${target}-cml-pr-${shaShort}`;