Repository: atlassian/changesets
Pull request #209 (2019-11-01 07:37:11)

Skip OTP check during isCI
During CI, a token shouldn't be required.

changeset-bot[bot]: ###  🦋  Changeset is good to go

Latest commit: 60d063cd79dca1dd0f7dd0750cd93e69d67037a7

**We got this.**

Not sure what this means? [Click here  to learn what changesets are](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/ryanbraganza/changesets/new/skip-otp-check-during-isCI?filename=.changeset/khaki-geckos-occur.md)


codecov[bot]: # [Codecov](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=h1) Report
> Merging [#209](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=desc) into [master](https://codecov.io/gh/atlassian/changesets/commit/3847edc21664505bd2773cb1f19ff3c718991454?src=pr&el=desc) will **increase** coverage by `0.54%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/atlassian/changesets/pull/209/graphs/tree.svg?width=650&token=j0W25zrXm2&height=150&src=pr)](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage    77.1%   77.64%   +0.54%     
==========================================
  Files          44       41       -3     
  Lines        1175     1020     -155     
  Branches      258      224      -34     
==========================================
- Hits          906      792     -114     
+ Misses        265      222      -43     
- Partials        4        6       +2
```


| [Impacted Files](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...ckages/cli/src/commands/publish/publishPackages.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvY2xpL3NyYy9jb21tYW5kcy9wdWJsaXNoL3B1Ymxpc2hQYWNrYWdlcy50cw==) | `75.75% <0%> (+75.75%)` | :arrow_up: |
| [packages/cli/src/utils/cli.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvY2xpL3NyYy91dGlscy9jbGkudHM=) | `10% <0%> (-11.74%)` | :arrow_down: |
| [packages/assemble-release-plan/src/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvYXNzZW1ibGUtcmVsZWFzZS1wbGFuL3NyYy9pbmRleC50cw==) | `88.88% <0%> (-6.57%)` | :arrow_down: |
| [packages/apply-release-plan/src/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvYXBwbHktcmVsZWFzZS1wbGFuL3NyYy9pbmRleC50cw==) | `86.2% <0%> (-6.35%)` | :arrow_down: |
| [packages/cli/src/commands/version/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvY2xpL3NyYy9jb21tYW5kcy92ZXJzaW9uL2luZGV4LnRz) | `65.51% <0%> (-5.54%)` | :arrow_down: |
| [packages/cli/src/commands/add/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvY2xpL3NyYy9jb21tYW5kcy9hZGQvaW5kZXgudHM=) | `65.51% <0%> (-4.18%)` | :arrow_down: |
| [packages/parse/src/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvcGFyc2Uvc3JjL2luZGV4LnRz) | `76.92% <0%> (-3.08%)` | :arrow_down: |
| [packages/get-release-plan/src/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvZ2V0LXJlbGVhc2UtcGxhbi9zcmMvaW5kZXgudHM=) | `88.88% <0%> (-1.12%)` | :arrow_down: |
| [packages/config/src/index.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvY29uZmlnL3NyYy9pbmRleC50cw==) | `100% <0%> (ø)` | :arrow_up: |
| [...ages/assemble-release-plan/src/flatten-releases.ts](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree#diff-cGFja2FnZXMvYXNzZW1ibGUtcmVsZWFzZS1wbGFuL3NyYy9mbGF0dGVuLXJlbGVhc2VzLnRz) | `88.88% <0%> (ø)` | :arrow_up: |
| ... and [16 more](https://codecov.io/gh/atlassian/changesets/pull/209/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=footer). Last update [3847edc...60d063c](https://codecov.io/gh/atlassian/changesets/pull/209?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Noviny: I'm happy with this change. I wouldn't mind stopping the codecov from failing, and this needs a conflict resolved, but happy to merge and release this to unblock you without going too deep on ensuring coverage up.
ryanbraganza: d'oh, I did the classic "fetch origin" thing, but my origin is set to my fork. I'll fix the conflicts.

Patch:
diff --git a/.changeset/fluffy-melons-kiss.md b/.changeset/fluffy-melons-kiss.md
new file mode 100644
index 0000000..d325261
--- /dev/null
+++ b/.changeset/fluffy-melons-kiss.md
@@ -0,0 +1,5 @@
+---
+"@changesets/cli": patch
+---
+
+Skip OTP check during isCI
diff --git a/packages/cli/src/commands/publish/publishPackages.ts b/packages/cli/src/commands/publish/publishPackages.ts
index 799de4a..c73ba68 100644
--- a/packages/cli/src/commands/publish/publishPackages.ts
+++ b/packages/cli/src/commands/publish/publishPackages.ts
@@ -7,6 +7,8 @@ import * as npmUtils from "./npm-utils";
 import { info, warn } from "@changesets/logger";
 import { TwoFactorState } from "../../utils/types";
 import { PreState } from "@changesets/types";
+// @ts-ignore
+import isCI from "is-ci";
 
 export default async function publishPackages({
   cwd,
@@ -26,8 +28,10 @@ export default async function publishPackages({
     otp === undefined
       ? {
           token: null,
-          // note: we're not awaiting this here, we want this request to happen in parallel with getUnpublishedPackages
-          isRequired: npmUtils.getTokenIsRequired()
+          isRequired: isCI
+            ? Promise.resolve(false)
+            : // note: we're not awaiting this here, we want this request to happen in parallel with getUnpublishedPackages
+              npmUtils.getTokenIsRequired()
         }
       : {
           token: otp,


Test patch:
diff --git a/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts b/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts
new file mode 100644
index 0000000..c87b8b7
--- /dev/null
+++ b/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts
@@ -0,0 +1,39 @@
+import { copyFixtureIntoTempDir } from "jest-fixtures";
+
+import publishPackages from "../publishPackages";
+import * as npmUtils from "../npm-utils";
+
+jest.mock("../npm-utils");
+jest.mock("is-ci", () => true);
+
+describe("publishPackages", () => {
+  let cwd: string;
+
+  beforeEach(async () => {
+    cwd = await copyFixtureIntoTempDir(__dirname, "simple-project");
+
+    // @ts-ignore
+    npmUtils.infoAllow404.mockImplementation(() => ({
+      published: false,
+      pkgInfo: {
+        version: "1.0.0"
+      }
+    }));
+
+    // @ts-ignore
+    npmUtils.publish.mockImplementation(() => ({
+      published: true
+    }));
+  });
+
+  afterEach(() => {
+    jest.clearAllMocks();
+  });
+
+  describe("when isCI", () => {
+    it("does not call out to npm to see if otp is required", async () => {
+      await publishPackages({ cwd, access: "public", preState: undefined });
+      expect(npmUtils.getTokenIsRequired).not.toHaveBeenCalled();
+    });
+  });
+});