Skip to content

Commit f48ef2d

Browse files
committed
Removing github token from input
1 parent c0f7ff9 commit f48ef2d

File tree

6 files changed

+15
-99
lines changed

6 files changed

+15
-99
lines changed

setup-env/config/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = {
44
ACCESS_KEY: 'access-key',
55
BUILD_NAME: 'build-name',
66
PROJECT_NAME: 'project-name',
7-
GITHUB_TOKEN: 'github-token',
87
GITHUB_APP: 'github-app',
98
},
109

setup-env/dist/index.js

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
ACCESS_KEY: 'access-key',
1111
BUILD_NAME: 'build-name',
1212
PROJECT_NAME: 'project-name',
13-
GITHUB_TOKEN: 'github-token',
1413
GITHUB_APP: 'github-app',
1514
},
1615

@@ -9361,7 +9360,6 @@ class ActionInput {
93619360
// non-compulsory fields
93629361
this.buildName = core.getInput(INPUT.BUILD_NAME);
93639362
this.projectName = core.getInput(INPUT.PROJECT_NAME);
9364-
this.githubToken = core.getInput(INPUT.GITHUB_TOKEN);
93659363
this.githubApp = core.getInput(INPUT.GITHUB_APP);
93669364
this.rerunAttempt = process?.env?.GITHUB_RUN_ATTEMPT;
93679365
this.runId = process?.env?.GITHUB_RUN_ID;
@@ -9378,7 +9376,6 @@ class ActionInput {
93789376
this.username = InputValidator.updateUsername(this.username);
93799377
this.buildName = InputValidator.validateBuildName(this.buildName);
93809378
this.projectName = InputValidator.validateProjectName(this.projectName);
9381-
this.githubToken = InputValidator.validateGithubToken(this.githubToken);
93829379
this.githubApp = InputValidator.validateGithubAppName(this.githubApp);
93839380
}
93849381

@@ -9409,14 +9406,16 @@ class ActionInput {
94099406
}
94109407

94119408
async checkIfBStackReRun() {
9412-
// Using !! ensures that the function returns true or false, regardless of the input values.
9413-
if (!this.rerunAttempt || !this.rerunAttempt > 1) {
9409+
// Ensure rerunAttempt is a number and greater than 1
9410+
if (!this.rerunAttempt || Number(this.rerunAttempt) <= 1) {
94149411
return false;
94159412
}
9416-
if (!this.runId || !this.runId > 1 || !this.repository || this.repository === 'none'
9417-
|| !this.githubToken || this.githubToken === 'none' || !this.username || !this.accessKey) {
9413+
9414+
// Ensure runId, repository, username, and accessKey are valid
9415+
if (!this.runId || !this.repository || this.repository === 'none' || !this.username || !this.accessKey) {
94189416
return false;
94199417
}
9418+
94209419
const triggeringActor = await this.identifyRunFromBStack();
94219420
core.info(`Triggering actor is - ${triggeringActor}`);
94229421
return triggeringActor === this.githubApp;
@@ -9427,7 +9426,7 @@ class ActionInput {
94279426
const runDetailsUrl = `https://api.github.com/repos/${this.repository}/actions/runs/${this.runId}`;
94289427
const runDetailsResponse = await axios.get(runDetailsUrl, {
94299428
headers: {
9430-
Authorization: `token ${this.githubToken}`,
9429+
Authorization: `token ${process.env.GITHUB_TOKEN}`,
94319430
Accept: 'application/vnd.github.v3+json',
94329431
},
94339432
});
@@ -9593,29 +9592,6 @@ class InputValidator {
95939592
return inputProjectName;
95949593
}
95959594

9596-
/**
9597-
* Validates the GitHub token input to ensure it is a valid non-empty string.
9598-
* If the input is 'none' or not provided, it returns 'none'.
9599-
* @param {string} githubToken Input for 'github-token'
9600-
* @returns {string} The validated GitHub token, or 'none' if input is 'none' or invalid
9601-
* @throws {Error} If the input is not a valid non-empty string
9602-
*/
9603-
static validateGithubToken(githubToken) {
9604-
if (typeof githubToken !== 'string') {
9605-
throw new Error("Invalid input for 'github-token'. Must be a valid non-empty string.");
9606-
}
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.");
9617-
}
9618-
96199595
/**
96209596
* Validates the app name input to ensure it is a valid non-empty string.
96219597
* If the input is 'none' or not provided, it returns 'browserstack[bot]'.

setup-env/src/actionInput/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ActionInput {
3232
// non-compulsory fields
3333
this.buildName = core.getInput(INPUT.BUILD_NAME);
3434
this.projectName = core.getInput(INPUT.PROJECT_NAME);
35-
this.githubToken = core.getInput(INPUT.GITHUB_TOKEN);
3635
this.githubApp = core.getInput(INPUT.GITHUB_APP);
3736
this.rerunAttempt = process?.env?.GITHUB_RUN_ATTEMPT;
3837
this.runId = process?.env?.GITHUB_RUN_ID;
@@ -49,7 +48,6 @@ class ActionInput {
4948
this.username = InputValidator.updateUsername(this.username);
5049
this.buildName = InputValidator.validateBuildName(this.buildName);
5150
this.projectName = InputValidator.validateProjectName(this.projectName);
52-
this.githubToken = InputValidator.validateGithubToken(this.githubToken);
5351
this.githubApp = InputValidator.validateGithubAppName(this.githubApp);
5452
}
5553

@@ -80,14 +78,16 @@ class ActionInput {
8078
}
8179

8280
async checkIfBStackReRun() {
83-
// Using !! ensures that the function returns true or false, regardless of the input values.
84-
if (!this.rerunAttempt || !this.rerunAttempt > 1) {
81+
// Ensure rerunAttempt is a number and greater than 1
82+
if (!this.rerunAttempt || Number(this.rerunAttempt) <= 1) {
8583
return false;
8684
}
87-
if (!this.runId || !this.runId > 1 || !this.repository || this.repository === 'none'
88-
|| !this.githubToken || this.githubToken === 'none' || !this.username || !this.accessKey) {
85+
86+
// Ensure runId, repository, username, and accessKey are valid
87+
if (!this.runId || !this.repository || this.repository === 'none' || !this.username || !this.accessKey) {
8988
return false;
9089
}
90+
9191
const triggeringActor = await this.identifyRunFromBStack();
9292
core.info(`Triggering actor is - ${triggeringActor}`);
9393
return triggeringActor === this.githubApp;
@@ -98,7 +98,7 @@ class ActionInput {
9898
const runDetailsUrl = `https://api.github.com/repos/${this.repository}/actions/runs/${this.runId}`;
9999
const runDetailsResponse = await axios.get(runDetailsUrl, {
100100
headers: {
101-
Authorization: `token ${this.githubToken}`,
101+
Authorization: `token ${process.env.GITHUB_TOKEN}`,
102102
Accept: 'application/vnd.github.v3+json',
103103
},
104104
});

setup-env/src/actionInput/inputValidator.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,6 @@ class InputValidator {
115115
return inputProjectName;
116116
}
117117

118-
/**
119-
* Validates the GitHub token input to ensure it is a valid non-empty string.
120-
* If the input is 'none' or not provided, it returns 'none'.
121-
* @param {string} githubToken Input for 'github-token'
122-
* @returns {string} The validated GitHub token, or 'none' if input is 'none' or invalid
123-
* @throws {Error} If the input is not a valid non-empty string
124-
*/
125-
static validateGithubToken(githubToken) {
126-
if (typeof githubToken !== 'string') {
127-
throw new Error("Invalid input for 'github-token'. Must be a valid non-empty string.");
128-
}
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.");
139-
}
140-
141118
/**
142119
* Validates the app name input to ensure it is a valid non-empty string.
143120
* If the input is 'none' or not provided, it returns 'browserstack[bot]'.

setup-env/test/actionInput/index.test.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ describe('Action Input operations for fetching all inputs, triggering validation
2020
sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername');
2121
sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName');
2222
sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName');
23-
sinon.stub(InputValidator, 'validateGithubToken').returns('validatedToken');
2423
sinon.stub(InputValidator, 'validateGithubAppName').returns('validatedAppName');
2524

2625
// Provide required inputs
@@ -67,14 +66,6 @@ describe('Action Input operations for fetching all inputs, triggering validation
6766
expect(e.message).to.eq('Action input failed for reason: Access Key Required');
6867
}
6968
});
70-
71-
it('Takes input and validates GitHub token and app name successfully', () => {
72-
stubbedInput.withArgs(INPUT.GITHUB_TOKEN).returns('someToken');
73-
stubbedInput.withArgs(INPUT.GITHUB_APP).returns('someApp');
74-
const actionInput = new ActionInput();
75-
expect(actionInput.githubToken).to.eq('validatedToken');
76-
expect(actionInput.githubApp).to.eq('validatedAppName');
77-
});
7869
});
7970

8071
context('Set Environment Variables', () => {
@@ -113,7 +104,6 @@ describe('Action Input operations for fetching all inputs, triggering validation
113104
sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername');
114105
sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName');
115106
sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName');
116-
sinon.stub(InputValidator, 'validateGithubToken').returns('validatedToken');
117107
sinon.stub(InputValidator, 'validateGithubAppName').returns('validatedAppName');
118108

119109
// Provide required inputs
@@ -130,9 +120,8 @@ describe('Action Input operations for fetching all inputs, triggering validation
130120
});
131121

132122
it('Returns false if rerun attempt is less than or equal to 1', async () => {
133-
// stubbedInput.withArgs(INPUT.GITHUB_APP).returns('someApp');
134123
const actionInput = new ActionInput();
135-
actionInput.rerunAttempt = '1';
124+
actionInput.rerunAttempt = '1'; // This should be a string or number
136125
const result = await actionInput.checkIfBStackReRun();
137126
// eslint-disable-next-line no-unused-expressions
138127
expect(result).to.be.false;
@@ -172,7 +161,6 @@ describe('Action Input operations for fetching all inputs, triggering validation
172161
sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername');
173162
sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName');
174163
sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName');
175-
sinon.stub(InputValidator, 'validateGithubToken').returns('validatedToken');
176164
sinon.stub(InputValidator, 'validateGithubAppName').returns('validatedAppName');
177165

178166
// Provide required inputs
@@ -223,7 +211,6 @@ describe('Action Input operations for fetching all inputs, triggering validation
223211
sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername');
224212
sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName');
225213
sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName');
226-
sinon.stub(InputValidator, 'validateGithubToken').returns('validatedToken');
227214
sinon.stub(InputValidator, 'validateGithubAppName').returns('validatedAppName');
228215

229216
// Provide required inputs

setup-env/test/actionInput/inputValidator.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,6 @@ describe('InputValidator class to validate individual fields of the action input
153153
});
154154
});
155155

156-
context('Validates GitHub Token', () => {
157-
it("Returns 'none' if the token is not provided", () => {
158-
expect(() => InputValidator.validateGithubToken()).to.throw("Invalid input for 'github-token'. Must be a valid non-empty string.");
159-
});
160-
161-
it("Returns 'none' if the token is 'none' (case insensitive)", () => {
162-
expect(InputValidator.validateGithubToken('None')).to.eq('none');
163-
});
164-
165-
it('Throws an error if the token is an empty string', () => {
166-
expect(() => InputValidator.validateGithubToken('')).to.throw("Invalid input for 'github-token'. Must be a valid non-empty string.");
167-
});
168-
169-
it('Throws an error if the token is not a valid string', () => {
170-
expect(() => InputValidator.validateGithubToken(123)).to.throw("Invalid input for 'github-token'. Must be a valid non-empty string.");
171-
});
172-
173-
it('Returns the token if it is a valid non-empty string and not "none"', () => {
174-
const validToken = 'someValidToken';
175-
expect(InputValidator.validateGithubToken(validToken)).to.eq(validToken);
176-
});
177-
});
178-
179156
context('Validates GitHub App Name', () => {
180157
it("Returns 'browserstack[bot]' if the app name is not provided", () => {
181158
expect(() => InputValidator.validateGithubAppName()).to.throw("Invalid input for 'github-app'. Must be a valid string.");

0 commit comments

Comments
 (0)