11var fs = require ( 'fs' )
22var path = require ( 'path' )
3- var request = require ( 'request' )
3+ var request = require ( 'teeny- request' ) . teenyRequest
44var urlgrey = require ( 'urlgrey' )
5+ var jsYaml = require ( 'js-yaml' )
56var walk = require ( 'ignore-walk' )
67var 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