@@ -23,7 +23,7 @@ var fs = require('fs'),
2323 crypto = require ( 'crypto' ) ,
2424 assert = require ( 'assert' ) . strict ,
2525 parser = new xml2js . Parser ( ) ,
26- timestamp , md5 ;
26+ timestamp , md5 , cb ;
2727var timestamp ;
2828var token = process . env . COVERALLS_TOKEN ;
2929
@@ -33,7 +33,9 @@ var token = process.env.COVERALLS_TOKEN;
3333 * @param {Array } classList - An array of class objects from the loaded XML file.
3434 * @param {String } path - The root path of the code repository.
3535 * @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 }
3739 * @todo Generalize path default
3840 */
3941const formatCoverage = function ( classList , path , sha ) {
@@ -63,20 +65,22 @@ const formatCoverage = function(classList, path, sha) {
6365 job . source_files = sourceFiles ;
6466 job . commit_sha = sha ;
6567 job . run_at = timestamp ; // "2013-02-18 00:52:48 -0800"
66- return job ;
68+ cb ( job ) ;
6769}
6870
6971/**
7072 * Loads a code coverage XML file in Cobertura Format and returns payload object for Coveralls API
7173 * @see {@link https://docs.coveralls.io/api-reference|Coveralls API docs }
7274 * @param {String } path - Path to the XML file containing coverage information.
7375 * @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
7578 * @todo Remove assert
7679 * @todo Generalize ignoring of submodules
7780 * @see {@link https://github.com/cobertura/cobertura/wiki|Cobertura Wiki }
7881 */
79- const coverage = function ( path , sha ) {
82+ const coverage = function ( path , repo , sha , callback ) {
83+ cb = callback ; // @fixme Making callback global feels hacky
8084 fs . readFile ( path , function ( err , data ) { // Read in XML file
8185 parser . parseString ( data , function ( err , result ) { // Parse XML
8286 const rigboxPath = result . coverage . sources [ 0 ] . source [ 0 ] ; // Extract root code path
@@ -87,25 +91,20 @@ const coverage = function(path, sha) {
8791 const packages = result . coverage . packages [ 0 ] . package ;
8892 packages . forEach ( package => { classes . push ( package . classes [ 0 ] . class ) } ) ; // Get all classes
8993 classes = classes . reduce ( ( acc , val ) => acc . concat ( val ) , [ ] ) ; // Flatten
90- //console.log(classes.length);
9194
9295 // 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' : [ ] } ;
9797 // Sort into piles
98- classes = classes . filter ( function ( e ) {
98+ modules [ 'rigbox' ] = classes . filter ( function ( e ) {
9999 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
100100 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 ; }
105105 else { return true } ;
106106 } ) ;
107- //console.log(obj.source_files[0].coverage.length);
108- return obj = formatCoverage ( classes , rigboxPath ) ;
107+ formatCoverage ( modules [ repo . toLowerCase ( ) ] , rigboxPath , callback ) ;
109108 } ) ;
110109 } ) ;
111110} ;
@@ -115,7 +114,7 @@ const coverage = function(path, sha) {
115114 * @param {String } path - Path to the source code file.
116115 * @returns {Object } key `Hash` contains MD5 digest string of file; `count` contains number of lines in source file
117116 */
118- const md5 = function ( path ) {
117+ md5 = function ( path ) {
119118 var hash = crypto . createHash ( 'md5' ) ; // Creating hash object
120119 var buf = fs . readFileSync ( path , 'utf-8' ) ; // Read in file
121120 var count = buf . split ( / \r \n | \r | \n / ) . length ; // Count the number of lines
0 commit comments