Repository: codecov/uploader
Pull request #408 (2021-10-05 16:48:13)

Do not include shafiles, Drone repo fix, Update blacklist, and ls-files
- #401
- #404 
- #406 
- #407 


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 667104a..bfab98d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,18 @@
 
 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.4](https://github.com/codecov/uploader/compare/v0.1.3...v0.1.4) (2021-10-05)
+
+### Features
+
+- use `git ls-files` ([6ff874c](https://github.com/codecov/uploader/commit/6ff874c960c7e94ba9e3029dad0592df2b1ad0d0))
+
+### Bug Fixes
+
+- change `projectRoot` to `dirPath` ([93a82de](https://github.com/codecov/uploader/commit/93a82de9a19966ba87ce7f5da03d024c874e0266))
+- correct service name of done.io ci ([46e82d5](https://github.com/codecov/uploader/commit/46e82d56a4e7417eeb92d09e3a5fb9106e4d6234))
+- prevent SHA files from being uploaded ([4bbe5e3](https://github.com/codecov/uploader/commit/4bbe5e3eba3f88efbe2ea2ac00ec143fa5046cf2))
+
 ### [0.1.3](https://github.com/codecov/uploader/compare/v0.1.2...v0.1.3) (2021-09-30)
 
 ### Bug Fixes
diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json
index e8b825b..bbd494c 100644
--- a/npm-shrinkwrap.json
+++ b/npm-shrinkwrap.json
@@ -1,12 +1,12 @@
 {
   "name": "codecov",
-  "version": "0.1.3",
+  "version": "0.1.4",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "codecov",
-      "version": "0.1.3",
+      "version": "0.1.4",
       "license": "ISC",
       "dependencies": {
         "fast-glob": "3.2.7",
diff --git a/package.json b/package.json
index d66cb76..4c56ac2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "codecov",
-  "version": "0.1.3",
+  "version": "0.1.4",
   "description": "Codecov Report Uploader",
   "private": true,
   "bin": "dist/bin/codecov.js",
diff --git a/src/ci_providers/provider_drone.ts b/src/ci_providers/provider_drone.ts
index bcf9184..a938c93 100644
--- a/src/ci_providers/provider_drone.ts
+++ b/src/ci_providers/provider_drone.ts
@@ -30,7 +30,7 @@ function _getPR(inputs: UploaderInputs): string {
 }
 
 function _getService(): string {
-  return 'drone'
+  return 'drone.io'
 }
 
 export function getServiceName(): string {
@@ -44,7 +44,7 @@ function _getSHA(inputs: UploaderInputs): string {
 
 function _getSlug(inputs: UploaderInputs): string {
   const { args, environment: envs } = inputs
-  return args.slug || envs.DRONE_REPO_LINK || ''
+  return args.slug || envs.DRONE_REPO || ''
 }
 
 export function getServiceParams(inputs: UploaderInputs): IServiceParams {
@@ -68,6 +68,6 @@ export function getEnvVarNames(): string[] {
     'DRONE_BUILD_URL',
     'DRONE_COMMIT_SHA',
     'DRONE_PULL_REQUEST',
-    'DRONE_REPO_LINK',
+    'DRONE_REPO',
   ]
 }
diff --git a/src/helpers/files.ts b/src/helpers/files.ts
index 54058f0..39bae8f 100644
--- a/src/helpers/files.ts
+++ b/src/helpers/files.ts
@@ -1,4 +1,4 @@
-import childProcess from 'child_process'
+import childProcess, { spawnSync } from 'child_process'
 import glob from 'fast-glob'
 import fs from 'fs'
 import { readFile } from 'fs/promises'
@@ -34,6 +34,8 @@ export function manualBlacklist(): string[] {
     '.gitignore',
     '.nvmrc',
     '.nyc_output',
+    'bower_components',
+    'jspm_packages',
     'node_modules',
     'vendor',
   ]
@@ -130,6 +132,8 @@ export function globBlacklist(): string[] {
     '*~',
     '.*coveragerc',
     '.coverage*',
+    'codecov.SHA256SUM',
+    'codecov.SHA256SUM.sig',
     'coverage-summary.json',
     'createdFiles.lst',
     'fullLocaleNames.lst',
@@ -195,7 +199,7 @@ export async function getCoverageFiles(
     } else {
       parts.push(globstar(pattern))
     }
-    
+
     return parts.join(EMPTY_STRING)
   }), {
     cwd: projectRoot,
@@ -252,12 +256,22 @@ export function getAllFiles(
 ): string[] {
   verbose(`Searching for files in ${dirPath}`, Boolean(args.verbose))
 
-  return glob
-    .sync(['**/*', '**/.[!.]*'], {
-      cwd: projectRoot,
-      ignore: manualBlacklist().map(globstar),
-    })
-    .map(file => `${file}\n`)
+  const {
+    stdout,
+    status,
+    error,
+  } = spawnSync('git', ['-C', dirPath, 'ls-files'], { encoding: 'utf8' })
+
+  if (error instanceof Error || status !== 0) {
+    return glob
+      .sync(['**/*', '**/.[!.]*'], {
+        cwd: dirPath,
+        ignore: manualBlacklist().map(globstar),
+      })
+      .map(file => `${file}\n`)
+  } else {
+    return stdout.split(/[\r\n]+/)
+  }
 }
 
 /**


Test patch:
diff --git a/test/helpers/files.test.ts b/test/helpers/files.test.ts
index 0a214ee..1bf3247 100644
--- a/test/helpers/files.test.ts
+++ b/test/helpers/files.test.ts
@@ -48,6 +48,15 @@ describe('File Helpers', () => {
     ).toMatch('npm-shrinkwrap.json')
   })
 
+  it('can get a file listing when git is unavailable', async () => {
+    td.replace(childProcess, 'spawnSync', () => {
+      return { stdout: '', status: null, error: new Error() }
+    })
+    expect(
+      await fileHelpers.getFileListing('.', { flags: '', verbose: 'true' }),
+    ).toMatch('npm-shrinkwrap.json')
+  })
+
   it('can parse the .gitignore file', () => {
     const readFileSync = td.replace(fs, 'readFileSync')
     td.when(readFileSync('.gitignore')).thenReturn(
diff --git a/test/providers/provider_drone.test.ts b/test/providers/provider_drone.test.ts
index 4b3d38d..b8d70cd 100644
--- a/test/providers/provider_drone.test.ts
+++ b/test/providers/provider_drone.test.ts
@@ -47,7 +47,7 @@ describe('Drone Params', () => {
         DRONE_BUILD_NUMBER: '2',
         DRONE_PULL_REQUEST: '1',
         DRONE_BUILD_URL: 'https://www.drone.io/',
-        DRONE_REPO_LINK: 'https:/example.com/repo',
+        DRONE_REPO: 'repo',
       },
     }
     const expected: IServiceParams = {
@@ -57,8 +57,8 @@ describe('Drone Params', () => {
       commit: 'testingsha',
       job: '',
       pr: '1',
-      service: 'drone',
-      slug: 'https:/example.com/repo',
+      service: 'drone.io',
+      slug: 'repo',
     }
     const params = providerDrone.getServiceParams(inputs)
     expect(params).toMatchObject(expected)