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 #46 from dtinth/cci2
Browse files Browse the repository at this point in the history
Support CircleCI 2.0
  • Loading branch information
Steve Peak authored Feb 21, 2017
2 parents 2408ca9 + e70ca5a commit f0c8aeb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
17 changes: 16 additions & 1 deletion lib/services/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ module.exports = {
commit : process.env.CIRCLE_SHA1,
branch : process.env.CIRCLE_BRANCH,
pr: process.env.CIRCLE_PR_NUMBER,
slug : process.env.CIRCLE_PROJECT_USERNAME + '/' + process.env.CIRCLE_PROJECT_REPONAME,
slug : detectRepoSlug(),
};
function detectRepoSlug(){
if (process.env.CIRCLE_PROJECT_REPONAME) {
// CircleCI 1.0
// CIRCLE_PROJECT_REPONAME=codecov
// CIRCLE_PROJECT_USERNAME=codecov-node
// CIRCLE_REPOSITORY_URL=https://github.com/codecov/codecov-node (note: GitHub Web URL)
return process.env.CIRCLE_PROJECT_USERNAME + '/' + process.env.CIRCLE_PROJECT_REPONAME;
}
if (process.env.CIRCLE_REPOSITORY_URL) {
// CircleCI 2.0
// [email protected]:codecov/codecov-node.git (note: Git/SSH URL)
return process.env.CIRCLE_REPOSITORY_URL.replace(/^.*:/, '').replace(/\.git$/, '');
}
throw new Error('Cannot detect repository slug.');
}
}

};
36 changes: 35 additions & 1 deletion test/services/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Circle CI Provider", function(){
expect(circle.detect()).to.be(true);
});

it ("can get circle env info get_commit_status", function(){
it ("can get circle env info (CircleCI 1.0)", function(){
process.env.CIRCLECI = 'true';
process.env.CIRCLE_BUILD_NUM = '1234';
process.env.CIRCLE_SHA1 = '5678';
Expand All @@ -27,4 +27,38 @@ describe("Circle CI Provider", function(){
});
});

it ("can get circle env info (CircleCI 2.0)", function(){
process.env.CIRCLECI = 'true';
process.env.CIRCLE_BRANCH = 'master';
process.env.CIRCLE_BUILD_NUM = '1234';
process.env.CIRCLE_SHA1 = 'abcd';
process.env.CIRCLE_NODE_INDEX = '1';
process.env.CIRCLE_BUILD_URL = 'https://circleci.com/gh/owner/repo/1234';
process.env.CIRCLE_COMPARE_URL = 'https://github.com/owner/repo/2408ca9...3c36cfa';
process.env.CIRCLE_NODE_INDEX = '1';
process.env.CIRCLE_REPOSITORY_URL = '[email protected]:owner/repo.git';
delete process.env.CIRCLE_PR_NUMBER;
delete process.env.CIRCLE_PROJECT_USERNAME;
delete process.env.CIRCLE_PROJECT_REPONAME;
expect(circle.configuration()).to.eql({
service : 'circleci',
commit : 'abcd',
build : '1234.1',
job : '1234.1',
branch : 'master',
pr : undefined,
slug : 'owner/repo'
});
});

it ("throws if repo slug cannot be detected", function(){
delete process.env.CIRCLE_PR_NUMBER;
delete process.env.CIRCLE_PROJECT_USERNAME;
delete process.env.CIRCLE_PROJECT_REPONAME;
delete process.env.CIRCLE_REPOSITORY_URL;
expect(function(){
circle.configuration();
}).to.throw(Error);
});

});
6 changes: 3 additions & 3 deletions test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Codecov", function(){
},
'testing node-'+codecov.version,
function(body){
expect(body).to.contain('http://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a');
expect(body).to.contain('https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a');
done();
},
function(errCode, errMsg){
Expand All @@ -44,7 +44,7 @@ describe("Codecov", function(){
},
'testing node-'+codecov.version,
function(body){
expect(body).to.contain('http://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a');
expect(body).to.contain('https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a');
done();
},
function(errCode, errMsg){
Expand All @@ -66,7 +66,7 @@ describe("Codecov", function(){
},
'testing node-'+codecov.version,
function(body){
expect(body).to.contain('http://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a');
expect(body).to.contain('https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a');
done();
},
function(errCode, errMsg){
Expand Down

0 comments on commit f0c8aeb

Please sign in to comment.