Skip to content

Commit

Permalink
feat: add ci.isPR (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
watson authored Sep 8, 2018
1 parent 516298c commit 3418f8b
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 15 deletions.
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

0 comments on commit 3418f8b

Please sign in to comment.