Repository: codecov/uploader
Pull request #674 (2022-03-21 14:47:43)

Release v0.1.20
## What's Changed
* fix: add helper arg array method, pass in extra gcov args by @michael-codecov in https://github.com/codecov/uploader/pull/658
* Release 0.1.19 by @michael-codecov in https://github.com/codecov/uploader/pull/661
* chore(deps): update node.js to v16.14.1 by @renovate in https://github.com/codecov/uploader/pull/665
* chore(deps): update node.js to v16.14.2 by @renovate in https://github.com/codecov/uploader/pull/668
* feat: add bitrise provider by @thomasrockhu-codecov in https://github.com/codecov/uploader/pull/670


**Full Changelog**: https://github.com/codecov/uploader/compare/v0.1.18...v0.1.20


Patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index f4f06a8..1ff331e 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -56,7 +56,7 @@ jobs:
   build-alpine:
     docker:
       # specify the version you desire here
-      - image: alpine:3.15.0
+      - image: alpine:3.15.1
 
       # Specify service dependencies here if necessary
       # CircleCI maintains a library of pre-built images
@@ -120,7 +120,7 @@ jobs:
   test-alpine:
     docker:
       # specify the version you desire here
-      - image: alpine:3.15.0
+      - image: alpine:3.15.1
     steps:
       - run:
           name: Install git
@@ -156,7 +156,7 @@ jobs:
   test-alpine-proxy:
     docker:
       # specify the version you desire here
-      - image: alpine:3.15.0
+      - image: alpine:3.15.1
     steps:
       - run:
           name: Install git
@@ -190,7 +190,7 @@ jobs:
   test-alpine-without-git:
     docker:
       # specify the version you desire here
-      - image: alpine:3.15.0
+      - image: alpine:3.15.1
     steps:
       - run:
           name: Install git
diff --git a/.nvmrc b/.nvmrc
index 832d385..d9f8800 100644
--- a/.nvmrc
+++ b/.nvmrc
@@ -1,1 +1,1 @@
-16.14.0
+16.14.2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index caaf371..53eb00f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,16 @@
 
 All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
 
+### [0.1.20](https://github.com/codecov/uploader/compare/v0.1.18...v0.1.20) (2022-03-21)
+
+### Features
+
+- add bitrise provider ([f02e1cf](https://github.com/codecov/uploader/commit/f02e1cf307bf076b01b323f4e01c4a3d7b006c53))
+
+### Bug Fixes
+
+- add helper arg array method, pass in extra gcov args ([57459e3](https://github.com/codecov/uploader/commit/57459e3b98ea9855da67f7d3c9ac6cd2a8e1c398))
+
 ### [0.1.19](https://github.com/codecov/uploader/compare/v0.1.18...v0.1.19) (2022-03-10)
 
 ### Bug Fixes
diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json
index 7c7807c..8d20348 100644
--- a/npm-shrinkwrap.json
+++ b/npm-shrinkwrap.json
@@ -1,12 +1,12 @@
 {
   "name": "@codecov/uploader",
-  "version": "0.1.19",
+  "version": "0.1.20",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "@codecov/uploader",
-      "version": "0.1.19",
+      "version": "0.1.20",
       "license": "ISC",
       "dependencies": {
         "fast-glob": "3.2.11",
diff --git a/package.json b/package.json
index 4077853..063cde1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@codecov/uploader",
-  "version": "0.1.19",
+  "version": "0.1.20",
   "description": "Codecov Report Uploader",
   "private": true,
   "bin": {
diff --git a/src/ci_providers/index.ts b/src/ci_providers/index.ts
index 5055427..a757a89 100644
--- a/src/ci_providers/index.ts
+++ b/src/ci_providers/index.ts
@@ -3,6 +3,7 @@ import { IProvider } from '../types'
 import * as providerAppveyorci from './provider_appveyorci'
 import * as providerAzurepipelines from './provider_azurepipelines'
 import * as providerBitbucket from './provider_bitbucket'
+import * as providerBitrise from './provider_bitrise'
 import * as providerBuildkite from './provider_buildkite'
 import * as providerCircleci from './provider_circleci'
 import * as providerCirrus from './provider_cirrus'
@@ -23,6 +24,7 @@ const providerList: IProvider[] = [
   providerAppveyorci,
   providerAzurepipelines,
   providerBitbucket,
+  providerBitrise,
   providerBuildkite,
   providerCircleci,
   providerCirrus,
diff --git a/src/ci_providers/provider_bitrise.ts b/src/ci_providers/provider_bitrise.ts
new file mode 100644
index 0000000..bdcccb3
--- /dev/null
+++ b/src/ci_providers/provider_bitrise.ts
@@ -0,0 +1,74 @@
+import { IServiceParams, UploaderEnvs, UploaderInputs } from '../types'
+
+import { parseSlugFromRemoteAddr } from '../helpers/git'
+
+export function detect(envs: UploaderEnvs): boolean {
+  return Boolean(envs.CI) && Boolean(envs.BITRISE_IO)
+}
+
+function _getBuild(inputs: UploaderInputs): string {
+  const { args, environment: envs } = inputs
+  return args.build || envs.BITRISE_BUILD_NUMBER || ''
+}
+
+function _getBuildURL(inputs: UploaderInputs): string {
+  const { environment: envs } = inputs
+  return envs.BITRISE_BUILD_URL || ''
+}
+
+function _getBranch(inputs: UploaderInputs): string {
+  const { args, environment: envs } = inputs
+  return args.branch || envs.BITRISE_GIT_BRANCH || ''
+}
+
+function _getJob() {
+  return ''
+}
+
+function _getPR(inputs: UploaderInputs): string {
+  const { args, environment: envs } = inputs
+  return args.pr || envs.BITRISE_PULL_REQUEST || ''
+}
+
+function _getService(): string {
+  return 'bitrise'
+}
+
+export function getServiceName(): string {
+  return 'Bitrise CI'
+}
+
+function _getSHA(inputs: UploaderInputs): string {
+  const { args, environment: envs } = inputs
+  return args.sha || envs.GIT_CLONE_COMMIT_HASH || ''
+}
+
+function _getSlug(inputs: UploaderInputs): string {
+  const { args } = inputs
+  return args.slug || parseSlugFromRemoteAddr('') || ''
+}
+
+export function getServiceParams(inputs: UploaderInputs): IServiceParams {
+  return {
+    branch: _getBranch(inputs),
+    build: _getBuild(inputs),
+    buildURL: _getBuildURL(inputs),
+    commit: _getSHA(inputs),
+    job: _getJob(),
+    pr: _getPR(inputs),
+    service: _getService(),
+    slug: _getSlug(inputs),
+  }
+}
+
+export function getEnvVarNames(): string[] {
+  return [
+    'BITRISE_BUILD_NUMBER',
+    'BITRISE_BUILD_URL',
+    'BITRISE_GIT_BRANCH',
+    'BITRISE_IO',
+    'BITRISE_PULL_REQUEST',
+    'CI',
+    'GIT_CLONE_COMMIT_HASH',
+  ]
+}


Test patch:
diff --git a/test/providers/provider_bitrise.test.ts b/test/providers/provider_bitrise.test.ts
new file mode 100644
index 0000000..397640c
--- /dev/null
+++ b/test/providers/provider_bitrise.test.ts
@@ -0,0 +1,177 @@
+import td from 'testdouble'
+import childProcess from 'child_process'
+import { IServiceParams, UploaderInputs } from '../../src/types'
+import { createEmptyArgs } from '../test_helpers'
+
+import * as providerBitrise from '../../src/ci_providers//provider_bitrise'
+
+describe('Bitrise Params', () => {
+  afterEach(() => {
+    td.reset()
+  })
+
+  describe('detect()', () => {
+    it('does not run without Bitrise env variable', () => {
+      const inputs: UploaderInputs = {
+        args: { ...createEmptyArgs() },
+        environment: {},
+      }
+      const detected = providerBitrise.detect(inputs.environment)
+      expect(detected).toBeFalsy()
+    })
+
+    it('does not run with only CI env variable', () => {
+      const inputs: UploaderInputs= {
+        args: { ...createEmptyArgs() },
+        environment: {
+          CI: 'true',
+        },
+      }
+      const detected = providerBitrise.detect(inputs.environment)
+      expect(detected).toBeFalsy()
+    })
+
+    it('runs with Bitrise env variables', () => {
+      const inputs: UploaderInputs= {
+        args: { ...createEmptyArgs() },
+        environment: {
+          BITRISE_IO: 'true',
+          CI: 'true',
+        },
+      }
+      const detected = providerBitrise.detect(inputs.environment)
+      expect(detected).toBeTruthy()
+    })
+  })
+
+  // This should test that the provider outputs proper default values
+  it('gets the correct params on no env variables', () => {
+    const inputs: UploaderInputs = {
+      args: { ...createEmptyArgs() },
+      environment: {
+        BITRISE_IO: 'true',
+        CI: 'true',
+      },
+    }
+    const expected: IServiceParams = {
+      branch: '',
+      build: '',
+      buildURL: '',
+      commit: '',
+      job: '',
+      pr: '',
+      service: 'bitrise',
+      slug: '',
+    }
+    const spawnSync = td.replace(childProcess, 'spawnSync')
+    td.when(
+      spawnSync('git', ['config', '--get', 'remote.origin.url']),
+    ).thenReturn({ stdout: '' })
+
+    const params = providerBitrise.getServiceParams(inputs)
+    expect(params).toMatchObject(expected)
+  })
+
+  // This should test that the provider outputs proper parameters when a push event is created
+  it('gets the correct params on push', () => {
+    const inputs: UploaderInputs = {
+      args: { ...createEmptyArgs() },
+      environment: {
+        BITRISE_BUILD_NUMBER: '2',
+        BITRISE_BUILD_URL: 'https://bitrise.com/testOrg/testRepo/2',
+        BITRISE_GIT_BRANCH: 'main',
+        BITRISE_IO: 'true',
+        CI: 'true',
+        GIT_CLONE_COMMIT_HASH: 'testingSha',
+      },
+    }
+    const expected: IServiceParams = {
+      branch: 'main',
+      build: '2',
+      buildURL: 'https://bitrise.com/testOrg/testRepo/2',
+      commit: 'testingSha',
+      job: '',
+      pr: '',
+      service: 'bitrise',
+      slug: 'testOrg/testRepo',
+    }
+    const spawnSync = td.replace(childProcess, 'spawnSync')
+    td.when(
+      spawnSync('git', ['config', '--get', 'remote.origin.url']),
+    ).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
+    const params = providerBitrise.getServiceParams(inputs)
+    expect(params).toMatchObject(expected)
+  })
+
+  it('gets the correct params on pr', () => {
+    const inputs: UploaderInputs = {
+      args: { ...createEmptyArgs() },
+      environment: {
+        BITRISE_BUILD_NUMBER: '2',
+        BITRISE_BUILD_URL: 'https://bitrise.com/testOrg/testRepo/2',
+        BITRISE_GIT_BRANCH: 'main',
+        BITRISE_IO: 'true',
+        BITRISE_PULL_REQUEST: '3',
+        CI: 'true',
+        GIT_CLONE_COMMIT_HASH: 'testingSha',
+      },
+    }
+    const expected: IServiceParams = {
+      branch: 'main',
+      build: '2',
+      buildURL: 'https://bitrise.com/testOrg/testRepo/2',
+      commit: 'testingSha',
+      job: '',
+      pr: '3',
+      service: 'bitrise',
+      slug: 'testOrg/testRepo',
+    }
+    const spawnSync = td.replace(childProcess, 'spawnSync')
+    td.when(
+      spawnSync('git', ['config', '--get', 'remote.origin.url']),
+    ).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
+    const params = providerBitrise.getServiceParams(inputs)
+    expect(params).toMatchObject(expected)
+  })
+
+  // This should test that the provider outputs proper parameters when given overrides
+  it('gets the correct params on overrides', () => {
+    const inputs: UploaderInputs = {
+      args: {
+        ...createEmptyArgs(),
+        ...{
+          branch: 'test',
+          build: '10',
+          pr: '11',
+          sha: 'otherTestingSha',
+          slug: 'neworg/newRepo',
+        },
+      },
+      environment: {
+        BITRISE_BUILD_NUMBER: '2',
+        BITRISE_BUILD_URL: 'https://bitrise.com/testOrg/testRepo/2',
+        BITRISE_GIT_BRANCH: 'main',
+        BITRISE_IO: 'true',
+        BITRISE_PULL_REQUEST: '3',
+        CI: 'true',
+        GIT_CLONE_COMMIT_HASH: 'testingSha',
+      },
+    }
+    const expected: IServiceParams = {
+      branch: 'test',
+      build: '10',
+      buildURL: 'https://bitrise.com/testOrg/testRepo/2',
+      commit: 'otherTestingSha',
+      job: '',
+      pr: '11',
+      service: 'bitrise',
+      slug: 'neworg/newRepo',
+    }
+    const spawnSync = td.replace(childProcess, 'spawnSync')
+    td.when(
+      spawnSync('git', ['config', '--get', 'remote.origin.url']),
+    ).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
+    const params = providerBitrise.getServiceParams(inputs)
+    expect(params).toMatchObject(expected)
+  })
+})