Repository: iterative/cml
Pull request #976 (2022-04-19 08:57:48)

Document Bitbucket `cml publish --native`
Missing from #943 🙈 


Patch:
diff --git a/bin/cml/publish.js b/bin/cml/publish.js
index 3b4723e..8e2c3fd 100644
--- a/bin/cml/publish.js
+++ b/bin/cml/publish.js
@@ -1,6 +1,7 @@
 const fs = require('fs').promises;
 const kebabcaseKeys = require('kebabcase-keys');
 const pipeArgs = require('../../src/pipe-args');
+const winston = require('winston');
 
 const CML = require('../../src/cml').default;
 
@@ -11,6 +12,13 @@ exports.command = data ? 'publish' : 'publish <asset>';
 exports.description = 'Upload an image to build a report';
 
 exports.handler = async (opts) => {
+  if (opts.gitlabUploads) {
+    winston.warn(
+      '--gitlab-uploads will be deprecated soon. Use --native instead.'
+    );
+    opts.native = true;
+  }
+
   const { file, repo, native } = opts;
 
   const path = opts.asset;
@@ -41,9 +49,12 @@ exports.builder = (yargs) =>
       },
       native: {
         type: 'boolean',
-        alias: 'gitlab-uploads',
         description:
-          "Uses driver's native capabilities to upload assets instead of CML's storage. Currently only available for GitLab CI."
+          "Uses driver's native capabilities to upload assets instead of CML's storage. Not available on GitHub."
+      },
+      gitlabUploads: {
+        type: 'boolean',
+        hidden: true
       },
       rmWatermark: {
         type: 'boolean',
diff --git a/src/cml.js b/src/cml.js
index 07f0e5b..2a92ba7 100755
--- a/src/cml.js
+++ b/src/cml.js
@@ -193,10 +193,10 @@ class CML {
   }
 
   async publish(opts = {}) {
-    const { title = '', md, native, gitlabUploads, rmWatermark } = opts;
+    const { title = '', md, native, rmWatermark } = opts;
 
     let mime, uri;
-    if (native || gitlabUploads) {
+    if (native) {
       ({ mime, uri } = await getDriver(this).upload(opts));
     } else {
       ({ mime, uri } = await upload(opts));


Test patch:
diff --git a/bin/cml/publish.test.js b/bin/cml/publish.test.js
index 715bde8..b0504d9 100644
--- a/bin/cml/publish.test.js
+++ b/bin/cml/publish.test.js
@@ -6,37 +6,32 @@ describe('CML e2e', () => {
     const output = await exec(`node ./bin/cml.js publish --help`);
 
     expect(output).toMatchInlineSnapshot(`
-    "cml.js publish <asset>
-
-    Upload an image to build a report
-
-    Options:
-          --help                      Show help                            [boolean]
-          --version                   Show version number                  [boolean]
-          --log                       Maximum log level
-              [string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
-          --md                        Output in markdown format [title ||
-                                      name](url).                          [boolean]
-      -t, --title                     Markdown title [title](url) or ![](url title).
-                                                                            [string]
-          --native, --gitlab-uploads  Uses driver's native capabilities to upload
-                                      assets instead of CML's storage. Currently
-                                      only available for GitLab CI.        [boolean]
-          --rm-watermark              Avoid CML watermark.                 [boolean]
-          --mime-type                 Specifies the mime-type. If not set guess it
-                                      from the content.                     [string]
-      -f, --file                      Append the output to the given file. Create it
-                                      if does not exist.                    [string]
-          --repo                      Specifies the repo to be used. If not
-                                      specified is extracted from the CI ENV.
-                                                                            [string]
-          --token                     Personal access token to be used. If not
-                                      specified, extracted from ENV REPO_TOKEN,
-                                      GITLAB_TOKEN, GITHUB_TOKEN, or
-                                      BITBUCKET_TOKEN.                      [string]
-          --driver                    If not specify it infers it from the ENV.
-                                 [string] [choices: \\"github\\", \\"gitlab\\", \\"bitbucket\\"]"
-  `);
+      "cml.js publish <asset>
+
+      Upload an image to build a report
+
+      Options:
+            --help          Show help                                        [boolean]
+            --version       Show version number                              [boolean]
+            --log           Maximum log level
+                [string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
+            --md            Output in markdown format [title || name](url).  [boolean]
+        -t, --title         Markdown title [title](url) or ![](url title).    [string]
+            --native        Uses driver's native capabilities to upload assets instead
+                            of CML's storage. Not available on GitHub.       [boolean]
+            --rm-watermark  Avoid CML watermark.                             [boolean]
+            --mime-type     Specifies the mime-type. If not set guess it from the
+                            content.                                          [string]
+        -f, --file          Append the output to the given file. Create it if does not
+                            exist.                                            [string]
+            --repo          Specifies the repo to be used. If not specified is
+                            extracted from the CI ENV.                        [string]
+            --token         Personal access token to be used. If not specified,
+                            extracted from ENV REPO_TOKEN, GITLAB_TOKEN, GITHUB_TOKEN,
+                            or BITBUCKET_TOKEN.                               [string]
+            --driver        If not specify it infers it from the ENV.
+                                   [string] [choices: \\"github\\", \\"gitlab\\", \\"bitbucket\\"]"
+    `);
   });
 
   test('cml publish assets/logo.png --md', async () => {
diff --git a/src/cml.test.js b/src/cml.test.js
index db74913..6a2bc7f 100644
--- a/src/cml.test.js
+++ b/src/cml.test.js
@@ -129,7 +129,7 @@ describe('Gitlab tests', () => {
 
     const output = await new CML({ repo: REPO }).publish({
       path,
-      gitlabUploads: true
+      native: true
     });
 
     expect(output.startsWith('https://')).toBe(true);
@@ -144,7 +144,7 @@ describe('Gitlab tests', () => {
       path,
       md: true,
       title,
-      gitlabUploads: true
+      native: true
     });
 
     expect(output.startsWith('![](https://')).toBe(true);
@@ -160,7 +160,7 @@ describe('Gitlab tests', () => {
       path,
       md: true,
       title,
-      gitlabUploads: true
+      native: true
     });
 
     expect(output.startsWith(`[${title}](https://`)).toBe(true);