@@ -23,7 +23,7 @@ var fs = require('fs'),
23
23
crypto = require ( 'crypto' ) ,
24
24
assert = require ( 'assert' ) . strict ,
25
25
parser = new xml2js . Parser ( ) ,
26
- timestamp , md5 ;
26
+ timestamp , md5 , cb ;
27
27
var timestamp ;
28
28
var token = process . env . COVERALLS_TOKEN ;
29
29
@@ -33,7 +33,9 @@ var token = process.env.COVERALLS_TOKEN;
33
33
* @param {Array } classList - An array of class objects from the loaded XML file.
34
34
* @param {String } path - The root path of the code repository.
35
35
* @param {String } sha - The commit SHA for this coverage test.
36
- * @returns {Object } Object containing array of source code files and their code coverage
36
+ * @param {function } callback - The callback function to run when complete. Takes object containing array of source
37
+ * code files and their code coverage
38
+ * @returns {Object }
37
39
* @todo Generalize path default
38
40
*/
39
41
const formatCoverage = function ( classList , path , sha ) {
@@ -63,20 +65,22 @@ const formatCoverage = function(classList, path, sha) {
63
65
job . source_files = sourceFiles ;
64
66
job . commit_sha = sha ;
65
67
job . run_at = timestamp ; // "2013-02-18 00:52:48 -0800"
66
- return job ;
68
+ cb ( job ) ;
67
69
}
68
70
69
71
/**
70
72
* Loads a code coverage XML file in Cobertura Format and returns payload object for Coveralls API
71
73
* @see {@link https://docs.coveralls.io/api-reference|Coveralls API docs }
72
74
* @param {String } path - Path to the XML file containing coverage information.
73
75
* @param {String } sha - The commit SHA for this coverage test
74
- * @returns {Object } Object containing array of source code files and their code coverage
76
+ * @param {String } repo - The repo to which the commit belongs
77
+ * @param {function } callback - The callback function to run when complete
75
78
* @todo Remove assert
76
79
* @todo Generalize ignoring of submodules
77
80
* @see {@link https://github.com/cobertura/cobertura/wiki|Cobertura Wiki }
78
81
*/
79
- const coverage = function ( path , sha ) {
82
+ const coverage = function ( path , repo , sha , callback ) {
83
+ cb = callback ; // @fixme Making callback global feels hacky
80
84
fs . readFile ( path , function ( err , data ) { // Read in XML file
81
85
parser . parseString ( data , function ( err , result ) { // Parse XML
82
86
const rigboxPath = result . coverage . sources [ 0 ] . source [ 0 ] ; // Extract root code path
@@ -87,25 +91,20 @@ const coverage = function(path, sha) {
87
91
const packages = result . coverage . packages [ 0 ] . package ;
88
92
packages . forEach ( package => { classes . push ( package . classes [ 0 ] . class ) } ) ; // Get all classes
89
93
classes = classes . reduce ( ( acc , val ) => acc . concat ( val ) , [ ] ) ; // Flatten
90
- //console.log(classes.length);
91
94
92
95
// The submodules
93
- var alyx_matlab = [ ] ;
94
- var signals = [ ] ;
95
- var npy_matlab = [ ] ;
96
- var wheelAnalysis = [ ] ;
96
+ var modules = { 'rigbox' : [ ] , 'alyx-matlab' : [ ] , 'signals' : [ ] , 'npy-matlab' : [ ] , 'wheelAnalysis' : [ ] } ;
97
97
// Sort into piles
98
- classes = classes . filter ( function ( e ) {
98
+ modules [ 'rigbox' ] = classes . filter ( function ( e ) {
99
99
if ( e . $ . filename . search ( / ( t e s t s \\ | _ .* t e s t | d o c s \\ ) / i) != - 1 ) { return false ; } // Filter out tests and docs
100
100
if ( ! Array . isArray ( e . lines [ 0 ] . line ) ) { return false ; } // Filter out files with no functional lines
101
- if ( e . $ . filename . startsWith ( 'alyx-matlab\\' ) ) { alyx_matlab . push ( e ) ; return false ; }
102
- if ( e . $ . filename . startsWith ( 'signals\\' ) ) { signals . push ( e ) ; return false ; }
103
- if ( e . $ . filename . startsWith ( 'npy-matlab\\' ) ) { npy_matlab . push ( e ) ; return false ; }
104
- if ( e . $ . filename . startsWith ( 'wheelAnalysis\\' ) ) { wheelAnalysis . push ( e ) ; return false ; }
101
+ if ( e . $ . filename . startsWith ( 'alyx-matlab\\' ) ) { modules [ 'alyx-matlab' ] . push ( e ) ; return false ; }
102
+ if ( e . $ . filename . startsWith ( 'signals\\' ) ) { modules . signals . push ( e ) ; return false ; }
103
+ if ( e . $ . filename . startsWith ( 'npy-matlab\\' ) ) { modules [ 'npy-matlab' ] . push ( e ) ; return false ; }
104
+ if ( e . $ . filename . startsWith ( 'wheelAnalysis\\' ) ) { modules . wheelAnalysis . push ( e ) ; return false ; }
105
105
else { return true } ;
106
106
} ) ;
107
- //console.log(obj.source_files[0].coverage.length);
108
- return obj = formatCoverage ( classes , rigboxPath ) ;
107
+ formatCoverage ( modules [ repo . toLowerCase ( ) ] , rigboxPath , callback ) ;
109
108
} ) ;
110
109
} ) ;
111
110
} ;
@@ -115,7 +114,7 @@ const coverage = function(path, sha) {
115
114
* @param {String } path - Path to the source code file.
116
115
* @returns {Object } key `Hash` contains MD5 digest string of file; `count` contains number of lines in source file
117
116
*/
118
- const md5 = function ( path ) {
117
+ md5 = function ( path ) {
119
118
var hash = crypto . createHash ( 'md5' ) ; // Creating hash object
120
119
var buf = fs . readFileSync ( path , 'utf-8' ) ; // Read in file
121
120
var count = buf . split ( / \r \n | \r | \n / ) . length ; // Count the number of lines
0 commit comments