Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from codecov/master
Browse files Browse the repository at this point in the history
Pull from codecov master
  • Loading branch information
eddiemoore authored Jul 25, 2016
2 parents ae1931b + 9d1b186 commit e170be6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 13 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ language: node_js
sudo: false

node_js:
- "4.1"
- "4.0"
- "6"
- "5"
- "4"
- "0.12"
- "0.11"
- "0.10"
- "iojs"

after_success:
- ./bin/codecov -e TRAVIS_NODE_VERSION
- ./bin/codecov -e TRAVIS_NODE_VERSION
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ istanbul cover test.js
[travis-image]: https://travis-ci.org/codecov/codecov-node.svg?branch=master
[travis-url]: https://travis-ci.org/codecov/codecov-node

[npm-url]: https://npmjs.org/package/codecov.io
[npm-image]: https://img.shields.io/npm/v/codecov.io.svg
[npm-url]: https://npmjs.org/package/codecov
[npm-image]: https://img.shields.io/npm/v/codecov.svg

[depstat-url]: https://david-dm.org/codecov/codecov-node
[depstat-image]: https://img.shields.io/david/codecov/codecov-node/master.svg

[devdepstat-url]: https://david-dm.org/codecov/codecov-node#info=devDependencies
[devdepstat-image]: https://img.shields.io/david/dev/codecov/codecov-node/master.svg

**With NYC**

```
nyc npm test
nyc report --reporter=text-lcov > coverage.lcov
./node_modules/.bin/codecov
```
19 changes: 12 additions & 7 deletions lib/codecov.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var path = require('path');
var request = require('request');
var urlgrey = require('urlgrey');
var execSync = require('child_process').execSync;
Expand Down Expand Up @@ -74,17 +75,17 @@ var patterns = "-type f \\( -name '*coverage.*' " +



var sendToCodecovV2 = function(codecov_endpoint, query, body, on_success, on_failure){
var sendToCodecovV2 = function(codecov_endpoint, query, upload_body, on_success, on_failure){
// Direct to Codecov
request.post(
{
url : urlgrey(codecov_endpoint + '/upload/v2').query(query).toString(),
body : body,
body : upload_body,
headers : {
'Content-Type': 'text/plain',
'Accept': 'text/plain'
}
}, function(err, response, body){
}, function(err, response, result){
if (err || response.statusCode !== 200) {
console.log(' ' + (err || response.body));
return on_failure(response.statusCode, response.body);
Expand All @@ -101,7 +102,7 @@ var sendToCodecovV2 = function(codecov_endpoint, query, body, on_success, on_fai
};


var sendToCodecovV3 = function(codecov_endpoint, query, body, on_success, on_failure){
var sendToCodecovV3 = function(codecov_endpoint, query, upload_body, on_success, on_failure){
// Direct to S3
request.post(
{
Expand All @@ -113,21 +114,21 @@ var sendToCodecovV3 = function(codecov_endpoint, query, body, on_success, on_fai
}
}, function(err, response, result){
if (err) {
sendToCodecovV2(codecov_endpoint, query, body, on_success, on_failure);
sendToCodecovV2(codecov_endpoint, query, upload_body, on_success, on_failure);

} else {
var codecov_report_url = result.split('\n')[0];
request.put(
{
url : result.split('\n')[1],
body : body,
body : upload_body,
headers : {
'Content-Type': 'plain/text',
'x-amz-acl': 'public-read'
}
}, function(err, response, result){
if (err) {
sendToCodecovV2(codecov_endpoint, query, body, on_success, on_failure);
sendToCodecovV2(codecov_endpoint, query, upload_body, on_success, on_failure);

} else {
console.log(' Success!');
Expand Down Expand Up @@ -158,6 +159,10 @@ var upload = function(args, on_success, on_failure){
' \\_____\\___/ \\__,_|\\___|\\___\\___/ \\_/ \n' +
' ' + version);

query.yaml = ['codecov.yml', '.codecov.yml'].reduce(function (result, file) {
return result || (fs.existsSync(path.resolve(process.cwd(), file)) ? file : undefined)
}, undefined)

if ((args.options.disable || '').split(',').indexOf('detect') === -1) {
console.log('==> Detecting CI Provider');
query = detectProvider();
Expand Down
26 changes: 26 additions & 0 deletions test/detect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

var detect = require("../lib/detect");
var execSync = require('child_process').execSync;
if (!execSync) {
var exec = require('execSync').exec;
var execSync = function(cmd){
return exec(cmd).stdout;
};
}

describe("Codecov", function(){

it("can detect existing appveyor service", function(){
process.env.TRAVIS = "true";

expect(detect().service).to.eql("travis");

process.env.TRAVIS = "";
});

it("can select local git service if no service is found", function(){
expect(detect().commit).to.match(/^\w{40}$/);
expect(detect().commit).to.eql(execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim());
});

});
27 changes: 27 additions & 0 deletions test/services/buildkite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var buildkite = require("../../lib/services/buildkite");

describe("Buildkite CI Provider", function(){

it ("can detect buildkite", function(){
process.env.BUILDKITE = "true";
expect(buildkite.detect()).to.be(true);
});

it ("can get buildkite env info", function(){
process.env.BUILDKITE_BUILD_NUMBER = "1";
process.env.BUILDKITE_BUILD_URL = "url";
process.env.BUILDKITE_COMMIT = "commit";
process.env.BUILDKITE_BRANCH = "branch";
process.env.BUILDKITE_PROJECT_SLUG = "slug";

expect(buildkite.configuration()).to.eql({
service : 'buildkite',
build : "1",
build_url : "url",
commit : "commit",
branch : "branch",
slug : "slug"
});
});

});
3 changes: 2 additions & 1 deletion test/services/snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ describe("Snap CI Provider", function(){
});

it ("can get snap env info get_commit_status for pull requests", function(){
process.env.SNAP_COMMIT = '';
process.env.SNAP_BRANCH = '';
process.env.SNAP_CI = "true";
process.env.SNAP_PIPELINE_COUNTER = '1234';
process.env.SNAP_COMMIT = '5678';
process.env.SNAP_UPSTREAM_COMMIT = '5678';
process.env.SNAP_UPSTREAM_BRANCH = 'upstream-branch';
process.env.SNAP_PULL_REQUEST_NUMBER = 'blah';
expect(snap.configuration()).to.eql({
Expand Down

0 comments on commit e170be6

Please sign in to comment.