Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Report in http header if we're in CI #129

Merged
merged 1 commit into from
Oct 7, 2016
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,8 @@ any):
origin (unique combination of protocol:host:port). Passed to the
[httpAgent](https://nodejs.org/api/http.html#http_agent_maxsockets).
Default = 50
* `isFromCI` {Boolean} Identify to severs if this request is coming from CI (for statistics purposes).
Default = detected from environment– primarily this is done by looking for
the CI environment variable to be set to `true`. Also accepted are the
existence of the `JENKINS_URL`, `bamboo.buildKey` and `TDDIUM` environment
variables.
6 changes: 6 additions & 0 deletions lib/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function initialize (uri, method, accept, headers) {
this.config.sessionToken = crypto.randomBytes(8).toString('hex')
this.log.verbose('request id', this.config.sessionToken)
}
if (this.config.isFromCI == null) {
this.config.isFromCI = Boolean(
process.env['CI'] === 'true' || process.env['TDDIUM'] ||
process.env['JENKINS_URL'] || process.env['bamboo.buildKey'])
}

var opts = {
url: uri,
Expand Down Expand Up @@ -47,6 +52,7 @@ function initialize (uri, method, accept, headers) {
if (this.refer) headers.referer = this.refer

headers['npm-session'] = this.config.sessionToken
headers['npm-in-ci'] = String(this.config.isFromCI)
headers['user-agent'] = this.config.userAgent

return opts
Expand Down
4 changes: 3 additions & 1 deletion test/config-override.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var config = {
log: { fake: function () {} },
defaultTag: 'next',
couchToken: { object: true },
sessionToken: 'hamchunx'
sessionToken: 'hamchunx',
isFromCI: true
}

test('config defaults', function (t) {
Expand Down Expand Up @@ -52,6 +53,7 @@ test('config defaults', function (t) {
t.equal(client.config.defaultTag, 'next')
t.ok(client.config.couchToken.object)
t.equal(client.config.sessionToken, 'hamchunx')
t.ok(client.config.isFromCI)

t.end()
})