Skip to content

Commit f06583c

Browse files
Merge pull request #178 from eddiemoore/feature/verbose
verbose and cleanup
2 parents 04bd3d0 + b514561 commit f06583c

File tree

5 files changed

+116
-90
lines changed

5 files changed

+116
-90
lines changed

bin/codecov

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,129 @@
11
#!/usr/bin/env node
22

3-
const app = require("../src");
3+
const app = require('../src')
44

5-
var argv = require("yargs") // eslint-disable-line
6-
.usage("Usage: $0 <command> [options]")
5+
var argv = require('yargs') // eslint-disable-line
6+
.usage('Usage: $0 <command> [options]')
77
.options({
88
build: {
9-
alias: "b",
10-
description: "Specify the build number manually"
9+
alias: 'b',
10+
description: 'Specify the build number manually',
1111
},
1212
branch: {
13-
alias: "B",
14-
description: "Specify the branch manually"
13+
alias: 'B',
14+
description: 'Specify the branch manually',
1515
},
1616
env: {
17-
alias: "e",
18-
description: "Specify environment variables to be included with this build.\nAlso accepting environment variables: CODECOV_ENV=VAR,VAR2"
17+
alias: 'e',
18+
description:
19+
'Specify environment variables to be included with this build.\nAlso accepting environment variables: CODECOV_ENV=VAR,VAR2',
1920
},
2021
sha: {
21-
alias: "C",
22-
description: "Specify the commit SHA mannually"
22+
alias: 'C',
23+
description: 'Specify the commit SHA mannually',
2324
},
2425
file: {
25-
alias: "f",
26-
description: "Target file(s) to upload"
26+
alias: 'f',
27+
description: 'Target file(s) to upload',
2728
},
2829
flags: {
29-
alias: "F",
30-
default: "",
31-
description: "Flag the upload to group coverage metrics"
30+
alias: 'F',
31+
default: '',
32+
description: 'Flag the upload to group coverage metrics',
3233
},
3334
name: {
34-
alias: "n",
35-
default: "",
36-
description: "Custom defined name of the upload. Visible in Codecov UI"
35+
alias: 'n',
36+
default: '',
37+
description: 'Custom defined name of the upload. Visible in Codecov UI',
3738
},
3839
parent: {
39-
alias: "N",
40-
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."
40+
alias: 'N',
41+
description:
42+
"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.",
4143
},
4244
pr: {
43-
alias: "P",
44-
description: "Specify the pull request number mannually"
45+
alias: 'P',
46+
description: 'Specify the pull request number mannually',
4547
},
4648
dir: {
47-
alias: "s",
48-
description: "Directory to search for coverage reports.\nAlready searches project root and current working directory"
49+
alias: 's',
50+
description:
51+
'Directory to search for coverage reports.\nAlready searches project root and current working directory',
4952
},
5053
token: {
51-
alias: "t",
52-
default: "",
53-
description: "Codecov upload token"
54+
alias: 't',
55+
default: '',
56+
description: 'Codecov upload token',
5457
},
5558
tag: {
56-
alias: "T",
57-
default: "",
58-
description: "Specify the git tag"
59+
alias: 'T',
60+
default: '',
61+
description: 'Specify the git tag',
5962
},
6063
verbose: {
61-
alias: "v",
62-
type: "boolean",
63-
description: "Run with verbose logging"
64+
alias: 'v',
65+
type: 'boolean',
66+
description: 'Run with verbose logging',
6467
},
6568
rootDir: {
66-
alias: "R",
67-
description: "Specify the project root directory when not in a git repo"
69+
alias: 'R',
70+
description: 'Specify the project root directory when not in a git repo',
6871
},
6972
nonZero: {
70-
alias: "Z",
71-
type: "boolean",
73+
alias: 'Z',
74+
type: 'boolean',
7275
default: false,
73-
description: "Should errors exit with a non-zero (default: false)"
76+
description: 'Should errors exit with a non-zero (default: false)',
7477
},
7578
dryRun: {
76-
alias: "d",
77-
type: "boolean",
78-
description: "Don't upload files to Codecov"
79+
alias: 'd',
80+
type: 'boolean',
81+
description: "Don't upload files to Codecov",
7982
},
8083
slug: {
81-
alias: "r",
82-
description: "Specify the slug manually (Enterprise use)"
84+
alias: 'r',
85+
description: 'Specify the slug manually (Enterprise use)',
8386
},
8487
url: {
85-
type: "string",
86-
description: "Change the upload host (Enterprise use)",
87-
default: "https://codecov.io"
88+
type: 'string',
89+
description: 'Change the upload host (Enterprise use)',
90+
default: 'https://codecov.io',
8891
},
8992
clean: {
90-
alias: "c",
91-
type: "boolean",
93+
alias: 'c',
94+
type: 'boolean',
9295
default: false,
93-
description: "Move discovered coverage reports to the trash"
96+
description: 'Move discovered coverage reports to the trash',
9497
},
9598
feature: {
9699
alias: 'X',
97-
type: "string",
100+
type: 'string',
98101
description: `Toggle functionalities
99-
-X network Disable uploading the file network`
100-
}
102+
-X network Disable uploading the file network`,
103+
},
101104
})
102105
.version()
103-
.help("help")
104-
.alias("help", "h").argv;
106+
.help('help')
107+
.alias('help', 'h').argv
105108

106-
const start = Date.now()
109+
const start = Date.now()
107110

108-
app.log(`Start of uploader: ${start}...`, { level: 'debug', argv })
109-
app.main(argv).then(() => {
111+
app.log(`Start of uploader: ${start}...`, { level: 'debug', argv })
112+
app
113+
.main(argv)
114+
.then(() => {
110115
const end = Date.now()
111-
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
112-
}).catch(error => {
116+
app.log(`End of uploader: ${end - start} milliseconds`, {
117+
level: 'debug',
118+
argv,
119+
})
120+
})
121+
.catch(error => {
113122
app.log(`Error!: ${error}`, { level: 'error', argv })
114123
const end = Date.now()
115-
app.log(`End of uploader: ${end - start} milliseconds`, { level: 'debug', argv })
124+
app.log(`End of uploader: ${end - start} milliseconds`, {
125+
level: 'debug',
126+
argv,
127+
})
116128
process.exit(argv.nonZero ? -1 : 0)
117-
})
118-
129+
})

src/helpers/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @param {string|Object} message
66
* @param {Object} [options]
7-
* @param {string} [options.level]
7+
* @param {'debug'|'error'} [options.level]
88
* @param {Object} [options.args]
99
* @returns void
1010
*/

src/helpers/web.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ function camelToSnake(str) {
9999
* @returns {string}
100100
*/
101101
function generateQuery(queryParams) {
102-
const query = Object.entries(queryParams)
102+
return Object.entries(queryParams)
103103
.map(([key, value]) => `${camelToSnake(key)}=${value}`)
104104
.join('&')
105-
return query
106105
}
107106

108107
module.exports = {

src/index.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ const providers = require('./ci_providers')
1313
* @param {string} token
1414
* @param {string} query
1515
* @param {string} uploadFile
16-
* @param {Object} args
17-
* @param {number} start
1816
*/
1917
function dryRun(uploadHost, token, query, uploadFile) {
2018
log('==> Dumping upload file (no upload)')
@@ -145,9 +143,10 @@ async function main(args) {
145143
throw new Error(`Error reading coverage file (${coverageFile}): ${error}`)
146144
}
147145

148-
uploadFile = uploadFile.concat(fileHelpers.fileHeader(coverageFile))
149-
uploadFile = uploadFile.concat(fileContents)
150-
uploadFile = uploadFile.concat(fileHelpers.endFileMarker())
146+
uploadFile = uploadFile
147+
.concat(fileHelpers.fileHeader(coverageFile))
148+
.concat(fileContents)
149+
.concat(fileHelpers.endFileMarker())
151150
}
152151

153152
// Cleanup
@@ -165,8 +164,9 @@ async function main(args) {
165164
.filter(Boolean)
166165
.map(evar => `${evar}=${process.env[evar] || ''}\n`)
167166
.join('')
168-
uploadFile = uploadFile.concat(vars)
169-
uploadFile = uploadFile.concat(fileHelpers.endEnvironmentMarker())
167+
uploadFile = uploadFile
168+
.concat(vars)
169+
.concat(fileHelpers.endEnvironmentMarker())
170170
}
171171

172172
const gzippedFile = zlib.gzipSync(uploadFile)
@@ -195,24 +195,40 @@ async function main(args) {
195195

196196
if (args.dryRun) {
197197
return dryRun(uploadHost, token, query, uploadFile)
198-
} else {
198+
}
199+
200+
log(
201+
`Pinging Codecov: ${uploadHost}/upload/v4?package=uploader-${version}&token=*******&${query}`,
202+
)
203+
try {
199204
log(
200-
`Pinging Codecov: ${uploadHost}/v4?package=uploader-${version}&token=*******&${query}`,
205+
`${uploadHost}/upload/v4?package=uploader-${version}&${query}
206+
Content-Type: 'text/plain'
207+
Content-Encoding: 'gzip'
208+
X-Reduced-Redundancy: 'false'`,
209+
{ level: 'debug', args },
201210
)
202-
try {
203-
const uploadURL = await webHelpers.uploadToCodecov(
204-
uploadHost,
205-
token,
206-
query,
207-
gzippedFile,
208-
version,
209-
)
210-
const result = await webHelpers.uploadToCodecovPUT(uploadURL, gzippedFile)
211-
log(result)
212-
return result
213-
} catch (error) {
214-
throw new Error(`Error uploading to ${uploadHost}: ${error}`)
215-
}
211+
const uploadURL = await webHelpers.uploadToCodecov(
212+
uploadHost,
213+
token,
214+
query,
215+
gzippedFile,
216+
version,
217+
)
218+
219+
log(uploadURL, { level: 'debug', args })
220+
221+
log(
222+
`${uploadURL.split('\n')[1]}
223+
Content-Type: 'text/plain'
224+
Content-Encoding: 'gzip'`,
225+
{ level: 'debug', args },
226+
)
227+
const result = await webHelpers.uploadToCodecovPUT(uploadURL, gzippedFile)
228+
log(result)
229+
return result
230+
} catch (error) {
231+
throw new Error(`Error uploading to ${uploadHost}: ${error}`)
216232
}
217233
}
218234

test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Uploader Core', () => {
3535

3636
nock('https://codecov.io')
3737
.post('/upload/v4')
38-
.query(actualQueryObject => actualQueryObject.name === 'customname')
38+
.query(parsedObj => parsedObj.name === 'customname')
3939
.reply(200, 'https://results.codecov.io\nhttps://codecov.io')
4040

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

0 commit comments

Comments
 (0)