Skip to content

converted session stop to build stop command in cli #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions commands/build_stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const axios = require('axios');
const constants = require("./utils/constants.js");
const process = require("process");
const fs = require("fs");
function stop_session(args) {
function stop_build(args) {
return new Promise(function (resolve, reject) {
var username = "";
var access_key = "";
Expand All @@ -26,33 +26,33 @@ function stop_session(args) {
} else {
reject("Access Key not provided");
}
if ("stop_last_session" in args) {
if ("stop_last_build" in args) {
const file_path = "lambdatest_run.json";
if (fs.existsSync(file_path)) {
let lambda_run = fs.readFileSync(file_path);
try {
let lambda_run_obj = JSON.parse(lambda_run);
if (!("session_id" in lambda_run_obj)) {
throw new Error("session_id is missing from the file");
if (!("build_id" in lambda_run_obj)) {
throw new Error("build_id is missing from the file");
}
args.session_id = lambda_run_obj.session_id;
args.build_id = lambda_run_obj.build_id;
} catch (e) {
reject(
"Error!! lambdatest_run.json file is tampered Err: " + e.message
);
}
} else {
reject(
"Error!! Last session details not found, lambdatest_run.json file not present!!"
"Error!! Last Build details not found, lambdatest_run.json file not present!!"
);
}
} else {
if (
!("session_id" in args) ||
args["session_id"] == "" ||
args["session_id"] == undefined
!("build_id" in args) ||
args["build_id"] == "" ||
args["build_id"] == undefined
) {
reject("Error!! Please provide a Session ID");
reject("Error!! Please provide a Build ID");
}
}
var env = "prod";
Expand All @@ -68,7 +68,7 @@ function stop_session(args) {

let options = {
method: 'put',
url: constants[env].BUILD_STOP_URL + args.session_id,
url: constants[env].BUILD_STOP_URL + "?buildId=" + args.build_id,
headers: {
Authorization: "Token " + access_key,
Username: username,
Expand All @@ -93,10 +93,10 @@ function stop_session(args) {
axios(options)
.then(response => {
if(response.data.length == 0){
resolve("No tests to stop in session " + args.session_id);
resolve("No tests to stop in build " + args.build_id);
} else {
resolve(
"Session Stopped successfully, No. of tests stopped are: " +
"Build Stopped successfully, No. of tests stopped are: " +
response.data.length
);
}
Expand All @@ -120,7 +120,7 @@ function stop_session(args) {
}

module.exports = function (args) {
stop_session(args)
stop_build(args)
.then(function (resp) {
console.log(resp);
})
Expand Down
10 changes: 5 additions & 5 deletions commands/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
prod: {
INTEGRATION_BASE_URL: "https://api.lambdatest.com/liis",
BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL: "https://api.lambdatest.com/api/v1/test/stop?sessionId=",
BUILD_STOP_URL: "https://api.lambdatest.com/api/v1/test/stop",
SESSION_URL:
"https://api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
Expand All @@ -35,7 +35,7 @@ module.exports = {
BUILD_BASE_URL:
"https://api-cypdevenv22-dev.lambdatestinternal.com/automation/api/v1/builds/",
BUILD_STOP_URL:
"https://api-cypdevenv22-dev.lambdatestinternal.com/api/v1/test/stop?sessionId=",
"https://api-cypdevenv22-dev.lambdatestinternal.com/api/v1/test/stop",
SESSION_URL:
"https://api-cypdevenv22-dev.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
Expand All @@ -47,7 +47,7 @@ module.exports = {
BUILD_BASE_URL:
"https://stage-api.lambdatestinternal.com/automation/api/v1/builds/",
BUILD_STOP_URL:
"https://stage-api.lambdatestinternal.com/api/v1/test/stop?sessionId=",
"https://stage-api.lambdatestinternal.com/api/v1/test/stop",
SESSION_URL:
"https://stage-api.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
Expand All @@ -59,7 +59,7 @@ module.exports = {
BUILD_BASE_URL:
"https://prestage-api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL:
"https://prestage-api.lambdatest.com/api/v1/test/stop?sessionId=",
"https://prestage-api.lambdatest.com/api/v1/test/stop",
SESSION_URL:
"https://prestage-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
Expand All @@ -70,7 +70,7 @@ module.exports = {
BUILD_BASE_URL:
"https://preprod-api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL:
"https://preprod-api.lambdatest.com/api/v1/test/stop?sessionId=",
"https://preprod-api.lambdatest.com/api/v1/test/stop",
SESSION_URL:
"https://preprod-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
Expand Down
2 changes: 1 addition & 1 deletion commands/utils/poller/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const axios = require('axios');
function stop_cypress_session(lt_config, session_id, env) {
return new Promise(function (resolve, reject) {
let options = {
url: constants[env].BUILD_STOP_URL + session_id,
url: constants[env].BUILD_STOP_URL + "?sessionId=" + session_id,
headers: {
Authorization: "Token " + lt_config["lambdatest_auth"]["access_key"],
Username: lt_config["lambdatest_auth"]["username"],
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ const argv = require("yargs")
function (yargs) {
return yargs
.option("id", {
alias: "session_id",
describe: "Session Identifier",
alias: "build_id",
describe: "Build Identifier",
type: "string",
})
.option("user", {
Expand All @@ -306,9 +306,9 @@ const argv = require("yargs")
"Default rejects self signed certificates in external requests",
type: "bool",
})
.option("sls", {
alias: "stop_last_session",
describe: "stop last session",
.option("slb", {
alias: "stop_last_build",
describe: "stop last build",
type: "bool",
});
},
Expand Down