diff --git a/__tests__/poll.test.ts b/__tests__/poll.test.ts index 4f9a098..f5f6dff 100644 --- a/__tests__/poll.test.ts +++ b/__tests__/poll.test.ts @@ -1,8 +1,10 @@ import {poll} from '../src/poll' const client = { - checks: { - listForRef: jest.fn() + rest: { + checks: { + listForRef: jest.fn() + } } } @@ -19,7 +21,7 @@ const run = () => }) test('returns conclusion of completed check', async () => { - client.checks.listForRef.mockResolvedValue({ + client.rest.checks.listForRef.mockResolvedValue({ data: { check_runs: [ { @@ -38,7 +40,7 @@ test('returns conclusion of completed check', async () => { const result = await run() expect(result).toBe('success') - expect(client.checks.listForRef).toHaveBeenCalledWith({ + expect(client.rest.checks.listForRef).toHaveBeenCalledWith({ owner: 'testOrg', repo: 'testRepo', ref: 'abcd', @@ -47,7 +49,7 @@ test('returns conclusion of completed check', async () => { }) test('polls until check is completed', async () => { - client.checks.listForRef + client.rest.checks.listForRef .mockResolvedValueOnce({ data: { check_runs: [ @@ -83,11 +85,11 @@ test('polls until check is completed', async () => { const result = await run() expect(result).toBe('failure') - expect(client.checks.listForRef).toHaveBeenCalledTimes(3) + expect(client.rest.checks.listForRef).toHaveBeenCalledTimes(3) }) test(`returns 'timed_out' if exceeding deadline`, async () => { - client.checks.listForRef.mockResolvedValue({ + client.rest.checks.listForRef.mockResolvedValue({ data: { check_runs: [ { diff --git a/src/main.ts b/src/main.ts index 72910ca..5fb86ed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import {context, GitHub} from '@actions/github' +import github, {context} from '@actions/github' import {poll} from './poll' async function run(): Promise { @@ -7,7 +7,7 @@ async function run(): Promise { const token = core.getInput('token', {required: true}) const result = await poll({ - client: new GitHub(token), + client: github.getOctokit(token), log: msg => core.info(msg), checkName: core.getInput('checkName', {required: true}), @@ -21,7 +21,7 @@ async function run(): Promise { core.setOutput('conclusion', result) } catch (error) { - core.setFailed(error.message) + core.setFailed(error instanceof Error ? error : JSON.stringify(error)) } } diff --git a/src/poll.ts b/src/poll.ts index 73b423a..b82dc49 100644 --- a/src/poll.ts +++ b/src/poll.ts @@ -1,8 +1,8 @@ -import {GitHub} from '@actions/github' +import {GitHub} from '@actions/github/lib/utils' import {wait} from './wait' export interface Options { - client: GitHub + client: InstanceType log: (message: string) => void checkName: string @@ -32,7 +32,7 @@ export const poll = async (options: Options): Promise => { log( `Retrieving check runs named ${checkName} on ${owner}/${repo}@${ref}...` ) - const result = await client.checks.listForRef({ + const result = await client.rest.checks.listForRef({ // eslint-disable-next-line @typescript-eslint/camelcase check_name: checkName, owner, @@ -51,7 +51,8 @@ export const poll = async (options: Options): Promise => { log( `Found a completed check with id ${completedCheck.id} and conclusion ${completedCheck.conclusion}` ) - return completedCheck.conclusion + // conclusion is only `null` if status is not `completed`. + return completedCheck.conclusion! } log(