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

Bump @octokit/rest from 16.43.1 to 17.2.1 #1146

Merged
merged 4 commits into from
May 17, 2020
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"rimraf": "^3.0.0",
"title-case": "^3.0.2",
"ts-jest": "^25.0.0",
"type-fest": "^0.13.1",
"typescript": "~3.8.3"
},
"husky": {
Expand Down
9 changes: 4 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@
},
"dependencies": {
"@auto-it/bot-list": "link:../../packages/bot-list",
"@octokit/core": "2.4.2",
"@octokit/graphql": "4.3.1",
"@octokit/plugin-enterprise-compatibility": "1.2.2",
"@octokit/plugin-retry": "3.0.1",
"@octokit/graphql": "^4.4.0",
"@octokit/plugin-enterprise-compatibility": "^1.2.2",
"@octokit/plugin-retry": "^3.0.1",
"@octokit/plugin-throttling": "^3.2.0",
"@octokit/rest": "16.43.1",
"@octokit/rest": "^17.9.0",
"await-to-js": "^2.1.1",
"chalk": "^4.0.0",
"cosmiconfig": "6.0.0",
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/__tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ describe("github", () => {
});

await gh.getCommitsForPR(22);
expect(listCommits).toHaveBeenCalled();
expect(paginate).toHaveBeenCalled();
});

test("getPullRequests", async () => {
Expand Down Expand Up @@ -672,8 +672,7 @@ describe("github", () => {

describe("error hook", () => {
test("strip authorization headers from error", () => {
type HookError = import("@octokit/rest").Octokit.HookError;
const error = (headers = {}): HookError => ({
const error = (headers = {}) => ({
name: "Request failed",
message: "The request has failed",
status: 404,
Expand All @@ -685,9 +684,7 @@ describe("github", () => {

expect(errorHook).toHaveBeenCalled();

const errorHandler = errorHook.mock.calls[0][1] as (
error: HookError
) => void;
const errorHandler = errorHook.mock.calls[0][1] as (error: Error) => void;

expect(
errorHandler.bind(undefined, error({ authorization: "token abc" }))
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Octokit } from "@octokit/rest";
import { RestEndpointMethodTypes } from "@octokit/rest";
import dotenv from "dotenv";
import envCi from "env-ci";
import fs from "fs";
Expand Down Expand Up @@ -117,6 +117,8 @@ interface BeforeShipitContext {
releaseType: ShipitRelease;
}

type PublishResponse = RestEndpointMethodTypes["repos"]["createRelease"]["response"];

export interface IAutoHooks {
/** Modify what is in the config. You must return the config in this hook. */
modifyConfig: SyncWaterfallHook<[LoadedAutoRc]>;
Expand Down Expand Up @@ -154,9 +156,7 @@ export interface IAutoHooks {
/** The generated release notes for the commits */
releaseNotes: string;
/** The response from creating the new release. */
response?:
| Octokit.Response<Octokit.ReposCreateReleaseResponse>
| Array<Octokit.Response<Octokit.ReposCreateReleaseResponse>>;
response?: PublishResponse | PublishResponse[];
}
]
>;
Expand All @@ -178,9 +178,7 @@ export interface IAutoHooks {
commits: IExtendedCommit[];
}
],
| Octokit.Response<Octokit.ReposCreateReleaseResponse>
| Array<Octokit.Response<Octokit.ReposCreateReleaseResponse>>
| void
PublishResponse | PublishResponse[] | void
>;
/** Get git author. Typically from a package distribution description file. */
getAuthor: AsyncSeriesBailHook<[], Partial<AuthorInformation> | void>;
Expand Down
48 changes: 27 additions & 21 deletions packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { enterpriseCompatibility } from "@octokit/plugin-enterprise-compatibilit
import path from "path";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";
import { Octokit } from "@octokit/rest";
import { Octokit, RestEndpointMethodTypes } from "@octokit/rest";
import { gitlogPromise as gitlog } from "gitlog";
import { HttpsProxyAgent } from "https-proxy-agent";
import tinyColor from "tinycolor2";
Expand All @@ -23,7 +23,10 @@ import { buildSearchQuery, ISearchResult } from "./match-sha-to-pr";
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> &
Partial<Pick<T, K>>;

export type IPRInfo = Omit<Octokit.ReposCreateStatusParams, "owner" | "repo">;
export type IPRInfo = Omit<
RestEndpointMethodTypes["repos"]["createStatus"]["parameters"],
"owner" | "repo"
>;

export interface IGitOptions {
/** Github repo owner (user) */
Expand Down Expand Up @@ -118,7 +121,7 @@ export default class Git {
return true;
}
},
onAbuseLimit: (retryAfter: number, opts: ThrottleOpts) => {
onAbuseLimit: (_: number, opts: ThrottleOpts) => {
// does not retry, only logs an error
this.logger.log.error(
`Went over abuse rate limit ${opts.method} ${opts.url}`
Expand Down Expand Up @@ -218,7 +221,7 @@ export default class Git {
async getLabels(prNumber: number) {
this.logger.verbose.info(`Getting labels for PR: ${prNumber}`);

const args: Octokit.IssuesListLabelsOnIssueParams = {
const args: RestEndpointMethodTypes["issues"]["listLabelsOnIssue"]["parameters"] = {
owner: this.options.owner,
repo: this.options.repo,
issue_number: prNumber,
Expand All @@ -245,7 +248,7 @@ export default class Git {
async getPr(prNumber: number) {
this.logger.verbose.info(`Getting info for PR: ${prNumber}`);

const args: Octokit.IssuesListLabelsOnIssueParams = {
const args: RestEndpointMethodTypes["issues"]["get"]["parameters"] = {
owner: this.options.owner,
repo: this.options.repo,
issue_number: prNumber,
Expand Down Expand Up @@ -295,8 +298,9 @@ export default class Git {
};

try {
const labels: Octokit.IssuesListLabelsForRepoResponse = await this.github.paginate(
this.github.issues.listLabelsForRepo.endpoint(args)
const labels = await this.github.paginate(
this.github.issues.listLabelsForRepo,
args
);

this.logger.veryVerbose.info(
Expand Down Expand Up @@ -440,7 +444,7 @@ export default class Git {
async getPullRequest(pr: number) {
this.logger.verbose.info(`Getting Pull Request: ${pr}`);

const args: Octokit.PullsGetParams = {
const args: RestEndpointMethodTypes["pulls"]["get"]["parameters"] = {
owner: this.options.owner,
repo: this.options.repo,
pull_number: pr,
Expand All @@ -457,7 +461,9 @@ export default class Git {
}

/** Search to GitHub project's issue and pull requests */
async searchRepo(options: Octokit.SearchIssuesAndPullRequestsParams) {
async searchRepo(
options: RestEndpointMethodTypes["search"]["issuesAndPullRequests"]["parameters"]
) {
const repo = `repo:${this.options.owner}/${this.options.repo}`;
options.q = `${repo} ${options.q}`;

Expand Down Expand Up @@ -497,7 +503,9 @@ export default class Git {

this.logger.verbose.info("Creating status using:\n", args);

const result = await this.github.repos.createStatus(args);
const result = await this.github.repos.createStatus(
args as RestEndpointMethodTypes["repos"]["createStatus"]["parameters"]
);

this.logger.veryVerbose.info("Got response from createStatues\n", result);
this.logger.verbose.info("Created status on GitHub.");
Expand Down Expand Up @@ -621,7 +629,9 @@ export default class Git {
}

/** Get all the pull requests for a project */
async getPullRequests(options?: Partial<Octokit.PullsListParams>) {
async getPullRequests(
options?: Partial<RestEndpointMethodTypes["pulls"]["list"]["parameters"]>
) {
this.logger.verbose.info("Getting pull requests...");

const result = (
Expand All @@ -640,18 +650,14 @@ export default class Git {

/** Get all the commits for a PR */
@memoize()
async getCommitsForPR(
pr: number
): Promise<Octokit.PullsListCommitsResponseItem[]> {
async getCommitsForPR(pr: number) {
this.logger.verbose.info(`Getting commits for PR #${pr}`);

const result = await this.github.paginate(
this.github.pulls.listCommits.endpoint({
owner: this.options.owner.toLowerCase(),
repo: this.options.repo.toLowerCase(),
pull_number: pr,
})
);
const result = await this.github.paginate(this.github.pulls.listCommits, {
owner: this.options.owner.toLowerCase(),
repo: this.options.repo.toLowerCase(),
pull_number: pr,
});

this.logger.veryVerbose.info(`Got response from PR #${pr}\n`, result);
this.logger.verbose.info(`Got commits for PR #${pr}.`);
Expand Down
19 changes: 9 additions & 10 deletions packages/core/src/release.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
GraphQlQueryResponse,
GraphQlQueryResponseData,
} from "@octokit/graphql/dist-types/types";
import { Octokit } from "@octokit/rest";
import { AsyncReturnType } from "type-fest";
import on from "await-to-js";
import * as fs from "fs";
import chunk from "lodash.chunk";
Expand Down Expand Up @@ -252,7 +248,10 @@ export default class Release {
.filter((q): q is string => Boolean(q))
.map((q) => this.git.graphql(q))
);
const data = queries.filter((q): q is GraphQlQueryResponse => Boolean(q));
type GraphQlQueryResponseData = NonNullable<typeof queries[number]>;
const data = queries.filter((q): q is GraphQlQueryResponseData =>
Boolean(q)
);

if (!data.length) {
return uniqueCommits;
Expand All @@ -265,9 +264,9 @@ export default class Release {

type QueryEntry = [string, GraphQlQueryResponseData];

const entries = data.reduce(
const entries = data.reduce<QueryEntry[]>(
(acc, result) => [...acc, ...(Object.entries(result) as QueryEntry[])],
[] as QueryEntry[]
[]
);

await Promise.all(
Expand Down Expand Up @@ -630,7 +629,7 @@ export default class Release {
*/
private getPRForRebasedCommits(
commit: IExtendedCommit,
pullRequests: Octokit.PullsGetResponse[]
pullRequests: Array<AsyncReturnType<Git["getPullRequest"]>["data"]>
) {
const matchPr = pullRequests.find(
(pr) => pr.merge_commit_sha === commit.hash
Expand All @@ -655,7 +654,7 @@ export default class Release {
/** The GitHub user name of the git committer */
login?: string;
})
| Partial<Octokit.UsersGetByUsernameResponse>
| Partial<AsyncReturnType<Git["getUserByUsername"]>>
> = [];

// If there is a pull request we will attempt to get the authors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Auto from "@auto-it/core";
import makeCommitFromMsg from "@auto-it/core/dist/__tests__/make-commit-from-msg";
import Changelog from "@auto-it/core/dist/changelog";
import { Octokit } from "@octokit/rest";
import { RestEndpointMethodTypes } from "@octokit/rest";
import {
makeChangelogHooks,
makeHooks,
Expand All @@ -16,7 +16,11 @@ exec.mockReturnValue("");
jest.spyOn(Auto, "execPromise").mockImplementation(exec);

const setup = (
contributors: Array<Partial<Octokit.ReposListContributorsResponseItem>> = []
contributors: Array<
Partial<
RestEndpointMethodTypes["repos"]["listContributors"]["response"]["data"][number]
>
> = []
) => {
const plugin = new FirstTimeContributor();
const hooks = makeHooks();
Expand Down
1 change: 1 addition & 0 deletions plugins/first-time-contributor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class FirstTimeContributorPlugin implements IPlugin {

/** Tap into auto plugin points. */
apply(auto: Auto) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const cache: Record<string, Record<string, any>> = {};

auto.hooks.onCreateChangelog.tap(this.name, (changelog) => {
Expand Down
11 changes: 7 additions & 4 deletions plugins/npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "fs";
import parseAuthor from "parse-author";
import path from "path";
import { Memoize as memoize } from "typescript-memoize";
import { Octokit } from "@octokit/rest";
import { RestEndpointMethodTypes } from "@octokit/rest";
import * as t from "io-ts";
import { execSync } from "child_process";
import on from "await-to-js";
Expand Down Expand Up @@ -1013,9 +1013,12 @@ export default class NPMPlugin implements IPlugin {

this.renderMonorepoChangelog = false;

return releases.filter((release): release is Octokit.Response<
Octokit.ReposCreateReleaseResponse
> => Boolean(release));
return releases.filter(
(
release
): release is RestEndpointMethodTypes["repos"]["createRelease"]["response"] =>
Boolean(release)
);
}
});
}
Expand Down
10 changes: 7 additions & 3 deletions plugins/released/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Auto, IPlugin, validatePluginConfiguration } from "@auto-it/core";
import { IExtendedCommit } from "@auto-it/core/dist/log-parse";
import { Octokit } from "@octokit/rest";
import { RestEndpointMethodTypes } from "@octokit/rest";

import merge from "deepmerge";
import * as t from "io-ts";
Expand Down Expand Up @@ -114,7 +114,9 @@ export default class ReleasedLabelPlugin implements IPlugin {
private async addReleased(
auto: Auto,
commit: IExtendedCommit,
releases: Array<Octokit.Response<Octokit.ReposCreateReleaseResponse>>
releases: Array<
RestEndpointMethodTypes["repos"]["createRelease"]["response"]
>
) {
const messages = [commit.subject];
const isPrerelease = releases.some((r) => r.data.prerelease);
Expand Down Expand Up @@ -185,7 +187,9 @@ export default class ReleasedLabelPlugin implements IPlugin {
/** Whether the release was a prerelease */
isPrerelease?: boolean;
/** All of the releases that happened */
releases: Array<Octokit.Response<Octokit.ReposCreateReleaseResponse>>;
releases: Array<
RestEndpointMethodTypes["repos"]["createRelease"]["response"]
>;
}) {
// leave a comment with the new version
const urls = releases.map((release) =>
Expand Down
2 changes: 1 addition & 1 deletion plugins/slack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@atomist/slack-messages": "~1.1.0",
"@auto-it/core": "link:../../packages/core",
"@octokit/rest": "16.43.1",
"@octokit/rest": "^17.9.0",
"fp-ts": "^2.5.3",
"https-proxy-agent": "^5.0.0",
"io-ts": "^2.1.2",
Expand Down
8 changes: 5 additions & 3 deletions plugins/slack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { githubToSlack } from "@atomist/slack-messages";
import { Octokit } from "@octokit/rest";
import { RestEndpointMethodTypes } from "@octokit/rest";
import createHttpsProxyAgent from "https-proxy-agent";

import {
Expand Down Expand Up @@ -135,7 +135,9 @@ export default class SlackPlugin implements IPlugin {
auto: Auto,
newVersion: string,
releaseNotes: string,
releases: Array<Octokit.Response<Octokit.ReposCreateReleaseResponse>>
releases: Array<
RestEndpointMethodTypes["repos"]["createRelease"]["response"]
>
) {
if (!auto.git) {
return;
Expand Down Expand Up @@ -163,7 +165,7 @@ export default class SlackPlugin implements IPlugin {
link_names: 1,
}),
headers: { "Content-Type": "application/json" },
agent: proxyUrl ? createHttpsProxyAgent(proxyUrl) : undefined
agent: proxyUrl ? createHttpsProxyAgent(proxyUrl) : undefined,
});

auto.logger.verbose.info("Posted release notes to slack.");
Expand Down
Loading