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

Commit

Permalink
initialize: Report in header if we're in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Jul 5, 2016
1 parent 0b595c4 commit f01d0f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,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.
4 changes: 4 additions & 0 deletions lib/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ 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($ENV['CI'] === 'true' || $ENV['TDDIUM'] || $ENV['JENKINS_URL'] || $ENV['bamboo.buildKey'])
}

var opts = {
url: uri,
Expand Down Expand Up @@ -47,6 +50,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()
})

0 comments on commit f01d0f6

Please sign in to comment.