This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from dtinth/cci2
Support CircleCI 2.0
- Loading branch information
Showing
3 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.'); | ||
} | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters