Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: @octokit/rest ^21.0.0 #1599

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-colts-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

deps: @octokit/rest ^21.0.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@jest/types": "^29.0.0",
"@octokit/graphql": "^8.0.0",
"@octokit/graphql-schema": "^15.3.0",
"@octokit/rest": "^20.0.0",
"@octokit/rest": "^21.0.0",
"@octokit/types": "^13.0.0",
"@types/jest": "^29.0.0",
"@types/node": ">=18.12",
Expand Down
284 changes: 151 additions & 133 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/api/github/checkRun.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Octokit } from '@octokit/rest';
import type { Endpoints } from '@octokit/types';
import git, { type ReadCommitResult } from 'isomorphic-git';

import type * as GitHub from '../github';

import { createCheckRun } from './checkRun';
import { createRestClient } from './octokit';

type CreateCheckRunResponse =
Endpoints['POST /repos/{owner}/{repo}/check-runs']['response'];

jest.mock('@octokit/rest');
jest.mock('isomorphic-git');
jest.mock('./octokit');

const mockClient = {
checks: {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('createCheckRun', () => {
const title = 'Build #23 failed';

beforeEach(() => {
jest.mocked(Octokit).mockReturnValue(mockClient as unknown as Octokit);
jest.mocked(createRestClient).mockResolvedValue(mockClient as never);
jest
.mocked(git.listRemotes)
.mockResolvedValue([
Expand All @@ -76,7 +76,7 @@ describe('createCheckRun', () => {
title,
});

expect(jest.mocked(Octokit)).toHaveBeenCalledWith({
expect(jest.mocked(createRestClient)).toHaveBeenCalledWith({
auth: 'Hello from GITHUB_API_TOKEN',
});
});
Expand All @@ -93,7 +93,7 @@ describe('createCheckRun', () => {
title,
});

expect(jest.mocked(Octokit)).toHaveBeenCalledWith({
expect(jest.mocked(createRestClient)).toHaveBeenCalledWith({
auth: 'Hello from GITHUB_TOKEN',
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/github/checkRun.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Octokit } from '@octokit/rest';
import type { Endpoints } from '@octokit/types';

import { pluralise } from '../../utils/logging';
import * as Git from '../git';

import { apiTokenFromEnvironment } from './environment';
import { createRestClient } from './octokit';

type Output = NonNullable<
Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters']['output']
Expand Down Expand Up @@ -106,7 +106,7 @@ export const createCheckRun = async ({
Git.getOwnerAndRepo({ dir }),
]);

const client = new Octokit({ auth: apiTokenFromEnvironment() });
const client = await createRestClient({ auth: apiTokenFromEnvironment() });

await client.checks.create({
conclusion,
Expand Down
18 changes: 9 additions & 9 deletions src/api/github/issueComment.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Octokit } from '@octokit/rest';
import git from 'isomorphic-git';

import { putIssueComment } from './issueComment';
import { createRestClient } from './octokit';

jest.mock('@octokit/rest');
jest.mock('isomorphic-git');
jest.mock('./octokit');

const mockClient = {
issues: {
Expand All @@ -27,7 +27,7 @@ beforeEach(() => {
{ remote: 'origin', url: '[email protected]:seek-oss/skuba.git' },
]);

jest.mocked(Octokit).mockReturnValue(mockClient as never);
jest.mocked(createRestClient).mockResolvedValue(mockClient as never);
});

afterEach(jest.resetAllMocks);
Expand All @@ -45,7 +45,7 @@ describe('putIssueComment', () => {
}),
).resolves.toStrictEqual({ id: 789 });

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);

expect(mockClient.issues.listComments).toHaveBeenCalledTimes(1);
expect(mockClient.issues.listComments.mock.calls[0][0])
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('putIssueComment', () => {
}),
).resolves.toStrictEqual({ id: 789 });

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);

expect(mockClient.users.getAuthenticated).toHaveBeenCalledTimes(1);

Expand Down Expand Up @@ -176,7 +176,7 @@ describe('putIssueComment', () => {
}),
).resolves.toStrictEqual({ id: 789 });

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);

expect(mockClient.users.getAuthenticated).toHaveBeenCalledTimes(1);

Expand Down Expand Up @@ -238,7 +238,7 @@ describe('putIssueComment', () => {
}),
).resolves.toStrictEqual({ id: 789 });

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);

expect(mockClient.users.getAuthenticated).toHaveBeenCalledTimes(1);

Expand Down Expand Up @@ -301,7 +301,7 @@ describe('putIssueComment', () => {
}),
).resolves.toStrictEqual({ id: 789 });

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);

expect(mockClient.users.getAuthenticated).toHaveBeenCalledTimes(1);

Expand Down Expand Up @@ -357,7 +357,7 @@ describe('putIssueComment', () => {
}),
).resolves.toStrictEqual({ id: 789 });

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);

// This should be skipped when `userId` is specified.
expect(mockClient.users.getAuthenticated).not.toHaveBeenCalled();
Expand Down
5 changes: 3 additions & 2 deletions src/api/github/issueComment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Octokit } from '@octokit/rest';
import type { Octokit } from '@octokit/rest';

import * as Git from '../git';

import { apiTokenFromEnvironment } from './environment';
import { createRestClient } from './octokit';
import { getPullRequestNumber } from './pullRequest';

const getUserId = async (client: Octokit): Promise<number> => {
Expand Down Expand Up @@ -83,7 +84,7 @@ export const putIssueComment = async (

const { owner, repo } = await Git.getOwnerAndRepo({ dir });

const client = new Octokit({ auth: apiTokenFromEnvironment() });
const client = await createRestClient({ auth: apiTokenFromEnvironment() });

const issueNumber =
params.issueNumber ?? (await getPullRequestNumber({ client, env }));
Expand Down
5 changes: 5 additions & 0 deletions src/api/github/octokit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Octokit } from '@octokit/rest';
import type { RequestParameters } from '@octokit/types';

export const createRestClient = async (options: {
auth: unknown;
}): Promise<Octokit> => new (await import('@octokit/rest')).Octokit(options);
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Octokit type appears to be auth?: any 😅


export const graphql = async <ResponseData>(
query: string,
parameters?: RequestParameters,
Expand Down
14 changes: 8 additions & 6 deletions src/api/github/pullRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Octokit } from '@octokit/rest';
import git from 'isomorphic-git';

import { createRestClient } from './octokit';
import { getPullRequestNumber } from './pullRequest';

jest.mock('@octokit/rest');
jest.mock('isomorphic-git');
jest.mock('./octokit');

const mockClient = {
repos: {
listPullRequestsAssociatedWithCommit: jest.fn(),
},
};

beforeEach(() => jest.mocked(Octokit).mockReturnValue(mockClient as never));
beforeEach(() =>
jest.mocked(createRestClient).mockResolvedValue(mockClient as never),
);

afterEach(jest.resetAllMocks);

Expand All @@ -22,15 +24,15 @@ describe('getPullRequestNumber', () => {
getPullRequestNumber({ env: { BUILDKITE_PULL_REQUEST: '123' } }),
).resolves.toBe(123);

expect(Octokit).not.toHaveBeenCalled();
expect(createRestClient).not.toHaveBeenCalled();
});

it('prefers a GitHub Actions environment variable', async () => {
await expect(
getPullRequestNumber({ env: { GITHUB_REF: 'refs/pull/456/merge' } }),
).resolves.toBe(456);

expect(Octokit).not.toHaveBeenCalled();
expect(createRestClient).not.toHaveBeenCalled();
});

it('falls back to the most recently updated pull request from the GitHub API', async () => {
Expand Down Expand Up @@ -96,7 +98,7 @@ describe('getPullRequestNumber', () => {
}
`);

expect(Octokit).toHaveBeenCalledTimes(1);
expect(createRestClient).toHaveBeenCalledTimes(1);
});

it('throws on an empty response from the GitHub API', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/api/github/pullRequest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Octokit } from '@octokit/rest';
import type { Octokit } from '@octokit/rest';

import * as Git from '../git';

import { apiTokenFromEnvironment } from './environment';
import { createRestClient } from './octokit';

interface GetPullRequestParameters {
/**
Expand Down Expand Up @@ -41,7 +42,8 @@ export const getPullRequestNumber = async (
}

const client =
params.client ?? new Octokit({ auth: apiTokenFromEnvironment() });
params.client ??
(await createRestClient({ auth: apiTokenFromEnvironment() }));

const [commitId, { owner, repo }] = await Promise.all([
Git.getHeadCommitId({ dir, env }),
Expand Down