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 3
3
const Fs = require ( 'fs' ) ;
4
4
const Path = require ( 'path' ) ;
5
5
6
+ const Contents = require ( './contents' ) ;
6
7
const Utils = require ( '../utils' ) ;
7
8
8
9
@@ -30,11 +31,7 @@ exports.create = async (path) => {
30
31
31
32
const buffer = Fs . readFileSync ( fullPath ) ;
32
33
33
- if ( options . json ) {
34
- return JSON . parse ( buffer . toString ( ) ) ;
35
- }
36
-
37
- return buffer ;
34
+ return Contents . convert ( buffer , options ) ;
38
35
}
39
36
} ;
40
37
} ;
Original file line number Diff line number Diff line change 2
2
3
3
const GitUrlParse = require ( 'git-url-parse' ) ;
4
4
5
+ const Contents = require ( './contents' ) ;
5
6
const Logger = require ( '../logger' ) ;
6
7
const OctokitWrapper = require ( './octokit-wrapper' ) ;
7
8
const Utils = require ( '../utils' ) ;
@@ -60,13 +61,9 @@ exports.create = (repository) => {
60
61
61
62
Logger . log ( [ 'loader' ] , 'Loaded: %s' , resource ) ;
62
63
63
- const content = Buffer . from ( result . data . content , 'base64' ) ;
64
+ const buffer = Buffer . from ( result . data . content , 'base64' ) ;
64
65
65
- if ( options . json ) {
66
- return JSON . parse ( content . toString ( ) ) ;
67
- }
68
-
69
- return content ;
66
+ return Contents . convert ( buffer , options ) ;
70
67
}
71
68
catch ( err ) {
72
69
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const Nv = require ( '@pkgjs/nv' ) ;
4
- const Yaml = require ( 'js-yaml' ) ;
5
4
6
5
const TravisImports = require ( './imports' ) ;
7
6
const Utils = require ( '../utils' ) ;
@@ -75,7 +74,7 @@ internals.scan = async (travisYaml, options) => {
75
74
exports . detect = async ( { loadFile } ) => {
76
75
77
76
try {
78
- var buffer = await loadFile ( '.travis.yml' ) ;
77
+ var travisYaml = await loadFile ( '.travis.yml' , { yaml : true } ) ;
79
78
}
80
79
catch ( err ) {
81
80
@@ -86,11 +85,6 @@ exports.detect = async ({ loadFile }) => {
86
85
throw err ;
87
86
}
88
87
89
- const travisYaml = Yaml . load ( buffer , {
90
- schema : Yaml . FAILSAFE_SCHEMA ,
91
- json : true
92
- } ) ;
93
-
94
88
return {
95
89
travis : await internals . scan ( travisYaml , { loadFile } )
96
90
} ;
You can’t perform that action at this time.
0 commit comments