Repository: iterative/cml
Pull request #1063 (2022-06-15 21:59:38)

additional `cml pr` options
Closes: https://github.com/iterative/cml/issues/1017
Adds:
- `--branch` allow a use to set a custom branch name like `exp-12345` or `exp=${{  matrix.exp_id }}`
- `--title` PR title
- `--body` (maybe `--description` is better ?) body contents
- `--message` custom commit message

some examples:
`cml pr --title test --body="test pr body" --message="my commit message" .`
`cml pr --skip-ci --branch exp-1234 --message="my commit message" .`
~~`cml pr --title="Fancy PR Body" --body report.md  .`~~

if `--message` is provided the ` [skip ci]` notation is only added if `--skip-ci` is included. For example, `cml pr --squash .` would make a commit with `[skip ci]` present but `cml pr --messsage="my yolo pr" --squash`  would not, including `--skip-ci` explicitly adds ` [skip ci]` to the end of the provided message for this example resulting in a commit message of `my yolo pr [skip ci]`



Patch:
diff --git a/bin/cml/pr.js b/bin/cml/pr.js
index 6e71c44..48fb631 100755
--- a/bin/cml/pr.js
+++ b/bin/cml/pr.js
@@ -39,6 +39,22 @@ exports.builder = (yargs) =>
         conflicts: ['merge', 'rebase'],
         description: 'Try to squash-merge the pull request upon creation.'
       },
+      branch: {
+        type: 'string',
+        description: 'Branch name for the pull request.'
+      },
+      title: {
+        type: 'string',
+        description: 'Pull request title.'
+      },
+      body: {
+        type: 'string',
+        description: 'Pull request description.'
+      },
+      message: {
+        type: 'string',
+        description: 'Commit message.'
+      },
       remote: {
         type: 'string',
         default: GIT_REMOTE,
diff --git a/src/cml.js b/src/cml.js
index 3c23ad3..c4a7cfe 100755
--- a/src/cml.js
+++ b/src/cml.js
@@ -453,6 +453,10 @@ class CML {
       globs = ['dvc.lock', '.gitignore'],
       md,
       skipCi,
+      branch,
+      message,
+      title,
+      body,
       merge,
       rebase,
       squash
@@ -486,7 +490,7 @@ class CML {
     const shaShort = sha.substr(0, 8);
 
     const target = await this.branch();
-    const source = `${target}-cml-pr-${shaShort}`;
+    const source = branch || `${target}-cml-pr-${shaShort}`;
 
     const branchExists = (
       await exec(
@@ -507,24 +511,23 @@ class CML {
       await exec(`git checkout -B ${target} ${sha}`);
       await exec(`git checkout -b ${source}`);
       await exec(`git add ${paths.join(' ')}`);
-      let commitMessage = `CML PR for ${shaShort}`;
-      if (skipCi || !(merge || rebase || squash)) {
+      let commitMessage = message || `CML PR for ${shaShort}`;
+      if (skipCi || (!message && !(merge || rebase || squash))) {
         commitMessage += ' [skip ci]';
       }
       await exec(`git commit -m "${commitMessage}"`);
       await exec(`git push --set-upstream ${remote} ${source}`);
     }
 
-    const title = `CML PR for ${target} ${shaShort}`;
-    const description = `
-Automated commits for ${this.repo}/commit/${sha} created by CML.
-  `;
-
     const url = await driver.prCreate({
       source,
       target,
-      title,
-      description,
+      title: title || `CML PR for ${target} ${shaShort}`,
+      description:
+        body ||
+        `
+Automated commits for ${this.repo}/commit/${sha} created by CML.
+      `,
       skipCi,
       autoMerge: merge
         ? 'merge'


Test patch:
diff --git a/bin/cml/pr.test.js b/bin/cml/pr.test.js
index 402d3a8..e8daab9 100644
--- a/bin/cml/pr.test.js
+++ b/bin/cml/pr.test.js
@@ -21,6 +21,10 @@ describe('CML e2e', () => {
                                                                              [boolean]
         --squash               Try to squash-merge the pull request upon creation.
                                                                              [boolean]
+        --branch               Branch name for the pull request.              [string]
+        --title                Pull request title.                            [string]
+        --body                 Pull request description.                      [string]
+        --message              Commit message.                                [string]
         --remote               Sets git remote.           [string] [default: \\"origin\\"]
         --user-email           Sets git user email.
                                              [string] [default: \\"olivaw@iterative.ai\\"]