Repository: codecov/uploader
Pull request #367 (2021-09-16 14:32:46)

Fix encoding of `buildURL`


Patch:
diff --git a/src/ci_providers/provider_appveyorci.ts b/src/ci_providers/provider_appveyorci.ts
index 48d4454..2b94009 100644
--- a/src/ci_providers/provider_appveyorci.ts
+++ b/src/ci_providers/provider_appveyorci.ts
@@ -9,7 +9,7 @@ export function detect(envs: UploaderEnvs): boolean {
 
 function _getBuild(inputs: UploaderInputs) {
   const { args, environment: envs } = inputs
-  return args.build || encodeURIComponent(envs.APPVEYOR_JOB_ID || '')
+  return args.build || envs.APPVEYOR_JOB_ID || ''
 }
 
 function _getBuildURL(inputs: UploaderInputs) {
@@ -20,8 +20,8 @@ function _getBuildURL(inputs: UploaderInputs) {
     envs.APPVEYOR_BUILD_ID &&
     envs.APPVEYOR_JOB_ID
   ) {
-    return encodeURIComponent(
-      `${envs.APPVEYOR_URL}/project/${envs.APPVEYOR_REPO_NAME}/builds/${envs.APPVEYOR_BUILD_ID}/job/${envs.APPVEYOR_JOB_ID}`,
+    return (
+      `${envs.APPVEYOR_URL}/project/${envs.APPVEYOR_REPO_NAME}/builds/${envs.APPVEYOR_BUILD_ID}/job/${envs.APPVEYOR_JOB_ID}`
     )
   }
   return ''
diff --git a/src/ci_providers/provider_azurepipelines.ts b/src/ci_providers/provider_azurepipelines.ts
index c25c719..59e26de 100644
--- a/src/ci_providers/provider_azurepipelines.ts
+++ b/src/ci_providers/provider_azurepipelines.ts
@@ -14,8 +14,8 @@ function _getBuild(inputs: UploaderInputs): string {
 function _getBuildURL(inputs: UploaderInputs): string {
   const { environment: envs } = inputs
   if (envs.SYSTEM_TEAMPROJECT && envs.BUILD_BUILDID) {
-    return encodeURIComponent(
-      `${envs.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs.BUILD_BUILDID}`,
+    return (
+      `${envs.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs.BUILD_BUILDID}`
     )
   }
   return ''
diff --git a/src/ci_providers/provider_circleci.ts b/src/ci_providers/provider_circleci.ts
index cf11294..6ca8eaf 100644
--- a/src/ci_providers/provider_circleci.ts
+++ b/src/ci_providers/provider_circleci.ts
@@ -6,7 +6,7 @@ export function detect(envs: UploaderEnvs): boolean {
 
 // eslint-disable-next-line no-unused-vars
 function _getBuildURL(inputs: UploaderInputs): string {
-  return ''
+  return inputs.environment['CIRCLE_BUILD_URL'] ?? ''
 }
 
 // This is the value that gets passed to the Codecov uploader
diff --git a/src/ci_providers/provider_githubactions.ts b/src/ci_providers/provider_githubactions.ts
index 866655a..776858e 100644
--- a/src/ci_providers/provider_githubactions.ts
+++ b/src/ci_providers/provider_githubactions.ts
@@ -14,10 +14,10 @@ function _getBuild(inputs: UploaderInputs): string {
 
 function _getBuildURL(inputs: UploaderInputs): string {
   const { environment: envs } = inputs
-  return encodeURIComponent(
+  return (
     `${envs.GITHUB_SERVER_URL}/${_getSlug(inputs)}/actions/runs/${_getBuild(
       inputs,
-    )}`,
+    )}`
   )
 }
 
@@ -37,7 +37,7 @@ function _getBranch(inputs: UploaderInputs): string {
 }
 
 function _getJob(envs: UploaderEnvs): string {
-  return encodeURIComponent(envs.GITHUB_WORKFLOW || '')
+  return (envs.GITHUB_WORKFLOW || '')
 }
 
 function _getPR(inputs: UploaderInputs): number {
diff --git a/src/ci_providers/provider_jenkinsci.ts b/src/ci_providers/provider_jenkinsci.ts
index a918be9..abee0cd 100644
--- a/src/ci_providers/provider_jenkinsci.ts
+++ b/src/ci_providers/provider_jenkinsci.ts
@@ -12,7 +12,7 @@ function _getBuild(inputs: UploaderInputs): string {
 
 function _getBuildURL(inputs: UploaderInputs): string {
   const { environment: envs } = inputs
-  return envs.BUILD_URL ? encodeURIComponent(envs.BUILD_URL) : ''
+  return envs.BUILD_URL ? (envs.BUILD_URL) : ''
 }
 
 function _getBranch(inputs: UploaderInputs): string {
diff --git a/src/helpers/web.ts b/src/helpers/web.ts
index f7de0b8..8131991 100644
--- a/src/helpers/web.ts
+++ b/src/helpers/web.ts
@@ -114,9 +114,9 @@ export function generateQuery(queryParams: IServiceParams): string {
   if (queryParams.pr === 0  || isNaN(Number(queryParams.pr))) {
     queryParams.pr = ''
   }
-  return Object.entries(queryParams)
-    .map(([key, value]) => `${snakeCase(key)}=${value}`)
-    .join('&')
+  return new URLSearchParams(Object.entries(queryParams)
+    .map(([key, value]) => [snakeCase(key), value])
+  ).toString()
 }
 
 export function parsePOSTResults(uploadURL: string): {


Test patch:
diff --git a/test/helpers/web.test.ts b/test/helpers/web.test.ts
index 72af2bc..a3d1b26 100644
--- a/test/helpers/web.test.ts
+++ b/test/helpers/web.test.ts
@@ -89,7 +89,7 @@ describe('Web Helpers', () => {
       job: '6',
     }
     expect(generateQuery(queryParams)).toBe(
-      'branch=testBranch&commit=commitSHA&build=4&build_url=https://ci-providor.local/job/xyz&name=testName&tag=tagV1&slug=testOrg/testRepo&service=testingCI&flags=unit,uploader&pr=2&job=6',
+      'branch=testBranch&commit=commitSHA&build=4&build_url=https%3A%2F%2Fci-providor.local%2Fjob%2Fxyz&name=testName&tag=tagV1&slug=testOrg%2FtestRepo&service=testingCI&flags=unit%2Cuploader&pr=2&job=6',
     )
   })
 
@@ -108,7 +108,7 @@ describe('Web Helpers', () => {
       job: '6',
     }
     expect(generateQuery(queryParams)).toBe(
-      'branch=testBranch&commit=commitSHA&build=4&build_url=https://ci-providor.local/job/xyz&name=testName&tag=tagV1&slug=testOrg/testRepo&service=testingCI&flags=unit,uploader&pr=&job=6',
+      'branch=testBranch&commit=commitSHA&build=4&build_url=https%3A%2F%2Fci-providor.local%2Fjob%2Fxyz&name=testName&tag=tagV1&slug=testOrg%2FtestRepo&service=testingCI&flags=unit%2Cuploader&pr=&job=6',
     )
   })
 
diff --git a/test/providers/provider_appveyorci.test.ts b/test/providers/provider_appveyorci.test.ts
index 479f938..e5fbb77 100644
--- a/test/providers/provider_appveyorci.test.ts
+++ b/test/providers/provider_appveyorci.test.ts
@@ -80,7 +80,7 @@ describe('AppveyorCI Params', () => {
       branch: 'main',
       build: '1',
       buildURL:
-        'https%3A%2F%2Fappveyor.com%2Fproject%2FtestOrg%2FtestRepo%2Fbuilds%2F2%2Fjob%2F1',
+        'https://appveyor.com/project/testOrg/testRepo/builds/2/job/1',
       commit: 'testingsha',
       job: 'testOrg%2FtestRepo%2F3',
       pr: 4,
diff --git a/test/providers/provider_azurepipelines.test.ts b/test/providers/provider_azurepipelines.test.ts
index 1e0bd53..4f0ee2a 100644
--- a/test/providers/provider_azurepipelines.test.ts
+++ b/test/providers/provider_azurepipelines.test.ts
@@ -64,7 +64,7 @@ describe('Jenkins CI Params', () => {
       branch: 'main',
       build: '1',
       buildURL:
-        'https%3A%2F%2Fexample.azure.comtestOrg%2F_build%2Fresults%3FbuildId%3D2',
+        'https://example.azure.comtestOrg/_build/results?buildId=2',
       commit: 'testingsha',
       job: '2',
       pr: 3,
@@ -100,7 +100,7 @@ describe('Jenkins CI Params', () => {
       branch: 'main',
       build: '1',
       buildURL:
-        'https%3A%2F%2Fexample.azure.comtestOrg%2F_build%2Fresults%3FbuildId%3D2',
+        'https://example.azure.comtestOrg/_build/results?buildId=2',
       commit: 'testingsha',
       job: '2',
       pr: 3,
@@ -136,7 +136,7 @@ describe('Jenkins CI Params', () => {
       branch: 'main',
       build: '1',
       buildURL:
-        'https%3A%2F%2Fexample.azure.comtestOrg%2F_build%2Fresults%3FbuildId%3D2',
+        'https://example.azure.comtestOrg/_build/results?buildId=2',
       commit: 'testingmergecommitsha2345678901234567890',
       job: '2',
       pr: 3,
diff --git a/test/providers/provider_githubactions.test.ts b/test/providers/provider_githubactions.test.ts
index 71b7c1a..09447d0 100644
--- a/test/providers/provider_githubactions.test.ts
+++ b/test/providers/provider_githubactions.test.ts
@@ -61,7 +61,7 @@ describe('GitHub Actions Params', () => {
       branch: 'master',
       build: '2',
       buildURL:
-        'https%3A%2F%2Fgithub.com%2FtestOrg%2FtestRepo%2Factions%2Fruns%2F2',
+        'https://github.com/testOrg/testRepo/actions/runs/2',
       commit: 'testingsha',
       job: 'testWorkflow',
       pr: 0,
@@ -95,7 +95,7 @@ describe('GitHub Actions Params', () => {
       branch: 'branch',
       build: '2',
       buildURL:
-        'https%3A%2F%2Fgithub.com%2FtestOrg%2FtestRepo%2Factions%2Fruns%2F2',
+        'https://github.com/testOrg/testRepo/actions/runs/2',
       commit: 'testingsha',
       job: 'testWorkflow',
       pr: 1,
@@ -136,7 +136,7 @@ describe('GitHub Actions Params', () => {
       branch: 'branch',
       build: '2',
       buildURL:
-        'https%3A%2F%2Fgithub.com%2FtestOrg%2FtestRepo%2Factions%2Fruns%2F2',
+        'https://github.com/testOrg/testRepo/actions/runs/2',
       commit: 'testingmergecommitsha2345678901234567890',
       job: 'testWorkflow',
       pr: 1,
@@ -177,7 +177,7 @@ describe('GitHub Actions Params', () => {
       branch: 'branch',
       build: '3',
       buildURL:
-        'https%3A%2F%2Fgithub.com%2FtestOrg%2FtestRepo%2Factions%2Fruns%2F3',
+        'https://github.com/testOrg/testRepo/actions/runs/3',
       commit: 'testsha',
       job: '',
       pr: 2,
@@ -216,7 +216,7 @@ describe('GitHub Actions Params', () => {
       branch: 'branch',
       build: '2',
       buildURL:
-        'https%3A%2F%2Fgithub.com%2FtestOrg%2FtestRepo%2Factions%2Fruns%2F2',
+        'https://github.com/testOrg/testRepo/actions/runs/2',
       commit: 'testingsha',
       job: 'testWorkflow',
       pr: 1,
diff --git a/test/providers/provider_jenkinsci.test.ts b/test/providers/provider_jenkinsci.test.ts
index ea530b7..ada1707 100644
--- a/test/providers/provider_jenkinsci.test.ts
+++ b/test/providers/provider_jenkinsci.test.ts
@@ -60,7 +60,7 @@ describe('Jenkins CI Params', () => {
     const expected: IServiceParams = {
       branch: 'main',
       build: '1',
-      buildURL: 'https%3A%2F%2Fexample.jenkins.com',
+      buildURL: 'https://example.jenkins.com',
       commit: 'testingsha',
       job: '',
       pr: 2,