File tree Expand file tree Collapse file tree 4 files changed +25
-18
lines changed Expand file tree Collapse file tree 4 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const Yaml = require ( 'js-yaml' ) ;
4+
5+ exports . convert = ( buffer , options ) => {
6+
7+ if ( options . json ) {
8+ return JSON . parse ( buffer . toString ( ) ) ;
9+ }
10+
11+ if ( options . yaml ) {
12+ return Yaml . load ( buffer , {
13+ schema : Yaml . FAILSAFE_SCHEMA ,
14+ json : true
15+ } ) ;
16+ }
17+
18+ return buffer ;
19+ } ;
Original file line number Diff line number Diff line change 33const Fs = require ( 'fs' ) ;
44const Path = require ( 'path' ) ;
55
6+ const Contents = require ( './contents' ) ;
67const Utils = require ( '../utils' ) ;
78
89
@@ -30,11 +31,7 @@ exports.create = async (path) => {
3031
3132 const buffer = Fs . readFileSync ( fullPath ) ;
3233
33- if ( options . json ) {
34- return JSON . parse ( buffer . toString ( ) ) ;
35- }
36-
37- return buffer ;
34+ return Contents . convert ( buffer , options ) ;
3835 }
3936 } ;
4037} ;
Original file line number Diff line number Diff line change 22
33const GitUrlParse = require ( 'git-url-parse' ) ;
44
5+ const Contents = require ( './contents' ) ;
56const Logger = require ( '../logger' ) ;
67const OctokitWrapper = require ( './octokit-wrapper' ) ;
78const Utils = require ( '../utils' ) ;
@@ -60,13 +61,9 @@ exports.create = (repository) => {
6061
6162 Logger . log ( [ 'loader' ] , 'Loaded: %s' , resource ) ;
6263
63- const content = Buffer . from ( result . data . content , 'base64' ) ;
64+ const buffer = Buffer . from ( result . data . content , 'base64' ) ;
6465
65- if ( options . json ) {
66- return JSON . parse ( content . toString ( ) ) ;
67- }
68-
69- return content ;
66+ return Contents . convert ( buffer , options ) ;
7067 }
7168 catch ( err ) {
7269
Original file line number Diff line number Diff line change 11'use strict' ;
22
33const Nv = require ( '@pkgjs/nv' ) ;
4- const Yaml = require ( 'js-yaml' ) ;
54
65const TravisImports = require ( './imports' ) ;
76const Utils = require ( '../utils' ) ;
@@ -75,7 +74,7 @@ internals.scan = async (travisYaml, options) => {
7574exports . detect = async ( { loadFile } ) => {
7675
7776 try {
78- var buffer = await loadFile ( '.travis.yml' ) ;
77+ var travisYaml = await loadFile ( '.travis.yml' , { yaml : true } ) ;
7978 }
8079 catch ( err ) {
8180
@@ -86,11 +85,6 @@ exports.detect = async ({ loadFile }) => {
8685 throw err ;
8786 }
8887
89- const travisYaml = Yaml . load ( buffer , {
90- schema : Yaml . FAILSAFE_SCHEMA ,
91- json : true
92- } ) ;
93-
9488 return {
9589 travis : await internals . scan ( travisYaml , { loadFile } )
9690 } ;
You can’t perform that action at this time.
0 commit comments