@@ -4,10 +4,10 @@ const Url = require('url');
4
4
const http = require ( 'http' ) ;
5
5
const https = require ( 'https' ) ;
6
6
7
- const lcov = require ( '../lib/lcov' ) ;
8
- const cobertura = require ( '../lib/cobertura' ) ;
9
- const golang = require ( '../lib/golang' ) ;
10
- const jacoco = require ( '../lib/jacoco' ) ;
7
+ const lcov = require ( '../lib/parsers/ lcov' ) ;
8
+ const cobertura = require ( '../lib/parsers/ cobertura' ) ;
9
+ const golang = require ( '../lib/parsers/ golang' ) ;
10
+ const jacoco = require ( '../lib/parsers/ jacoco' ) ;
11
11
12
12
const git = require ( '../lib/git' ) ;
13
13
const ci = require ( '../lib/ci' ) ;
@@ -16,90 +16,94 @@ module.exports = function cli({ parser, input, url, basePath }) {
16
16
const parsedUrl = Url . parse ( url ) ;
17
17
18
18
return new Promise ( async function ( resolve , reject ) {
19
- const info = await git . parse ( ) ;
20
- const env = ci ( ) ;
21
- const output = {
22
- service_job_id : env . service_job_id ,
23
- service_pull_request : env . service_pull_request ,
24
- service_name : env . service_name ,
25
- source_files : [ ] ,
26
- git : {
27
- author_date : info . author_date ,
28
- author_email : info . author_email ,
29
- author_name : info . author_name ,
30
- committer_date : info . committer_date ,
31
- commit : env . commit || info . commit ,
32
- branch : env . branch || info . branch ,
33
- message : env . message || info . message ,
34
- committer_name : env . committer_name || info . committer_name ,
35
- committer_email : env . committer_email || info . committer_email ,
36
- remotes : info . remotes
37
- } ,
38
- run_at : new Date ( )
39
- } ;
19
+ try {
20
+ const info = await git . parse ( ) ;
21
+ const env = ci ( ) ;
22
+ const output = {
23
+ service_job_id : env . service_job_id ,
24
+ service_pull_request : env . service_pull_request ,
25
+ service_name : env . service_name ,
26
+ source_files : [ ] ,
27
+ git : {
28
+ author_date : info . author_date ,
29
+ author_email : info . author_email ,
30
+ author_name : info . author_name ,
31
+ committer_date : info . committer_date ,
32
+ commit : env . commit || info . commit ,
33
+ branch : env . branch || info . branch ,
34
+ message : env . message || info . message ,
35
+ committer_name : env . committer_name || info . committer_name ,
36
+ committer_email : env . committer_email || info . committer_email ,
37
+ remotes : info . remotes
38
+ } ,
39
+ run_at : new Date ( )
40
+ } ;
40
41
41
- switch ( parser ) {
42
- case 'cobertura' :
43
- output [ 'source_files' ] = await cobertura . parse ( input ) ;
44
- break ;
45
- case 'golang' :
46
- output [ 'source_files' ] = await golang . parse ( input ) ;
47
- break ;
48
- case 'jacoco' :
49
- output [ 'source_files' ] = await jacoco . parse ( input ) ;
50
- break ;
51
- default :
52
- output [ 'source_files' ] = await lcov . parse ( input ) ;
53
- break ;
54
- }
42
+ switch ( parser ) {
43
+ case 'cobertura' :
44
+ output [ 'source_files' ] = await cobertura . parse ( input ) ;
45
+ break ;
46
+ case 'golang' :
47
+ output [ 'source_files' ] = await golang . parse ( input ) ;
48
+ break ;
49
+ case 'jacoco' :
50
+ output [ 'source_files' ] = await jacoco . parse ( input ) ;
51
+ break ;
52
+ default :
53
+ output [ 'source_files' ] = await lcov . parse ( input ) ;
54
+ break ;
55
+ }
55
56
56
- // Go through and set the file contents
57
- for ( let i = 0 ; i < output [ 'source_files' ] . length ; i ++ ) {
58
- let path = basePath ? Path . resolve ( process . cwd ( ) , basePath , output [ 'source_files' ] [ i ] . file ) : output [ 'source_files' ] [ i ] . file ;
57
+ // Go through and set the file contents
58
+ for ( let i = 0 ; i < output [ 'source_files' ] . length ; i ++ ) {
59
+ let path = basePath ? Path . resolve ( process . cwd ( ) , basePath , output [ 'source_files' ] [ i ] . file ) : output [ 'source_files' ] [ i ] . file ;
59
60
60
- if ( fs . existsSync ( path ) ) {
61
- output [ 'source_files' ] [ i ] . source = fs . readFileSync ( path ) . toString ( 'utf8' ) ;
62
- output [ 'source_files' ] [ i ] . title = output [ 'source_files' ] [ i ] . file . substring ( output [ 'source_files' ] [ i ] . file . lastIndexOf ( '/' ) + 1 , output [ 'source_files' ] [ i ] . file . length ) ;
63
- } else {
64
- return reject ( `can not find file at ${ path } ` ) ;
65
- }
66
- }
61
+ if ( fs . existsSync ( path ) ) {
62
+ output [ 'source_files' ] [ i ] . source = fs . readFileSync ( path ) . toString ( 'utf8' ) ;
63
+ output [ 'source_files' ] [ i ] . title = output [ 'source_files' ] [ i ] . file . substring ( output [ 'source_files' ] [ i ] . file . lastIndexOf ( '/' ) + 1 , output [ 'source_files' ] [ i ] . file . length ) ;
64
+ } else {
65
+ return reject ( `can not find file at ${ path } ` ) ;
66
+ }
67
+ }
67
68
68
- const options = {
69
- hostname : parsedUrl . hostname ,
70
- port : parsedUrl . port || 80 ,
71
- path : '/api/upload' ,
72
- method : 'POST' ,
73
- headers : {
74
- 'Content-Type' : 'application/json' ,
75
- }
76
- } ;
77
- let operation = http ;
78
- let data = '' ;
69
+ const options = {
70
+ hostname : parsedUrl . hostname ,
71
+ port : parsedUrl . port || 80 ,
72
+ path : '/api/upload' ,
73
+ method : 'POST' ,
74
+ headers : {
75
+ 'Content-Type' : 'application/json' ,
76
+ }
77
+ } ;
78
+ let operation = http ;
79
+ let data = '' ;
79
80
80
- if ( parsedUrl . protocol == 'https:' ) {
81
- options . port = 443 ;
82
- operation = https ;
83
- }
81
+ if ( parsedUrl . protocol == 'https:' ) {
82
+ options . port = 443 ;
83
+ operation = https ;
84
+ }
84
85
85
- let req = operation . request ( options , ( res ) => {
86
- res . on ( 'data' , ( chunk ) => {
87
- data += chunk ;
88
- } ) ;
89
- res . on ( 'end' , ( ) => {
90
- try {
91
- const response = JSON . parse ( data ) ;
92
- if ( response . error ) {
93
- return reject ( response . error ) ; // eslint-disable-line
94
- } else {
95
- return resolve ( response ) ;
86
+ let req = operation . request ( options , ( res ) => {
87
+ res . on ( 'data' , ( chunk ) => {
88
+ data += chunk ;
89
+ } ) ;
90
+ res . on ( 'end' , ( ) => {
91
+ try {
92
+ const response = JSON . parse ( data ) ;
93
+ if ( response . error ) {
94
+ return reject ( response . error ) ; // eslint-disable-line
95
+ } else {
96
+ return resolve ( response ) ;
97
+ }
98
+ } catch ( ex ) {
99
+ return reject ( ex ) ;
96
100
}
97
- } catch ( ex ) {
98
- return reject ( ex ) ;
99
- }
101
+ } ) ;
100
102
} ) ;
101
- } ) ;
102
- req . write ( JSON . stringify ( output ) ) ;
103
- req . end ( ) ;
103
+ req . write ( JSON . stringify ( output ) ) ;
104
+ req . end ( ) ;
105
+ } catch ( ex ) {
106
+ return reject ( ex ) ;
107
+ }
104
108
} ) ;
105
109
} ;
0 commit comments