Skip to content

Commit

Permalink
parent commit sha (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoore authored May 10, 2021
1 parent c92854b commit c7d1eb3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
4 changes: 4 additions & 0 deletions bin/codecov
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var argv = require("yargs") // eslint-disable-line
default: "",
description: "Custom defined name of the upload. Visible in Codecov UI"
},
parent: {
alias: "N",
description: "The commit SHA of the parent for which you are uploading coverage. If not present, the parent will be determined using the API of your repository provider. When using the repository provider's API, the parent is determined via finding the closest ancestor to the commit."
},
pr: {
alias: "P",
description: "Specify the pull request number mannually"
Expand Down
36 changes: 12 additions & 24 deletions src/helpers/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function populateBuildParams (inputs, serviceParams) {
serviceParams.flags = validateHelpers.validateFlags(args.flags)
? args.flags
: ''
serviceParams.parent = args.parent || ''
return serviceParams
}

Expand Down Expand Up @@ -67,31 +68,18 @@ async function uploadToCodecov (uploadURL, token, query, uploadFile, version) {
}
}


function camelToSnake(str) {
return str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(s => s.toLowerCase())
.join('_')
}

function generateQuery (queryParams) {
const query = ''.concat(
'branch=',
queryParams.branch,
'&commit=',
queryParams.commit,
'&build=',
queryParams.build,
'&build_url=',
queryParams.buildURL,
'&name=',
queryParams.name,
'&tag=',
queryParams.tag,
'&slug=',
queryParams.slug,
'&service=',
queryParams.service,
'&flags=',
queryParams.flags,
'&pr=',
queryParams.pr,
'&job=',
queryParams.job
)
const query = Object
.entries(queryParams)
.map(([key, value]) => `${camelToSnake(key)}=${value}`)
.join('&')
return query
}

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function dryRun (uploadHost, token, query, uploadFile) {
* @param {string} args.file Target file(s) to upload
* @param {string} args.flags Flag the upload to group coverage metrics
* @param {string} args.name Custom defined name of the upload. Visible in Codecov UI
* @param {string} args.parent The commit SHA of the parent for which you are uploading coverage.
* @param {string} args.pr Specify the pull request number mannually
* @param {string} args.token Codecov upload token
* @param {string} args.tag Specify the git tag
Expand Down
10 changes: 5 additions & 5 deletions test/helpers/web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ describe('Web Helpers', function () {
const queryParams = {}
queryParams.branch = 'testBranch'
queryParams.commit = 'commitSHA'
queryParams.buildURL = 'https://ci-providor.local/job/xyz'
queryParams.job = '6'
queryParams.flags = 'unit,uploader'
queryParams.slug = 'testOrg/testRepo'
queryParams.build = '4'
queryParams.service = 'testingCI'
queryParams.buildURL = 'https://ci-providor.local/job/xyz'
queryParams.name = 'testName'
queryParams.tag = 'tagV1'
queryParams.slug = 'testOrg/testRepo'
queryParams.service = 'testingCI'
queryParams.flags = 'unit,uploader'
queryParams.pr = '2'
queryParams.job = '6'
expect(webHelper.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'
)
Expand Down
23 changes: 23 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,27 @@ describe('Uploader Core', function () {
})
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
}, 30000)

it('Can upload with parent sha', async function () {
process.env.CI = 'true'
process.env.CIRCLECI = 'true'

const parent = '2x4bqz123abc'

nock('https://codecov.io')
.post('/upload/v4')
.query(actualQueryObject => actualQueryObject.parent === parent)
.reply(200, 'https://results.codecov.io\nhttps://codecov.io')

nock('https://codecov.io')
.put('/')
.reply(200, 'success')

const result = await app.main({
token: 'abcdefg',
url: 'https://codecov.io',
parent,
})
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
}, 30000)
})

0 comments on commit c7d1eb3

Please sign in to comment.