Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Heroku support #34

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Officially supported CI servers:
| [dsari](https://github.com/rfinnie/dsari) | `ci.DSARI` | 🚫 |
| [GitLab CI](https://about.gitlab.com/gitlab-ci/) | `ci.GITLAB` | 🚫 |
| [GoCD](https://www.go.cd/) | `ci.GOCD` | 🚫 |
| [Heroku](https://www.heroku.com) | `ci.HEROKU` | 🚫 |
| [Hudson](http://hudson-ci.org) | `ci.HUDSON` | 🚫 |
| [Jenkins CI](https://jenkins-ci.org) | `ci.JENKINS` | ✅ |
| [Magnum CI](https://magnum-ci.com) | `ci.MAGNUM` | 🚫 |
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Object.defineProperty(exports, '_vendors', {
exports.name = null
exports.isPR = null

function includes (str, search) {
return !!~str.indexOf(search)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this less clever and more explicit.

-   return !!~str.indexOf(search)
+   return str.indexOf(search) > -1;

}

vendors.forEach(function (vendor) {
var envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env]
var isCI = envs.every(function (obj) {
Expand Down Expand Up @@ -60,6 +64,13 @@ exports.isCI = !!(

function checkEnv (obj) {
if (typeof obj === 'string') return !!env[obj]

if ('env' in obj) {
// { env: "NODE", includes: "heroku" }
return obj.env in env && includes(env[obj.env], obj.includes)
}

// { "CI_NAME": "codeship" }
return Object.keys(obj).every(function (k) {
return env[k] === obj[k]
})
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ test('Cirrus CI - Not PR', function (t) {
t.end()
})

test('Heroku - Not PR', function (t) {
process.env.NODE = '/app/.heroku/node/bin/node'

clearModule('./')
var ci = require('./')

t.equal(ci.isCI, true)
t.equal(ci.isPR, null)
t.equal(ci.name, 'Heroku')
t.equal(ci.HEROKU, true)
assertVendorConstants('HEROKU', ci, t)

delete process.env.NODE

t.end()
})

test('Semaphore - PR', function (t) {
process.env.SEMAPHORE = 'true'
process.env.PULL_REQUEST_NUMBER = '42'
Expand Down
5 changes: 5 additions & 0 deletions vendors.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
"constant": "GOCD",
"env": "GO_PIPELINE_LABEL"
},
{
"name": "Heroku",
"constant": "HEROKU",
"env": { "env": "NODE", "includes": "heroku" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test, you check for this value: /app/.heroku/node/bin/node. Is that a constant? Could you check for that value explicitly instead of any value with heroku in it?

},
{
"name": "Hudson",
"constant": "HUDSON",
Expand Down