forked from markdalgleish/gulp-coveralls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (45 loc) · 1.39 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var through = require('through2'),
PluginError = require('plugin-error'),
coveralls = require('coveralls');
module.exports = function() {
return through.obj(function(file, enc, callback) {
var stream = this;
function handleError(done, err) {
if (err){
stream.emit('error', new PluginError('gulp-coveralls', err));
done();
}
}
function sendToCoverallsCallback(done, err, response, body) {
handleError(done, err);
if (response.statusCode >= 400){
handleError(done, 'Bad response:' + response.statusCode + ' ' + body);
} else {
done();
}
}
function sendToCoveralls(input, done) {
coveralls.getBaseOptions(function(err, options){
options.filepath = '.';
coveralls.convertLcovToCoveralls(input, options, function(err, postData){
handleError(done, err);
coveralls.sendToCoveralls(postData, function(err, response, body){
sendToCoverallsCallback(done, err, response, body);
});
});
});
}
if (file.isNull()) {
this.push(file);
return callback();
}
if (file.isStream()) {
this.emit('error', new PluginError('gulp-coveralls', 'Stream content is not supported'));
return callback();
}
if (file.isBuffer()) {
sendToCoveralls(file.contents.toString(), callback);
this.push(file);
}
});
};