-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:browserstack/browserstack-cypress…
…-cli
- Loading branch information
Showing
18 changed files
with
987 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,94 @@ | ||
'use strict'; | ||
var config = require('../helpers/config'); | ||
var request = require('request') | ||
var logger = require("../helpers/logger"); | ||
var Constant = require("../helpers/constants") | ||
const request = require('request'); | ||
|
||
const config = require("../helpers/config"), | ||
logger = require("../helpers/logger").winstonLogger, | ||
Constants = require("../helpers/constants"), | ||
util = require("../helpers/util"); | ||
|
||
module.exports = function info(args) { | ||
return buildInfo(args) | ||
} | ||
|
||
function buildInfo(args) { | ||
let bsConfigPath = process.cwd() + args.cf; | ||
logger.log(`Reading config from ${args.cf}`); | ||
var bsConfig = require(bsConfigPath); | ||
|
||
let buildId = args._[1] | ||
|
||
let options = { | ||
url: config.buildUrl + buildId, | ||
method: 'GET', | ||
auth: { | ||
user: bsConfig.auth.username, | ||
password: bsConfig.auth.access_key | ||
} | ||
} | ||
|
||
request(options, function (err, resp, body) { | ||
if (err) { | ||
logger.log(Constant.userMessages.BUILD_INFO_FAILED); | ||
} else { | ||
let build = null | ||
try { | ||
build = JSON.parse(body) | ||
} catch (error) { | ||
build = null | ||
} | ||
|
||
if (resp.statusCode != 200) { | ||
if (build) { | ||
logger.error(`${Constant.userMessages.BUILD_INFO_FAILED} with error: \n${JSON.stringify(build, null, 2)}`); | ||
} else { | ||
logger.error(Constant.userMessages.BUILD_INFO_FAILED); | ||
|
||
util.validateBstackJson(bsConfigPath).then(function (bsConfig) { | ||
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting); | ||
|
||
let buildId = args._[1]; | ||
|
||
let options = { | ||
url: config.buildUrl + buildId, | ||
method: "GET", | ||
auth: { | ||
user: bsConfig.auth.username, | ||
password: bsConfig.auth.access_key, | ||
}, | ||
headers: { | ||
"User-Agent": util.getUserAgent(), | ||
}, | ||
}; | ||
|
||
request(options, function (err, resp, body) { | ||
let message = null; | ||
let messageType = null; | ||
let errorCode = null; | ||
|
||
if (err) { | ||
message = Constants.userMessages.BUILD_INFO_FAILED; | ||
messageType = Constants.messageTypes.ERROR; | ||
errorCode = 'api_failed_build_info'; | ||
|
||
logger.info(message); | ||
} else { | ||
let build = null; | ||
try { | ||
build = JSON.parse(body); | ||
} catch (error) { | ||
build = null; | ||
} | ||
} else if(resp.statusCode == 299) { | ||
if(build) { | ||
logger.log(build.message); | ||
|
||
if (resp.statusCode == 299) { | ||
messageType = Constants.messageTypes.INFO; | ||
errorCode = "api_deprecated"; | ||
|
||
if (build) { | ||
message = build.message; | ||
logger.info(message); | ||
} else { | ||
message = Constants.userMessages.API_DEPRECATED; | ||
logger.info(message); | ||
} | ||
} else if (resp.statusCode != 200) { | ||
messageType = Constants.messageTypes.ERROR; | ||
errorCode = "api_failed_build_info"; | ||
|
||
if (build) { | ||
message = `${ | ||
Constants.userMessages.BUILD_INFO_FAILED | ||
} with error: \n${JSON.stringify(build, null, 2)}`; | ||
logger.error(message); | ||
if (build.message === "Unauthorized") errorCode = "api_auth_failed"; | ||
} else { | ||
message = Constants.userMessages.BUILD_INFO_FAILED; | ||
logger.error(message); | ||
} | ||
} else { | ||
logger.log(Constants.userMessages.API_DEPRECATED); | ||
messageType = Constants.messageTypes.SUCCESS; | ||
message = `Build info for build id: \n ${JSON.stringify( | ||
build, | ||
null, | ||
2 | ||
)}`; | ||
logger.info(message); | ||
} | ||
} else { | ||
logger.log(`Build info for build id: \n ${JSON.stringify(build, null, 2)}`) | ||
} | ||
} | ||
}) | ||
util.sendUsageReport(bsConfig, args, message, messageType, errorCode); | ||
}) | ||
}).catch(function (err) { | ||
logger.error(err); | ||
util.setUsageReportingFlag(null, args.disableUsageReporting); | ||
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err)); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.