Skip to content

Commit

Permalink
Merge pull request #367 from codecov/wip/build-url
Browse files Browse the repository at this point in the history
Fix encoding of `buildURL`
  • Loading branch information
mitchell-codecov authored Sep 16, 2021
2 parents 6b330f7 + a6e3abf commit 7ba8b19
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/ci_providers/provider_appveyorci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 ''
Expand Down
4 changes: 2 additions & 2 deletions src/ci_providers/provider_azurepipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
2 changes: 1 addition & 1 deletion src/ci_providers/provider_circleci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/ci_providers/provider_githubactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}`,
)}`
)
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/ci_providers/provider_jenkinsci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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): {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
})

Expand All @@ -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',
)
})

Expand Down
2 changes: 1 addition & 1 deletion test/providers/provider_appveyorci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test/providers/provider_azurepipelines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions test/providers/provider_githubactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/providers/provider_jenkinsci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7ba8b19

Please sign in to comment.