Skip to content

Commit c0f7ff9

Browse files
committed
Added test cases
1 parent ba05fb4 commit c0f7ff9

File tree

9 files changed

+297
-68
lines changed

9 files changed

+297
-68
lines changed

setup-env/config/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
BROWSERSTACK_PROJECT_NAME: 'BROWSERSTACK_PROJECT_NAME',
1616
},
1717

18-
BROWSERSTACK_TEMPLATE: {
18+
BROWSERSTACK_INTEGRATIONS: {
1919
DETAILS_API_URL: 'https://integrate.browserstack.com/api/ci-tools/v1/builds/{runId}/rebuild/details?tool=github-actions&as_bot=true',
2020
},
2121
};

setup-env/dist/index.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
BROWSERSTACK_PROJECT_NAME: 'BROWSERSTACK_PROJECT_NAME',
2222
},
2323

24-
BROWSERSTACK_TEMPLATE: {
24+
BROWSERSTACK_INTEGRATIONS: {
2525
DETAILS_API_URL: 'https://integrate.browserstack.com/api/ci-tools/v1/builds/{runId}/rebuild/details?tool=github-actions&as_bot=true',
2626
},
2727
};
@@ -9329,10 +9329,9 @@ function wrappy (fn, cb) {
93299329

93309330
const core = __nccwpck_require__(2186);
93319331
const axios = __nccwpck_require__(8757);
9332-
const github = __nccwpck_require__(5438);
93339332
const InputValidator = __nccwpck_require__(4881);
93349333
const constants = __nccwpck_require__(1468);
9335-
const { BROWSERSTACK_TEMPLATE } = __nccwpck_require__(1468);
9334+
const { BROWSERSTACK_INTEGRATIONS } = __nccwpck_require__(1468);
93369335

93379336
const {
93389337
INPUT,
@@ -9366,7 +9365,7 @@ class ActionInput {
93669365
this.githubApp = core.getInput(INPUT.GITHUB_APP);
93679366
this.rerunAttempt = process?.env?.GITHUB_RUN_ATTEMPT;
93689367
this.runId = process?.env?.GITHUB_RUN_ID;
9369-
this.repository = `${github?.context?.repo?.owner}/${github?.context?.repo?.repo}`;
9368+
this.repository = process?.env?.GITHUB_REPOSITORY;
93709369
} catch (e) {
93719370
throw Error(`Action input failed for reason: ${e.message}`);
93729371
}
@@ -9411,7 +9410,6 @@ class ActionInput {
94119410

94129411
async checkIfBStackReRun() {
94139412
// Using !! ensures that the function returns true or false, regardless of the input values.
9414-
core.info(`The variables set are: rerunAttempt - ${this.rerunAttempt}, runId - ${this.runId}, repository - ${this.repository}, githubToken - ${this.githubToken}`);
94159413
if (!this.rerunAttempt || !this.rerunAttempt > 1) {
94169414
return false;
94179415
}
@@ -9445,7 +9443,7 @@ class ActionInput {
94459443
// Check if the run was triggered by the BrowserStack rerun bot
94469444
core.info('The re-run was triggered by the GitHub App from BrowserStack.');
94479445

9448-
const browserStackApiUrl = BROWSERSTACK_TEMPLATE.DETAILS_API_URL.replace('{runId}', this.runId);
9446+
const browserStackApiUrl = BROWSERSTACK_INTEGRATIONS.DETAILS_API_URL.replace('{runId}', this.runId);
94499447

94509448
// Call BrowserStack API to get the tests to rerun
94519449
const bsApiResponse = await axios.get(browserStackApiUrl, {
@@ -9603,30 +9601,42 @@ class InputValidator {
96039601
* @throws {Error} If the input is not a valid non-empty string
96049602
*/
96059603
static validateGithubToken(githubToken) {
9606-
if (githubToken && githubToken.toLowerCase() !== 'none') {
9607-
if (typeof githubToken === 'string' && githubToken.trim().length > 0) {
9608-
return githubToken;
9609-
}
9604+
if (typeof githubToken !== 'string') {
96109605
throw new Error("Invalid input for 'github-token'. Must be a valid non-empty string.");
96119606
}
9612-
return 'none';
9607+
9608+
if (githubToken.toLowerCase() === 'none') {
9609+
return 'none';
9610+
}
9611+
9612+
if (githubToken.trim().length > 0) {
9613+
return githubToken;
9614+
}
9615+
9616+
throw new Error("Invalid input for 'github-token'. Must be a valid non-empty string.");
96139617
}
96149618

96159619
/**
96169620
* Validates the app name input to ensure it is a valid non-empty string.
9617-
* If the input is 'none' or not provided, it returns 'none'.
9618-
* @param {string} githubAppName Input for 'repository'
9619-
* @returns {string} Validated app name, or 'none' if input is 'none' or invalid
9621+
* If the input is 'none' or not provided, it returns 'browserstack[bot]'.
9622+
* @param {string} githubAppName Input for 'github-app'
9623+
* @returns {string} Validated app name, or 'browserstack[bot]' if input is 'none' or invalid
96209624
* @throws {Error} If the input is not a valid non-empty string
96219625
*/
96229626
static validateGithubAppName(githubAppName) {
9623-
if (githubAppName && githubAppName.toLowerCase() !== 'browserstack[bot]') {
9624-
if (typeof githubAppName === 'string' && githubAppName.trim().length > 0) {
9625-
return githubAppName;
9626-
}
9627+
if (typeof githubAppName !== 'string') {
96279628
throw new Error("Invalid input for 'github-app'. Must be a valid string.");
96289629
}
9629-
return 'browserstack[bot]';
9630+
9631+
if (githubAppName.toLowerCase() === 'browserstack[bot]') {
9632+
return 'browserstack[bot]';
9633+
}
9634+
9635+
if (githubAppName.trim().length > 0) {
9636+
return githubAppName;
9637+
}
9638+
9639+
throw new Error("Invalid input for 'github-app'. Must be a valid string.");
96309640
}
96319641
}
96329642

@@ -14605,7 +14615,7 @@ const ActionInput = __nccwpck_require__(9426);
1460514615
const run = async () => {
1460614616
try {
1460714617
const inputParser = new ActionInput();
14608-
inputParser.setEnvVariables();
14618+
await inputParser.setEnvVariables();
1460914619
} catch (e) {
1461014620
core.setFailed(`Action Failed: ${e}`);
1461114621
}

setup-env/src/actionInput/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const core = require('@actions/core');
22
const axios = require('axios');
3-
const github = require('@actions/github');
43
const InputValidator = require('./inputValidator');
54
const constants = require('../../config/constants');
6-
const { BROWSERSTACK_TEMPLATE } = require("../../config/constants");
5+
const { BROWSERSTACK_INTEGRATIONS } = require("../../config/constants");
76

87
const {
98
INPUT,
@@ -37,7 +36,7 @@ class ActionInput {
3736
this.githubApp = core.getInput(INPUT.GITHUB_APP);
3837
this.rerunAttempt = process?.env?.GITHUB_RUN_ATTEMPT;
3938
this.runId = process?.env?.GITHUB_RUN_ID;
40-
this.repository = `${github?.context?.repo?.owner}/${github?.context?.repo?.repo}`;
39+
this.repository = process?.env?.GITHUB_REPOSITORY;
4140
} catch (e) {
4241
throw Error(`Action input failed for reason: ${e.message}`);
4342
}
@@ -115,7 +114,7 @@ class ActionInput {
115114
// Check if the run was triggered by the BrowserStack rerun bot
116115
core.info('The re-run was triggered by the GitHub App from BrowserStack.');
117116

118-
const browserStackApiUrl = BROWSERSTACK_TEMPLATE.DETAILS_API_URL.replace('{runId}', this.runId);
117+
const browserStackApiUrl = BROWSERSTACK_INTEGRATIONS.DETAILS_API_URL.replace('{runId}', this.runId);
119118

120119
// Call BrowserStack API to get the tests to rerun
121120
const bsApiResponse = await axios.get(browserStackApiUrl, {

setup-env/src/actionInput/inputValidator.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,42 @@ class InputValidator {
123123
* @throws {Error} If the input is not a valid non-empty string
124124
*/
125125
static validateGithubToken(githubToken) {
126-
if (githubToken && githubToken.toLowerCase() !== 'none') {
127-
if (typeof githubToken === 'string' && githubToken.trim().length > 0) {
128-
return githubToken;
129-
}
126+
if (typeof githubToken !== 'string') {
130127
throw new Error("Invalid input for 'github-token'. Must be a valid non-empty string.");
131128
}
132-
return 'none';
129+
130+
if (githubToken.toLowerCase() === 'none') {
131+
return 'none';
132+
}
133+
134+
if (githubToken.trim().length > 0) {
135+
return githubToken;
136+
}
137+
138+
throw new Error("Invalid input for 'github-token'. Must be a valid non-empty string.");
133139
}
134140

135141
/**
136142
* Validates the app name input to ensure it is a valid non-empty string.
137-
* If the input is 'none' or not provided, it returns 'none'.
138-
* @param {string} githubAppName Input for 'repository'
139-
* @returns {string} Validated app name, or 'none' if input is 'none' or invalid
143+
* If the input is 'none' or not provided, it returns 'browserstack[bot]'.
144+
* @param {string} githubAppName Input for 'github-app'
145+
* @returns {string} Validated app name, or 'browserstack[bot]' if input is 'none' or invalid
140146
* @throws {Error} If the input is not a valid non-empty string
141147
*/
142148
static validateGithubAppName(githubAppName) {
143-
if (githubAppName && githubAppName.toLowerCase() !== 'browserstack[bot]') {
144-
if (typeof githubAppName === 'string' && githubAppName.trim().length > 0) {
145-
return githubAppName;
146-
}
149+
if (typeof githubAppName !== 'string') {
147150
throw new Error("Invalid input for 'github-app'. Must be a valid string.");
148151
}
149-
return 'browserstack[bot]';
152+
153+
if (githubAppName.toLowerCase() === 'browserstack[bot]') {
154+
return 'browserstack[bot]';
155+
}
156+
157+
if (githubAppName.trim().length > 0) {
158+
return githubAppName;
159+
}
160+
161+
throw new Error("Invalid input for 'github-app'. Must be a valid string.");
150162
}
151163
}
152164

setup-env/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ActionInput = require('./actionInput');
99
const run = async () => {
1010
try {
1111
const inputParser = new ActionInput();
12-
inputParser.setEnvVariables();
12+
await inputParser.setEnvVariables();
1313
} catch (e) {
1414
core.setFailed(`Action Failed: ${e}`);
1515
}

0 commit comments

Comments
 (0)