Skip to content

Commit 93aebce

Browse files
Merge pull request #69 from riday-bs/INTG-2232
🐛 Fix: Use env variable to get triggeringActor instead of API call
2 parents 4478e16 + 5962ee7 commit 93aebce

File tree

3 files changed

+6
-87
lines changed

3 files changed

+6
-87
lines changed

setup-env/dist/index.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34647,27 +34647,11 @@ class ActionInput {
3464734647
return false;
3464834648
}
3464934649

34650-
const triggeringActor = await this.identifyRunFromBStack();
34650+
const triggeringActor = process.env.GITHUB_TRIGGERING_ACTOR;
3465134651
core.info(`Triggering actor is - ${triggeringActor}`);
3465234652
return triggeringActor === this.githubApp;
3465334653
}
3465434654

34655-
async identifyRunFromBStack() {
34656-
try {
34657-
const runDetailsUrl = `https://api.github.com/repos/${this.repository}/actions/runs/${this.runId}`;
34658-
const runDetailsResponse = await axios.get(runDetailsUrl, {
34659-
headers: {
34660-
Authorization: `token ${this.githubToken}`,
34661-
Accept: 'application/vnd.github.v3+json',
34662-
},
34663-
});
34664-
34665-
return runDetailsResponse.data.triggering_actor?.login;
34666-
} catch (error) {
34667-
core.info(`Error getting run details to identify actor of the build: ${error.message}`);
34668-
}
34669-
}
34670-
3467134655
async setBStackRerunEnvVars() {
3467234656
try {
3467334657
// Check if the run was triggered by the BrowserStack rerun bot

setup-env/src/actionInput/index.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,11 @@ class ActionInput {
9191
return false;
9292
}
9393

94-
const triggeringActor = await this.identifyRunFromBStack();
94+
const triggeringActor = process.env.GITHUB_TRIGGERING_ACTOR;
9595
core.info(`Triggering actor is - ${triggeringActor}`);
9696
return triggeringActor === this.githubApp;
9797
}
9898

99-
async identifyRunFromBStack() {
100-
try {
101-
const runDetailsUrl = `https://api.github.com/repos/${this.repository}/actions/runs/${this.runId}`;
102-
const runDetailsResponse = await axios.get(runDetailsUrl, {
103-
headers: {
104-
Authorization: `token ${this.githubToken}`,
105-
Accept: 'application/vnd.github.v3+json',
106-
},
107-
});
108-
109-
return runDetailsResponse.data.triggering_actor?.login;
110-
} catch (error) {
111-
core.info(`Error getting run details to identify actor of the build: ${error.message}`);
112-
}
113-
}
114-
11599
async setBStackRerunEnvVars() {
116100
try {
117101
// Check if the run was triggered by the BrowserStack rerun bot

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

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -160,69 +160,20 @@ describe('Action Input operations for fetching all inputs, triggering validation
160160

161161
it('Returns true if rerun was triggered by the GitHub App', async () => {
162162
const actionInput = new ActionInput();
163-
sinon.stub(actionInput, 'identifyRunFromBStack').returns(Promise.resolve('validatedAppName'));
163+
process.env.GITHUB_TRIGGERING_ACTOR = 'validatedAppName';
164164
const result = await actionInput.checkIfBStackReRun();
165165
// eslint-disable-next-line no-unused-expressions
166166
expect(result).to.be.true;
167+
delete process.env.GITHUB_TRIGGERING_ACTOR;
167168
});
168169

169170
it('Returns false if rerun was not triggered by the GitHub App', async () => {
170171
const actionInput = new ActionInput();
171-
sinon.stub(actionInput, 'identifyRunFromBStack').returns(Promise.resolve('otherActor'));
172+
process.env.GITHUB_TRIGGERING_ACTOR = 'otherActor';
172173
const result = await actionInput.checkIfBStackReRun();
173174
// eslint-disable-next-line no-unused-expressions
174175
expect(result).to.be.false;
175-
});
176-
});
177-
178-
context('Identify Run From BrowserStack', () => {
179-
let axiosGetStub;
180-
let stubbedInput;
181-
182-
beforeEach(() => {
183-
stubbedInput = sinon.stub(core, 'getInput');
184-
sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername');
185-
sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName');
186-
sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName');
187-
sinon.stub(InputValidator, 'validateGithubAppName').returns('validatedAppName');
188-
sinon.stub(InputValidator, 'validateGithubToken').returns('validatedToken');
189-
190-
// Provide required inputs
191-
stubbedInput.withArgs(INPUT.USERNAME, { required: true }).returns('someUsername');
192-
stubbedInput.withArgs(INPUT.ACCESS_KEY, { required: true }).returns('someAccessKey');
193-
194-
process.env.GITHUB_REPOSITORY = 'browserstack/github-actions';
195-
process.env.GITHUB_RUN_ID = '12345';
196-
process.env.GITHUB_RUN_ATTEMPT = '2';
197-
198-
// Stub the axios.get method
199-
axiosGetStub = sinon.stub(axios, 'get');
200-
// Stub core.info to prevent it from throwing an error
201-
sinon.stub(core, 'info');
202-
});
203-
204-
afterEach(() => {
205-
sinon.restore();
206-
});
207-
208-
it('Returns the triggering actor from the GitHub API', async () => {
209-
const actionInput = new ActionInput();
210-
axiosGetStub.resolves({
211-
data: {
212-
triggering_actor: { login: 'someActor' },
213-
},
214-
});
215-
const result = await actionInput.identifyRunFromBStack();
216-
expect(result).to.eq('someActor');
217-
});
218-
219-
it('Handles errors and returns undefined when GitHub API fails', async () => {
220-
const actionInput = new ActionInput();
221-
axiosGetStub.rejects(new Error('API failed'));
222-
const result = await actionInput.identifyRunFromBStack();
223-
// eslint-disable-next-line no-unused-expressions
224-
expect(result).to.be.undefined;
225-
sinon.assert.calledOnce(core.info);
176+
delete process.env.GITHUB_TRIGGERING_ACTOR;
226177
});
227178
});
228179

0 commit comments

Comments
 (0)