diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 7a25abc..59649d6 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -10,53 +10,17 @@ import * as core from '@actions/core' import * as main from '../src/main' // Mock the GitHub Actions core library -const debugMock = jest.spyOn(core, 'debug') const getInputMock = jest.spyOn(core, 'getInput') const setFailedMock = jest.spyOn(core, 'setFailed') -const setOutputMock = jest.spyOn(core, 'setOutput') // Mock the action's main function const runMock = jest.spyOn(main, 'run') -// Other utilities -const timeRegex = /^\d{2}:\d{2}:\d{2}/ - describe('action', () => { beforeEach(() => { jest.clearAllMocks() }) - it('sets the time output', async () => { - // Set the action's inputs as return values from core.getInput() - getInputMock.mockImplementation((name: string): string => { - switch (name) { - case 'milliseconds': - return '500' - default: - return '' - } - }) - - await main.run() - expect(runMock).toHaveReturned() - - // Verify that all of the core library functions were called correctly - expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') - expect(debugMock).toHaveBeenNthCalledWith( - 2, - expect.stringMatching(timeRegex) - ) - expect(debugMock).toHaveBeenNthCalledWith( - 3, - expect.stringMatching(timeRegex) - ) - expect(setOutputMock).toHaveBeenNthCalledWith( - 1, - 'time', - expect.stringMatching(timeRegex) - ) - }) - it('sets a failed status', async () => { // Set the action's inputs as return values from core.getInput() getInputMock.mockImplementation((name: string): string => { diff --git a/dist/index.js b/dist/index.js index eb6aea9..3ea07ec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15189,7 +15189,7 @@ const auth_app_1 = __nccwpck_require__(7541); const app_1 = __nccwpck_require__(4389); async function getInstallationId(app, owner) { for await (const { installation } of app.eachInstallation.iterator()) { - if (installation.account?.login.toLowerCase() == owner.toLowerCase()) { + if (installation.account?.login.toLowerCase() === owner.toLowerCase()) { return installation.id; } } @@ -15210,10 +15210,10 @@ async function getInstallationToken(appId, privateKey, clientId, clientSecret, i exports.getInstallationToken = getInstallationToken; function newGitHubApp(appId, privateKey, clientId, clientSecret) { return new app_1.App({ - appId: appId, - privateKey: privateKey, - clientId: clientId, - clientSecret: clientSecret + appId, + privateKey, + clientId, + clientSecret }); } exports.newGitHubApp = newGitHubApp; @@ -15289,9 +15289,9 @@ async function run() { const owner = (0, helpers_1.getEnvironmentVariable)('GITHUB_REPOSITORY_OWNER'); core.info('searching for installation'); const app = (0, auth_1.newGitHubApp)(appId, privateKey, clientId, clientSecret); - var id = await (0, auth_1.getInstallationId)(app, owner); + const id = await (0, auth_1.getInstallationId)(app, owner); core.info('found installation id, getting token'); - var token = await (0, auth_1.getInstallationToken)(appId, privateKey, clientId, clientSecret, id); + const token = await (0, auth_1.getInstallationToken)(appId, privateKey, clientId, clientSecret, id); core.info('got token, setting output'); core.setSecret(token); core.setOutput('app_install_token', token); diff --git a/src/auth.ts b/src/auth.ts index e8e186f..6cb4ff5 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -3,7 +3,7 @@ import { App } from '@octokit/app' async function getInstallationId(app: App, owner: string): Promise { for await (const { installation } of app.eachInstallation.iterator()) { - if (installation.account?.login.toLowerCase() == owner.toLowerCase()) { + if (installation.account?.login.toLowerCase() === owner.toLowerCase()) { return installation.id } } @@ -37,10 +37,10 @@ function newGitHubApp( clientSecret: string ): App { return new App({ - appId: appId, - privateKey: privateKey, - clientId: clientId, - clientSecret: clientSecret + appId, + privateKey, + clientId, + clientSecret }) } diff --git a/src/main.ts b/src/main.ts index 0a1e9f2..85e1078 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,9 +16,9 @@ export async function run(): Promise { core.info('searching for installation') const app = newGitHubApp(appId, privateKey, clientId, clientSecret) - var id = await getInstallationId(app, owner) + const id = await getInstallationId(app, owner) core.info('found installation id, getting token') - var token = await getInstallationToken( + const token = await getInstallationToken( appId, privateKey, clientId,