Skip to content

Commit fc9d04a

Browse files
committed
Update request for hitting turboscale backend
1 parent bf50fd7 commit fc9d04a

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

bin/helpers/atsHelper.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// TODO: confirm if we need to add command line args. if yes then decide priority
22

3-
const logger = require("./logger").winstonLogger;
3+
const request = require('request'),
4+
logger = require('./logger').winstonLogger,
5+
utils = require('./utils'),
6+
config = require('./config');
7+
Constants = require('./constants');
48

59
exports.isTurboScaleSession = (bsConfig) => {
610
// env var will override config
@@ -39,15 +43,40 @@ exports.getTurboScaleGridName = (bsConfig) => {
3943
exports.getTurboScaleGridDetails = async (bsConfig) => {
4044
try {
4145
const gridName = this.getTurboScaleGridName(bsConfig);
42-
// TODO: update request making logic
43-
const response = await this.nodeRequest('GET', `${turboScaleConstants.API_ENDPOINT}/grids/${gridName}`, {}, bsConfig);
4446

45-
return JSON.parse(response.data);
47+
return new Promise((resolve, reject) => {
48+
let options = {
49+
url: `${config.turboScaleAPIUrl}/grids/${gridName}`,
50+
auth: {
51+
username: bsConfig.auth.username,
52+
password: bsConfig.auth.access_key,
53+
},
54+
headers: {
55+
'User-Agent': utils.getUserAgent(),
56+
}
57+
};
58+
let responseData = {};
59+
request.get(options, function (err, resp, data) {
60+
if(err) {
61+
logger.warn(utils.formatRequest(err, resp, data));
62+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
63+
resolve({});
64+
} else {
65+
try {
66+
responseData = JSON.parse(data);
67+
} catch (e) {
68+
responseData = {};
69+
}
70+
if(resp.statusCode != 200) {
71+
logger.warn(`Warn: Get Initial Details Request failed with status code ${resp.statusCode}`);
72+
utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
73+
resolve({});
74+
}
75+
resolve(responseData);
76+
}
77+
});
78+
});
4679
} catch (err) {
4780
logger.error(`Failed to find TurboScale Grid: ${err}: ${err.stack}`);
4881
}
4982
};
50-
51-
52-
53-
ATSGridName = getTurboScaleGridName(bsConfig);

bin/helpers/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/",
55
"usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal",
66
"localTestingListUrl": "https://www.browserstack.com/local/v1/list",
7-
"turboScaleUrl": "https://grid.browserstack.com/packages/cypress"
7+
"turboScaleUrl": "https://grid.browserstack.com/packages/cypress",
8+
"turboScaleAPIUrl": "https://api.browserstack.com/automate-turboscale/v1"
89
}

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let terminalWidth = (process.stdout.columns) * 0.9;
2424
let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
2525
if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
2626

27-
let getOptions = (auth, build_id) => {
27+
let getOptions = (auth, build_id) => {
2828
const options = {
2929
url: `${config.buildUrlV2}${build_id}`,
3030
auth: {

0 commit comments

Comments
 (0)