diff --git a/README.md b/README.md index 9d81f4d..139e0b1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/initialize.js b/lib/initialize.js index 3c12697..174eb82 100644 --- a/lib/initialize.js +++ b/lib/initialize.js @@ -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, @@ -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 diff --git a/test/config-override.js b/test/config-override.js index 026cb19..e333aca 100644 --- a/test/config-override.js +++ b/test/config-override.js @@ -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) { @@ -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() })