Skip to content

Commit 2f04bc2

Browse files
committed
Update endpoint and payload
1 parent b2d3a22 commit 2f04bc2

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

bin/helpers/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ config.rails_host = hosts[config.env].rails_host;
1111
config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
1212
config.buildUrl = `${config.cypress_v1}/builds/`;
1313
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
14-
config.usageReportingUrl = `http://127.0.0.1:3000/send_event_cy/`;
15-
config.usageReportingApiKey = 'abcd';
14+
config.usageReportingUrl = `http://127.0.0.1:8000/send_event_cy_internal`;
1615
config.fileName = "tests.zip";
1716

1817
module.exports = config;

bin/helpers/usageReporting.js

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ function cli_version_and_path(bsConfig) {
8181
// 2. check version of Cypress installed globally if not present in project
8282

8383
if (bsConfig) {
84-
let _path = path.join(bsConfig.run_settings.cypress_proj_dir, 'node_modules', 'browserstack-cypress-cli');
84+
let _path = path.join(bsConfig.run_settings.cypress_proj_dir, 'node_modules', 'browserstack-cypress');
8585
let version = get_version(_path);
8686
if (!version) {
87-
version = get_version('browserstack-cypress-cli');
87+
version = get_version('browserstack-cypress');
8888

8989
if (!version) {
9090
// return path = null if version is null
@@ -95,7 +95,7 @@ function cli_version_and_path(bsConfig) {
9595
}
9696
return [version, _path];
9797
} else {
98-
let version = get_version('browserstack-cypress-cli');
98+
let version = get_version('browserstack-cypress');
9999

100100
if (!version) {
101101
// return path = null if version is null
@@ -105,38 +105,90 @@ function cli_version_and_path(bsConfig) {
105105
}
106106
}
107107

108+
function ci_environment() {
109+
var env = process.env;
110+
// Jenkins
111+
if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
112+
return "Jenkins";
113+
}
114+
// CircleCI
115+
if (env.CI === "true" && env.CIRCLECI === "true") {
116+
return "CircleCI";
117+
}
118+
// Travis CI
119+
if (env.CI === "true" && env.TRAVIS === "true") {
120+
return "Travis CI";
121+
}
122+
// Codeship
123+
if (env.CI === "true" && env.CI_NAME === "codeship") {
124+
return "Codeship";
125+
}
126+
// Bitbucket
127+
if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
128+
return "Bitbucket";
129+
}
130+
// Drone
131+
if (env.CI === "true" && env.DRONE === "true") {
132+
return "Drone";
133+
}
134+
// Semaphore
135+
if (env.CI === "true" && env.SEMAPHORE === "true") {
136+
return "Semaphore";
137+
}
138+
// GitLab
139+
if (env.CI === "true" && env.GITLAB_CI === "true") {
140+
return "GitLab";
141+
}
142+
// Buildkite
143+
if (env.CI === "true" && env.BUILDKITE === "true") {
144+
return "Buildkite";
145+
}
146+
// Visual Studio Team Services
147+
if (env.TF_BUILD === "True") {
148+
return "Visual Studio Team Services";
149+
}
150+
// if no matches, return null
151+
return null;
152+
}
153+
108154
function isUsageReportingEnabled() {
109155
return process.env.DISABLE_USAGE_REPORTING;
110156
}
111157

112158
function send(args) {
113159
if (!isUsageReportingEnabled()) return;
114160

115-
let [cli_version, cli_path] = cli_version_and_path(args.bsConfig);
161+
let bsConfig = args.bstack_config;
162+
let [cli_version, cli_path] = cli_version_and_path(bsConfig);
163+
164+
delete args.bstack_config;
116165

117166
const payload = {
118-
api_key: config.usageReportingApiKey,
167+
event_type: "cypress_cli_stats",
119168
data: {
120-
event_type: 'cypress_cli_instrumentation',
121169
os: _os(),
122170
os_version: os_version(),
123171
bstack_json_found_in_pwd: bstack_json_found_in_pwd(),
124172
cypress_json_found_in_pwd: cypress_json_found_in_pwd(),
125173
cli_version: cli_version,
126174
cli_path: cli_path,
127175
npm_version: npm_version(),
128-
local_cypress_version: local_cypress_version(args.bstack_config),
129-
timestamp: new Date().getTime(),
130-
...args
131-
}
176+
local_cypress_version: local_cypress_version(bsConfig),
177+
ci_environment: ci_environment(),
178+
event_timestamp: new Date().toLocaleString(),
179+
...args,
180+
},
132181
};
133182

134183
const options = {
135-
method: 'POST',
184+
headers: {
185+
"Content-Type": "text/json",
186+
},
187+
method: "POST",
136188
url: config.usageReportingUrl,
137189
body: payload,
138-
json: true
139-
}
190+
json: true,
191+
};
140192

141193
fileLogger.info(`Sending ${payload} to ${config.usageReportingUrl}`);
142194
request(options, function (error, res, body) {

0 commit comments

Comments
 (0)