Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit afcf3e5

Browse files
Fixed merge conflicts
2 parents 145cb46 + 023d204 commit afcf3e5

File tree

8 files changed

+1898
-1063
lines changed

8 files changed

+1898
-1063
lines changed

.eslintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"mocha": true
5+
},
6+
"globals": {
7+
"expect": true
8+
},
9+
"extends": ["eslint:recommended", "prettier"],
10+
"rules": {
11+
"no-console": "off",
12+
"no-empty": ["error", { "allowEmptyCatch": true }]
13+
}
14+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ nyc report --reporter=text-lcov > coverage.lcov
9898
- v3.0.2 Security fixes
9999
- v3.0.3 Support non-git/hg root dirs
100100
- v3.0.4 Security fixes
101+
- v3.1.0 Custom yaml file. Allow codecov token from yml file.

bin/codecov

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var args = argv.option([
2121
{name: 'url', short: 'u', type: 'string', description: "Your Codecov endpoint"},
2222
{name: 'flags', short: 'F', type: 'string', description: "Codecov Flags"},
2323
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"},
24-
{name: 'pipe', short: 'l', type: 'boolean', description: "Listen to stdin for coverage data"}
24+
{name: 'pipe', short: 'l', type: 'boolean', description: "Listen to stdin for coverage data"},
25+
{name: 'yml', short: 'y', type: 'string', description: "Configuration file Used to specify the location of the .codecov.yml config file. Defaults to codecov.yml and .codecov.yml"},
2526
]).run();
2627

2728
if (args.options.pipe) {

lib/codecov.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var fs = require('fs')
22
var path = require('path')
3-
var request = require('request')
3+
var request = require('teeny-request').teenyRequest
44
var urlgrey = require('urlgrey')
5+
var jsYaml = require('js-yaml')
56
var walk = require('ignore-walk')
67
var execSync = require('child_process').execSync
78

@@ -145,18 +146,19 @@ var sendToCodecovV2 = function(
145146
on_failure
146147
) {
147148
// Direct to Codecov
148-
request.post(
149+
request(
149150
{
150-
url: urlgrey(codecov_endpoint + '/upload/v2')
151+
uri: urlgrey(codecov_endpoint + '/upload/v2')
151152
.query(query)
152153
.toString(),
154+
method: 'POST',
153155
body: upload_body,
154156
headers: {
155157
'Content-Type': 'text/plain',
156158
Accept: 'text/plain',
157159
},
158160
},
159-
function(err, response, result) {
161+
function(err, response) {
160162
if (err || response.statusCode !== 200) {
161163
console.log(' ' + (err || response.body))
162164
return response
@@ -179,11 +181,12 @@ var sendToCodecovV3 = function(
179181
on_failure
180182
) {
181183
// Direct to S3
182-
request.post(
184+
request(
183185
{
184-
url: urlgrey(codecov_endpoint + '/upload/v4')
186+
uri: urlgrey(codecov_endpoint + '/upload/v4')
185187
.query(query)
186188
.toString(),
189+
method: 'POST',
187190
body: '',
188191
headers: {
189192
'Content-Type': 'text/plain',
@@ -201,16 +204,17 @@ var sendToCodecovV3 = function(
201204
)
202205
} else {
203206
var codecov_report_url = result.split('\n')[0]
204-
request.put(
207+
request(
205208
{
206-
url: result.split('\n')[1],
209+
uri: result.split('\n')[1],
210+
method: 'PUT',
207211
body: upload_body,
208212
headers: {
209213
'Content-Type': 'text/plain',
210214
'x-amz-acl': 'public-read',
211215
},
212216
},
213-
function(err, response, result) {
217+
function(err) {
214218
if (err) {
215219
sendToCodecovV2(
216220
codecov_endpoint,
@@ -240,6 +244,11 @@ var upload = function(args, on_success, on_failure) {
240244
'https://codecov.io'
241245
var query = {}
242246
var debug = []
247+
var yamlFile =
248+
args.options.yml ||
249+
process.env.codecov_yml ||
250+
process.env.CODECOV_YML ||
251+
'codecov.yml'
243252

244253
console.log(
245254
'' +
@@ -253,20 +262,22 @@ var upload = function(args, on_success, on_failure) {
253262
version
254263
)
255264

256-
query.yaml = ['codecov.yml', '.codecov.yml'].reduce(function(result, file) {
257-
return (
258-
result ||
259-
(fs.existsSync(path.resolve(process.cwd(), file)) ? file : undefined)
260-
)
261-
}, undefined)
262-
263265
if ((args.options.disable || '').split(',').indexOf('detect') === -1) {
264266
console.log('==> Detecting CI Provider')
265267
query = detectProvider()
266268
} else {
267269
debug.push('disabled detect')
268270
}
269271

272+
query.yaml = [yamlFile, '.codecov.yml'].reduce(function(result, file) {
273+
return (
274+
result ||
275+
(fs.existsSync(path.resolve(process.cwd(), file))
276+
? path.resolve(process.cwd(), file)
277+
: undefined)
278+
)
279+
}, undefined)
280+
270281
if (args.options.build) {
271282
query.build = args.options.build
272283
}
@@ -289,8 +300,19 @@ var upload = function(args, on_success, on_failure) {
289300
query.flags = flags
290301
}
291302

303+
var yamlToken
304+
try {
305+
var loadedYamlFile = jsYaml.safeLoad(fs.readFileSync(query.yaml, 'utf8'))
306+
yamlToken =
307+
loadedYamlFile && loadedYamlFile.codecov && loadedYamlFile.codecov.token
308+
} catch (e) {
309+
// silently fail
310+
}
292311
var token =
293-
args.options.token || process.env.codecov_token || process.env.CODECOV_TOKEN
312+
args.options.token ||
313+
yamlToken ||
314+
process.env.codecov_token ||
315+
process.env.CODECOV_TOKEN
294316
if (token) {
295317
query.token = token
296318
}

0 commit comments

Comments
 (0)