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

feat: add ci.isPR #16

Merged
merged 1 commit into from
Sep 8, 2018
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ boolean to be set to `true` if they use certain vendor neutral
environment variables. In those cases `ci.name` will be `null` and no
vendor specific boolean will be set to `true`.

### `ci.isPR`

A boolean if PR detection is supported for the current CI server. Will
be `true` if a PR is being tested. Otherwise `false`. If PR detection is
not supported for the current CI server, the value will be `null`.

### `ci.<VENDOR-CONSTANT>`

A vendor specific boolean constants is exposed for each support CI
Expand Down
25 changes: 24 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Object.defineProperty(exports, '_vendors', {
})

exports.name = null
exports.isPR = null

vendors.forEach(function (vendor) {
var envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env]
Expand All @@ -19,8 +20,30 @@ vendors.forEach(function (vendor) {
return env[k] === obj[k]
})
})

exports[vendor.constant] = isCI
if (isCI) exports.name = vendor.name

if (isCI) {
exports.name = vendor.name

if (vendor.pr) {
var val = env[vendor.pr.env]
if (val) {
switch (vendor.pr.type) {
case 'not-false':
exports.isPR = val !== 'false'
break
case 'boolean':
exports.isPR = val === 'true'
break
default:
exports.isPR = true
}
} else {
exports.isPR = false
}
}
}
})

exports.isCI = !!(
Expand Down
Loading