From 5962ee78f5cf0647e9ff00026c3b98c307daa251 Mon Sep 17 00:00:00 2001 From: Riday Shah Date: Tue, 16 Sep 2025 19:19:54 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Use=20env=20variable=20to?= =?UTF-8?q?=20get=20triggeringActor=20instead=20of=20API=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup-env/dist/index.js | 18 +------- setup-env/src/actionInput/index.js | 18 +------- setup-env/test/actionInput/index.test.js | 57 ++---------------------- 3 files changed, 6 insertions(+), 87 deletions(-) diff --git a/setup-env/dist/index.js b/setup-env/dist/index.js index 80dc3baa..434ee126 100644 --- a/setup-env/dist/index.js +++ b/setup-env/dist/index.js @@ -34647,27 +34647,11 @@ class ActionInput { return false; } - const triggeringActor = await this.identifyRunFromBStack(); + const triggeringActor = process.env.GITHUB_TRIGGERING_ACTOR; core.info(`Triggering actor is - ${triggeringActor}`); return triggeringActor === this.githubApp; } - async identifyRunFromBStack() { - try { - const runDetailsUrl = `https://api.github.com/repos/${this.repository}/actions/runs/${this.runId}`; - const runDetailsResponse = await axios.get(runDetailsUrl, { - headers: { - Authorization: `token ${this.githubToken}`, - Accept: 'application/vnd.github.v3+json', - }, - }); - - return runDetailsResponse.data.triggering_actor?.login; - } catch (error) { - core.info(`Error getting run details to identify actor of the build: ${error.message}`); - } - } - async setBStackRerunEnvVars() { try { // Check if the run was triggered by the BrowserStack rerun bot diff --git a/setup-env/src/actionInput/index.js b/setup-env/src/actionInput/index.js index f5518e82..741a79be 100644 --- a/setup-env/src/actionInput/index.js +++ b/setup-env/src/actionInput/index.js @@ -91,27 +91,11 @@ class ActionInput { return false; } - const triggeringActor = await this.identifyRunFromBStack(); + const triggeringActor = process.env.GITHUB_TRIGGERING_ACTOR; core.info(`Triggering actor is - ${triggeringActor}`); return triggeringActor === this.githubApp; } - async identifyRunFromBStack() { - try { - const runDetailsUrl = `https://api.github.com/repos/${this.repository}/actions/runs/${this.runId}`; - const runDetailsResponse = await axios.get(runDetailsUrl, { - headers: { - Authorization: `token ${this.githubToken}`, - Accept: 'application/vnd.github.v3+json', - }, - }); - - return runDetailsResponse.data.triggering_actor?.login; - } catch (error) { - core.info(`Error getting run details to identify actor of the build: ${error.message}`); - } - } - async setBStackRerunEnvVars() { try { // Check if the run was triggered by the BrowserStack rerun bot diff --git a/setup-env/test/actionInput/index.test.js b/setup-env/test/actionInput/index.test.js index 0bfa0a76..b870513d 100644 --- a/setup-env/test/actionInput/index.test.js +++ b/setup-env/test/actionInput/index.test.js @@ -160,69 +160,20 @@ describe('Action Input operations for fetching all inputs, triggering validation it('Returns true if rerun was triggered by the GitHub App', async () => { const actionInput = new ActionInput(); - sinon.stub(actionInput, 'identifyRunFromBStack').returns(Promise.resolve('validatedAppName')); + process.env.GITHUB_TRIGGERING_ACTOR = 'validatedAppName'; const result = await actionInput.checkIfBStackReRun(); // eslint-disable-next-line no-unused-expressions expect(result).to.be.true; + delete process.env.GITHUB_TRIGGERING_ACTOR; }); it('Returns false if rerun was not triggered by the GitHub App', async () => { const actionInput = new ActionInput(); - sinon.stub(actionInput, 'identifyRunFromBStack').returns(Promise.resolve('otherActor')); + process.env.GITHUB_TRIGGERING_ACTOR = 'otherActor'; const result = await actionInput.checkIfBStackReRun(); // eslint-disable-next-line no-unused-expressions expect(result).to.be.false; - }); - }); - - context('Identify Run From BrowserStack', () => { - let axiosGetStub; - let stubbedInput; - - beforeEach(() => { - stubbedInput = sinon.stub(core, 'getInput'); - sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername'); - sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName'); - sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName'); - sinon.stub(InputValidator, 'validateGithubAppName').returns('validatedAppName'); - sinon.stub(InputValidator, 'validateGithubToken').returns('validatedToken'); - - // Provide required inputs - stubbedInput.withArgs(INPUT.USERNAME, { required: true }).returns('someUsername'); - stubbedInput.withArgs(INPUT.ACCESS_KEY, { required: true }).returns('someAccessKey'); - - process.env.GITHUB_REPOSITORY = 'browserstack/github-actions'; - process.env.GITHUB_RUN_ID = '12345'; - process.env.GITHUB_RUN_ATTEMPT = '2'; - - // Stub the axios.get method - axiosGetStub = sinon.stub(axios, 'get'); - // Stub core.info to prevent it from throwing an error - sinon.stub(core, 'info'); - }); - - afterEach(() => { - sinon.restore(); - }); - - it('Returns the triggering actor from the GitHub API', async () => { - const actionInput = new ActionInput(); - axiosGetStub.resolves({ - data: { - triggering_actor: { login: 'someActor' }, - }, - }); - const result = await actionInput.identifyRunFromBStack(); - expect(result).to.eq('someActor'); - }); - - it('Handles errors and returns undefined when GitHub API fails', async () => { - const actionInput = new ActionInput(); - axiosGetStub.rejects(new Error('API failed')); - const result = await actionInput.identifyRunFromBStack(); - // eslint-disable-next-line no-unused-expressions - expect(result).to.be.undefined; - sinon.assert.calledOnce(core.info); + delete process.env.GITHUB_TRIGGERING_ACTOR; }); });