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

Upgrade @octokit/plugin-throttling and fix type errors #294

Merged
merged 1 commit into from
May 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@changesets/pre": "^1.0.9",
"@changesets/read": "^0.5.3",
"@manypkg/get-packages": "^1.1.3",
"@octokit/plugin-throttling": "5.1.1",
"@octokit/plugin-throttling": "^5.2.1",
"@types/fs-extra": "^8.0.0",
"@types/jest": "^29.5.1",
"@types/node": "^12.7.1",
Expand Down
12 changes: 7 additions & 5 deletions src/readChangesetState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ export default async function readChangesetState(
cwd: string = process.cwd()
): Promise<ChangesetState> {
let preState = await readPreState(cwd);
let isInPreMode = preState !== undefined && preState.mode === "pre";

let changesets = await readChangesets(cwd);

if (isInPreMode) {
if (preState !== undefined && preState.mode === "pre") {
let changesetsToFilter = new Set(preState.changesets);
changesets = changesets.filter((x) => !changesetsToFilter.has(x.id));

return {
preState,
changesets: changesets.filter((x) => !changesetsToFilter.has(x.id)),
};
}

return {
preState: isInPreMode ? preState : undefined,
preState: undefined,
changesets,
};
}
20 changes: 14 additions & 6 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import * as gitUtils from "./gitUtils";
import readChangesetState from "./readChangesetState";
import resolveFrom from "resolve-from";
import { throttling } from "@octokit/plugin-throttling";
// temporary workaround for https://github.com/octokit/plugin-throttling.js/pull/590
import type {} from "@octokit/plugin-throttling/dist-types/types.d";

// GitHub Issues/PRs messages have a max size limit on the
// message body payload.
// `body is too long (maximum is 65536 characters)`.
// To avoid that, we ensure to cap the message to 60k chars.
const MAX_CHARACTERS_PER_MESSAGE = 60000;

const setupOctokit = (githubToken) => {
const setupOctokit = (githubToken: string) => {
return new (GitHub.plugin(throttling))(
getOctokitOptions(githubToken, {
throttle: {
Expand Down Expand Up @@ -61,7 +59,7 @@ const setupOctokit = (githubToken) => {
};

const createRelease = async (
octokit: ReturnType<typeof GitHub>,
octokit: ReturnType<typeof setupOctokit>,
{ pkg, tagName }: { pkg: Package; tagName: string }
) => {
try {
Expand All @@ -87,7 +85,12 @@ const createRelease = async (
});
} catch (err) {
// if we can't find a changelog, the user has probably disabled changelogs
if (err.code !== "ENOENT") {
if (
err &&
typeof err === "object" &&
"code" in err &&
err.code !== "ENOENT"
) {
throw err;
}
}
Expand Down Expand Up @@ -205,7 +208,12 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
try {
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
} catch (err) {
if (err && err.code === "MODULE_NOT_FOUND") {
if (
err &&
typeof err === "object" &&
"code" in err &&
err.code === "MODULE_NOT_FOUND"
) {
throw new Error(
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`
);
Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
// @ts-ignore
import mdastToString from "mdast-util-to-string";
import { exec } from "@actions/exec";
import { getPackages, Package } from "@manypkg/get-packages";

export const BumpLevels = {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1751,10 +1751,10 @@
"@octokit/types" "^6.39.0"
deprecation "^2.3.1"

"@octokit/plugin-throttling@5.1.1":
version "5.1.1"
resolved "https://registry.yarnpkg.com/@octokit/plugin-throttling/-/plugin-throttling-5.1.1.tgz#7e7ff4646a8ad622d34d9e0c5be7a7e6ea35ba10"
integrity sha512-UlsdoW3ZOhhvjnK8S+OmQWOvB14kaKKdxseGFAxVHVggKZlgKO/ZtAb1AQoHXaQUCfO7uV/O5BR27o/wbKAzHg==
"@octokit/plugin-throttling@^5.2.1":
version "5.2.1"
resolved "https://registry.yarnpkg.com/@octokit/plugin-throttling/-/plugin-throttling-5.2.1.tgz#0600a0165bb439afaf40cf7cccae21cea7b3fd03"
integrity sha512-UUTFP301/gYEgsPABIP35QZR4dEXPtyoXHCQhPXU8U4FphXKjXOahoMlHg/T4IQVWMmSy607zsqThuBkpV9Gjg==
dependencies:
"@octokit/types" "^9.0.0"
bottleneck "^2.15.3"
Expand Down