Skip to content

Commit b8157ae

Browse files
Merge pull request #213 from codecov/validate-token
fix: correctly validate token
2 parents 127584e + 4faa6cd commit b8157ae

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/index.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const providers = require('./ci_providers')
1717
function dryRun(uploadHost, token, query, uploadFile, source) {
1818
log('==> Dumping upload file (no upload)')
1919
log(
20-
`${uploadHost}/upload/v4?package=${webHelpers.getPackage(source)}&token=${token}&${query}`,
20+
`${uploadHost}/upload/v4?package=${webHelpers.getPackage(
21+
source,
22+
)}&token=${token}&${query}`,
2123
)
2224
log(uploadFile)
2325
}
@@ -69,8 +71,11 @@ async function main(args) {
6971
let token = validateHelpers.validateToken(args.token) ? args.token : ''
7072
if (token === '') {
7173
token = process.env.CODECOV_TOKEN || ''
74+
token = validateHelpers.validateToken(process.env.CODECOV_TOKEN)
75+
? process.env.CODECOV_TOKEN
76+
: ''
7277
}
73-
token = args.token || process.env.CODECOV_TOKEN || ''
78+
7479
log(generateHeader(getVersion()))
7580

7681
// == Step 2: detect if we are in a git repo
@@ -120,14 +125,14 @@ async function main(args) {
120125
)
121126
}
122127
} else {
123-
if (typeof(args.file) === 'string') {
128+
if (typeof args.file === 'string') {
124129
coverageFilePaths = [args.file]
125130
} else {
126131
coverageFilePaths = args.file
127132
}
128133

129-
coverageFilePaths.filter((file) => {
130-
return validateHelpers.validateFileNamePath(file);
134+
coverageFilePaths.filter(file => {
135+
return validateHelpers.validateFileNamePath(file)
131136
})
132137
if (coverageFilePaths.length === 0) {
133138
throw new Error('No coverage files found, exiting.')
@@ -143,13 +148,13 @@ async function main(args) {
143148
let fileContents
144149
try {
145150
log(`Processing ${coverageFile}...`),
146-
fileContents = await fileHelpers.readCoverageFile(
147-
args.dir || projectRoot,
148-
coverageFile,
149-
)
151+
(fileContents = await fileHelpers.readCoverageFile(
152+
args.dir || projectRoot,
153+
coverageFile,
154+
))
150155
} catch (error) {
151156
log(`Could not read coverage file (${coverageFile}): ${error}`)
152-
continue;
157+
continue
153158
}
154159

155160
uploadFile = uploadFile
@@ -207,11 +212,15 @@ async function main(args) {
207212
}
208213

209214
log(
210-
`Pinging Codecov: ${uploadHost}/upload/v4?package=${webHelpers.getPackage(args.source)}&token=*******&${query}`,
215+
`Pinging Codecov: ${uploadHost}/upload/v4?package=${webHelpers.getPackage(
216+
args.source,
217+
)}&token=*******&${query}`,
211218
)
212219
try {
213220
log(
214-
`${uploadHost}/upload/v4?package=${webHelpers.getPackage(args.source)}&${query}
221+
`${uploadHost}/upload/v4?package=${webHelpers.getPackage(
222+
args.source,
223+
)}&${query}
215224
Content-Type: 'text/plain'
216225
Content-Encoding: 'gzip'
217226
X-Reduced-Redundancy: 'false'`,

0 commit comments

Comments
 (0)