aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Merwin <[email protected]>2015-12-10 12:52:55 -0800
committerNick Merwin <[email protected]>2015-12-10 12:52:55 -0800
commitd084add18e87fd1a292315de7c9eb171e8fd4b93 (patch)
treec90578e6a9540b8af75a930dc25d3c07be4efee6
parent712e6e4bb4d8e1a60f646d954743a6808aa7f13e (diff)
parentd60635885d243abef2cbc5b2a0da7a27d752a14b (diff)
downloadnode-coveralls-d084add18e87fd1a292315de7c9eb171e8fd4b93.tar.xz
node-coveralls-d084add18e87fd1a292315de7c9eb171e8fd4b93.zip
merge conflictspr/96
-rw-r--r--.travis.yml6
-rw-r--r--README.md23
-rw-r--r--lib/convertLcovToCoveralls.js6
-rw-r--r--lib/detectLocalGit.js2
-rw-r--r--lib/fetchGitData.js2
-rw-r--r--lib/getOptions.js22
-rw-r--r--lib/handleInput.js7
-rw-r--r--lib/sendToCoveralls.js7
-rw-r--r--package.json12
-rw-r--r--test/convertLcovToCoveralls.js2
-rw-r--r--test/getOptions.js19
-rw-r--r--test/sendToCoveralls.js31
12 files changed, 113 insertions, 26 deletions
diff --git a/.travis.yml b/.travis.yml
index b6f134c..284a527 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,8 @@
language: node_js
node_js:
- - '0.10'
- - '0.11'
+ - stable
+ - 4.2
+ - 0.10
+ - 0.11
script: make test-coveralls
diff --git a/README.md b/README.md
index eb28744..842c532 100644
--- a/README.md
+++ b/README.md
@@ -4,17 +4,17 @@
[Coveralls.io](https://coveralls.io/) support for node.js. Get the great coverage reporting of coveralls.io and add a cool coverage button ( like the one above ) to your README.
-Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circle-ci](https://circleci.com/), [jenkins](http://jenkins-ci.org/)
+Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circleci](https://circleci.com/), [jenkins](http://jenkins-ci.org/)
##Installation:
Add the latest version of `coveralls` to your package.json:
```
-npm install coveralls --save
+npm install coveralls --save-dev
```
If you're using mocha, add `mocha-lcov-reporter` to your package.json:
```
-npm install mocha-lcov-reporter --save
+npm install mocha-lcov-reporter --save-dev
```
##Usage:
@@ -123,20 +123,29 @@ Simply run your tap tests with the `COVERALLS_REPO_TOKEN` environment
variable set and tap will automatically use `nyc` to report
coverage to coveralls.
+### Command Line Parameters
+Usage: coveralls.js [-v] filepath
+
+#### Optional arguments:
+
+-v, --verbose
+
+filepath - optionally defines the base filepath of your source files.
+
## Running locally
If you're running locally, you must have a `.coveralls.yml` file, as documented in [their documentation](https://coveralls.io/docs/ruby), with your `repo_token` in it; or, you must provide a `COVERALLS_REPO_TOKEN` environment-variable on the command-line.
If you want to send commit data to coveralls, you can set the `COVERALLS_GIT_COMMIT` environment-variable to the commit hash you wish to reference. If you don't want to use a hash, you can set it to `HEAD` to supply coveralls with the latest commit data. This requires git to be installed and executable on the current PATH.
-[travis-image]: https://travis-ci.org/cainus/node-coveralls.svg?branch=master
-[travis-url]: https://travis-ci.org/cainus/node-coveralls
+[travis-image]: https://travis-ci.org/nickmerwin/node-coveralls.svg?branch=master
+[travis-url]: https://travis-ci.org/nickmerwin/node-coveralls
[codeship-image]: https://www.codeship.io/projects/de6fb440-dea9-0130-e7d9-122ca7ee39d3/status
[codeship-url]: https://www.codeship.io/projects/5622
-[coveralls-image]: https://img.shields.io/coveralls/cainus/node-coveralls/master.svg
-[coveralls-url]: https://coveralls.io/r/cainus/node-coveralls?branch=master
+[coveralls-image]: https://coveralls.io/repos/nickmerwin/node-coveralls/badge.svg?branch=master&service=github
+[coveralls-url]: https://coveralls.io/github/nickmerwin/node-coveralls?branch=master
## Contributing
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js
index 3f604e1..896462e 100644
--- a/lib/convertLcovToCoveralls.js
+++ b/lib/convertLcovToCoveralls.js
@@ -48,9 +48,15 @@ var convertLcovToCoveralls = function(input, options, cb){
if (options.service_job_id){
postJson.service_job_id = options.service_job_id;
}
+ if (options.service_pull_request){
+ postJson.service_pull_request = options.service_pull_request;
+ }
if (options.repo_token) {
postJson.repo_token = options.repo_token;
}
+ if (options.service_pull_request) {
+ postJson.service_pull_request = options.service_pull_request;
+ }
parsed.forEach(function(file){
postJson.source_files.push(convertLcovFileObject(file, filepath));
});
diff --git a/lib/detectLocalGit.js b/lib/detectLocalGit.js
index 302cd44..773eb70 100644
--- a/lib/detectLocalGit.js
+++ b/lib/detectLocalGit.js
@@ -3,7 +3,7 @@ var path = require('path');
var REGEX_BRANCH = /^ref: refs\/heads\/(\w+)$/;
-module.exports = function detectLocalGit(knownCommit, knownBranch) {
+module.exports = function detectLocalGit() {
var dir = process.cwd(), gitDir;
while (path.resolve('/') !== dir) {
gitDir = path.join(dir, '.git');
diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js
index 67b6190..0c516d3 100644
--- a/lib/fetchGitData.js
+++ b/lib/fetchGitData.js
@@ -59,7 +59,7 @@ function fetchBranch(git, cb) {
});
}
-var REGEX_COMMIT_DETAILS = /\nauthor (.+?) <(.+?)>.+\ncommitter (.+?) <(.+?)>.+\n?[\S\s]+?\n\n(.*)/m;
+var REGEX_COMMIT_DETAILS = /\nauthor (.+?) <(.+?)>.+\ncommitter (.+?) <(.+?)>.+[\S\s]*?\n\n(.*)/m;
function fetchHeadDetails(git, cb) {
exec('git cat-file -p ' + git.head.id, function(err, response) {
diff --git a/lib/getOptions.js b/lib/getOptions.js
index eab67f4..350af68 100644
--- a/lib/getOptions.js
+++ b/lib/getOptions.js
@@ -9,10 +9,16 @@ var getBaseOptions = function(cb){
var git_commit = process.env.COVERALLS_GIT_COMMIT;
var git_branch = process.env.COVERALLS_GIT_BRANCH;
+ var match = (process.env.CI_PULL_REQUEST || "").match(/(\d+)$/);
+
+ if (match) {
+ options.service_pull_request = match[1];
+ }
+
if (process.env.TRAVIS){
options.service_name = 'travis-ci';
options.service_job_id = process.env.TRAVIS_JOB_ID;
- git_commit = process.env.TRAVIS_COMMIT;
+ git_commit = 'HEAD';
git_branch = process.env.TRAVIS_BRANCH;
}
@@ -28,6 +34,7 @@ var getBaseOptions = function(cb){
if (process.env.JENKINS_URL){
options.service_name = 'jenkins';
options.service_job_id = process.env.BUILD_ID;
+ options.service_pull_request = process.env.ghprbPullId;
git_commit = process.env.GIT_COMMIT;
git_branch = process.env.GIT_BRANCH;
}
@@ -62,7 +69,7 @@ var getBaseOptions = function(cb){
}
if (!git_commit || !git_branch) {
- var data = require('./detectLocalGit')(git_commit, git_branch);
+ var data = require('./detectLocalGit')();
if (data) {
git_commit = git_commit || data.git_commit;
git_branch = git_branch || data.git_branch;
@@ -108,11 +115,13 @@ var getBaseOptions = function(cb){
}
};
-var getOptions = function(cb){
+var getOptions = function(cb, _userOptions){
if (!cb){
throw new Error('getOptions requires a callback');
}
+ var userOptions = _userOptions || {};
+
getBaseOptions(function(err, options){
// try to get filepath from the command-line
if (process.argv[2]) {
@@ -124,7 +133,12 @@ var getOptions = function(cb){
options.filepath = process.argv[2];
}
}
- cb(err, options);
+
+ // lodash or else would be better, but no need for the extra dependency
+ for (var option in userOptions) {
+ options[option] = userOptions[option];
+ }
+ cb(err, options);
});
};
diff --git a/lib/handleInput.js b/lib/handleInput.js
index 5f88394..845bfad 100644
--- a/lib/handleInput.js
+++ b/lib/handleInput.js
@@ -1,9 +1,10 @@
var index = require('../index');
var logger = require('./logger')();
-function handleInput(input, cb) {
+function handleInput(input, cb, userOptions) {
logger.debug(input);
- var options = index.getOptions(function(err, options){
+ logger.debug('user options ' + userOptions);
+ index.getOptions(function(err, options){
if (err){
logger.error("error from getOptions");
@@ -33,7 +34,7 @@ function handleInput(input, cb) {
cb(null);
});
});
- });
+ }, userOptions);
}
module.exports = handleInput;
diff --git a/lib/sendToCoveralls.js b/lib/sendToCoveralls.js
index 10e614d..38b37f7 100644
--- a/lib/sendToCoveralls.js
+++ b/lib/sendToCoveralls.js
@@ -1,8 +1,13 @@
var request = require('request');
var sendToCoveralls = function(obj, cb){
+ var urlBase = 'https://coveralls.io';
+ if (process.env.COVERALLS_ENDPOINT) {
+ urlBase = process.env.COVERALLS_ENDPOINT;
+ }
+
var str = JSON.stringify(obj);
- var url = 'https://coveralls.io/api/v1/jobs';
+ var url = urlBase + '/api/v1/jobs';
request.post({url : url, form : { json : str}}, function(err, response, body){
cb(err, response, body);
});
diff --git a/package.json b/package.json
index ce0ea06..b06a3f7 100644
--- a/package.json
+++ b/package.json
@@ -5,9 +5,9 @@
"coverage",
"coveralls"
],
- "version": "2.11.2",
+ "version": "2.11.4",
"bugs": {
- "url": "https://github.com/cainus/node-coveralls/issues"
+ "url": "https://github.com/nickmerwin/node-coveralls/issues"
},
"scripts": {
"test": "make test"
@@ -16,9 +16,11 @@
"coveralls": "./bin/coveralls.js"
},
"maintainers": [
- "Gregg Caines <[email protected]> (http://caines.ca)"
+ "Nick Merwin <[email protected]> (https://coveralls.io)"
],
"contributors": [
+ "Gregg Caines <[email protected]> (http://caines.ca)",
+ "Joshua Ma <[email protected]> (http://joshma.com)",
"Alan Gutierrez <[email protected]> (http://www.prettyrobots.com/)",
"Kir Belevich (https://github.com/svg)",
"elliotcable <[email protected]> (http://elliottcable.name/)",
@@ -30,7 +32,7 @@
"js-yaml": "3.0.1",
"lcov-parse": "0.0.6",
"log-driver": "1.2.4",
- "request": "2.40.0"
+ "request": "2.67.0"
},
"devDependencies": {
"sinon-restore": "1.0.0",
@@ -49,7 +51,7 @@
},
"repository": {
"type": "git",
- "url": "git://github.com/cainus/node-coveralls.git"
+ "url": "git://github.com/nickmerwin/node-coveralls.git"
},
"author": "Gregg Caines",
"license": "BSD"
diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js
index 6a64eda..24fa6c8 100644
--- a/test/convertLcovToCoveralls.js
+++ b/test/convertLcovToCoveralls.js
@@ -29,6 +29,7 @@ describe("convertLcovToCoveralls", function(){
process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
+ process.env.CI_PULL_REQUEST = "https://github.com/fake/fake/pulls/123";
getOptions(function(err, options){
var lcovpath = __dirname + "/../fixtures/onefile.lcov";
@@ -37,6 +38,7 @@ describe("convertLcovToCoveralls", function(){
options.filepath = libpath;
convertLcovToCoveralls(input, options, function(err, output){
should.not.exist(err);
+ output.service_pull_request.should.equal("123");
//output.git.should.equal("GIT_HASH");
done();
});
diff --git a/test/getOptions.js b/test/getOptions.js
index 8a77708..ac26caf 100644
--- a/test/getOptions.js
+++ b/test/getOptions.js
@@ -115,6 +115,9 @@ describe("getOptions", function(){
it ("should set service_name if it exists", function(done){
testServiceName(getOptions, done);
});
+ it("should set service_pull_request if it exists", function(done){
+ testServicePullRequest(getOptions, done);
+ });
it ("should set service_name and service_job_id if it's running on travis-ci", function(done){
testTravisCi(getOptions, done);
});
@@ -135,6 +138,14 @@ describe("getOptions", function(){
it ("should set service_name and service_job_id if it's running on wercker", function(done){
testWercker(getOptions, done);
});
+ it ("should override set options with user options", function(done){
+ var userOptions = {service_name: 'OVERRIDDEN_SERVICE_NAME'};
+ process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
+ getOptions(function(err, options){
+ options.service_name.should.equal("OVERRIDDEN_SERVICE_NAME");
+ done();
+ }, userOptions);
+ });
});
var testServiceJobId = function(sut, done){
@@ -246,6 +257,14 @@ var testServiceName = function(sut, done){
});
};
+var testServicePullRequest = function(sut, done){
+ process.env.CI_PULL_REQUEST = "https://github.com/fake/fake/pulls/123";
+ sut(function(err, options){
+ options.service_pull_request.should.equal("123");
+ done();
+ });
+};
+
var testTravisCi = function(sut, done){
process.env.TRAVIS = "TRUE";
process.env.TRAVIS_JOB_ID = "1234";
diff --git a/test/sendToCoveralls.js b/test/sendToCoveralls.js
index 937df95..f809319 100644
--- a/test/sendToCoveralls.js
+++ b/test/sendToCoveralls.js
@@ -5,9 +5,20 @@ var index = require('../index');
logger = require('log-driver')({level : false});
describe("sendToCoveralls", function(){
+ var realCoverallsHost;
+ beforeEach(function() {
+ realCoverallsHost = process.env.COVERALLS_ENDPOINT;
+ });
+
afterEach(function() {
sinon.restoreAll();
+ if (realCoverallsHost !== undefined) {
+ process.env.COVERALLS_ENDPOINT = realCoverallsHost;
+ } else {
+ delete process.env.COVERALLS_ENDPOINT;
+ }
});
+
it ("passes on the correct params to request.post", function(done){
sinon.stub(request, 'post', function(obj, cb){
obj.url.should.equal('https://coveralls.io/api/v1/jobs');
@@ -16,12 +27,28 @@ describe("sendToCoveralls", function(){
});
var obj = {"some":"obj"};
- index.sendToCoveralls(obj, function(err, response, body){
+ index.sendToCoveralls(obj, function(err, response, body){
+ err.should.equal('err');
+ response.should.equal('response');
+ body.should.equal('body');
+ done();
+ });
+ });
+
+ it ("allows sending to enterprise url", function(done){
+ process.env.COVERALLS_ENDPOINT = 'https://coveralls-ubuntu.domain.com';
+ sinon.stub(request, 'post', function(obj, cb){
+ obj.url.should.equal('https://coveralls-ubuntu.domain.com/api/v1/jobs');
+ obj.form.should.eql({json : '{"some":"obj"}'});
+ cb('err', 'response', 'body');
+ });
+
+ var obj = {"some":"obj"};
+ index.sendToCoveralls(obj, function(err, response, body){
err.should.equal('err');
response.should.equal('response');
body.should.equal('body');
done();
-
});
});
});