From 55e5630a46785c2196639f774797083f170cbd96 Mon Sep 17 00:00:00 2001 From: Nicola Molinari Date: Fri, 4 Mar 2022 10:13:55 +0100 Subject: [PATCH 1/7] fix: body max length --- src/run.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/run.ts b/src/run.ts index 09b140ee..f7347555 100644 --- a/src/run.ts +++ b/src/run.ts @@ -15,6 +15,12 @@ import * as gitUtils from "./gitUtils"; import readChangesetState from "./readChangesetState"; import resolveFrom from "resolve-from"; +// 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 createRelease = async ( octokit: ReturnType, { pkg, tagName }: { pkg: Package; tagName: string } @@ -282,6 +288,14 @@ ${ let searchResult = await searchResultPromise; console.log(JSON.stringify(searchResult.data, null, 2)); + + let messageBody = await prBodyPromise; + if (messageBody.length > MAX_CHARACTERS_PER_MESSAGE) { + messageBody = [ + messageBody.substring(0, MAX_CHARACTERS_PER_MESSAGE), + "[Too long, message truncated]", + ].join("\n\n"); + } if (searchResult.data.items.length === 0) { console.log("creating pull request"); const { @@ -290,7 +304,7 @@ ${ base: branch, head: versionBranch, title: finalPrTitle, - body: await prBodyPromise, + body: messageBody, ...github.context.repo, }); @@ -301,7 +315,7 @@ ${ await octokit.pulls.update({ pull_number: searchResult.data.items[0].number, title: finalPrTitle, - body: await prBodyPromise, + body: messageBody, ...github.context.repo, }); console.log("pull request found"); From 71fc24b2e1e86f0608a50b4ff4c9cb2b7aef999d Mon Sep 17 00:00:00 2001 From: Nicola Molinari Date: Fri, 4 Mar 2022 11:16:36 +0100 Subject: [PATCH 2/7] docs: improve logs --- src/run.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/run.ts b/src/run.ts index f7347555..c03ce39b 100644 --- a/src/run.ts +++ b/src/run.ts @@ -291,6 +291,9 @@ ${ let messageBody = await prBodyPromise; if (messageBody.length > MAX_CHARACTERS_PER_MESSAGE) { + console.log( + `message body too long, truncating at ${MAX_CHARACTERS_PER_MESSAGE} charachters.` + ); messageBody = [ messageBody.substring(0, MAX_CHARACTERS_PER_MESSAGE), "[Too long, message truncated]", @@ -298,9 +301,7 @@ ${ } if (searchResult.data.items.length === 0) { console.log("creating pull request"); - const { - data: { number }, - } = await octokit.pulls.create({ + const { data: newPullRequest } = await octokit.pulls.create({ base: branch, head: versionBranch, title: finalPrTitle, @@ -309,19 +310,21 @@ ${ }); return { - pullRequestNumber: number, + pullRequestNumber: newPullRequest.number, }; } else { + const [pullRequest] = searchResult.data.items; + + console.log("pull request found, updating"); await octokit.pulls.update({ - pull_number: searchResult.data.items[0].number, + pull_number: pullRequest.number, title: finalPrTitle, body: messageBody, ...github.context.repo, }); - console.log("pull request found"); return { - pullRequestNumber: searchResult.data.items[0].number, + pullRequestNumber: pullRequest.number, }; } } From 97e55697befe5b5bc58867e28df2a75c4425f888 Mon Sep 17 00:00:00 2001 From: Nicola Molinari Date: Fri, 4 Mar 2022 11:21:32 +0100 Subject: [PATCH 3/7] docs: changeset --- .changeset/lucky-pans-thank.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lucky-pans-thank.md diff --git a/.changeset/lucky-pans-thank.md b/.changeset/lucky-pans-thank.md new file mode 100644 index 00000000..ee9696f2 --- /dev/null +++ b/.changeset/lucky-pans-thank.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": patch +--- + +Truncate GitHub PR message if it exceeds a size limit of 60k characters. From e351993abcdc7428fe6dbfcda00e4dea244863f4 Mon Sep 17 00:00:00 2001 From: Nicola Molinari Date: Mon, 7 Mar 2022 21:24:46 +0100 Subject: [PATCH 4/7] refactor: changeset message to omit some info if message exceeds size limit --- .changeset/lucky-pans-thank.md | 2 +- src/__snapshots__/run.test.ts.snap | 45 +++++++- src/run.test.ts | 110 +++++++++++++++++++ src/run.ts | 164 ++++++++++++++++++----------- 4 files changed, 259 insertions(+), 62 deletions(-) diff --git a/.changeset/lucky-pans-thank.md b/.changeset/lucky-pans-thank.md index ee9696f2..d7cd2b9d 100644 --- a/.changeset/lucky-pans-thank.md +++ b/.changeset/lucky-pans-thank.md @@ -2,4 +2,4 @@ "@changesets/action": patch --- -Truncate GitHub PR message if it exceeds a size limit of 60k characters. +Automatically adjust GitHub PR message if it exceeds a size limit of 60k characters by omitting some of the changelog information. diff --git a/src/__snapshots__/run.test.ts.snap b/src/__snapshots__/run.test.ts.snap index 9ce562c1..c20dfbf3 100644 --- a/src/__snapshots__/run.test.ts.snap +++ b/src/__snapshots__/run.test.ts.snap @@ -6,6 +6,7 @@ Array [ "base": "some-branch", "body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated. + # Releases ## simple-project-pkg-a@1.1.0 @@ -18,7 +19,7 @@ Array [ - Updated dependencies - simple-project-pkg-b@1.1.0 - ## simple-project-pkg-b@1.1.0 +## simple-project-pkg-b@1.1.0 ### Minor Changes @@ -32,12 +33,53 @@ Array [ ] `; +exports[`version does not include any release information if message exceeds size limit 1`] = ` +Array [ + Object { + "base": "some-branch", + "body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated. + + +# Releases + +> All release information have been omitted from this message, as the content exceeds the size limit.", + "head": "changeset-release/some-branch", + "owner": "changesets", + "repo": "action", + "title": "Version Packages", + }, +] +`; + +exports[`version does not include changelog entry if message exceeds size limit 1`] = ` +Array [ + Object { + "base": "some-branch", + "body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated. + + +# Releases + +> The changelog information of each package has been omitted from this message, as the content exceeds the size limit. + +## simple-project-pkg-a@1.1.0 + +", + "head": "changeset-release/some-branch", + "owner": "changesets", + "repo": "action", + "title": "Version Packages", + }, +] +`; + exports[`version doesn't include ignored package that got a dependency update in the PR body 1`] = ` Array [ Object { "base": "some-branch", "body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated. + # Releases ## ignored-package-pkg-b@1.1.0 @@ -59,6 +101,7 @@ Array [ "base": "some-branch", "body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated. + # Releases ## simple-project-pkg-a@1.1.0 diff --git a/src/run.test.ts b/src/run.test.ts index f156402e..e7c4a747 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -157,4 +157,114 @@ describe("version", () => { expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); }); + + it("does not include changelog entry if message exceeds size limit", async () => { + let cwd = f.copy("simple-project"); + linkNodeModules(cwd); + + mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( + () => ({ data: { items: [] } }) + ); + + await writeChangesets( + [ + { + releases: [ + { + name: "simple-project-pkg-a", + type: "minor", + }, + ], + summary: `# Non manus superum + +## Nec cornibus aequa numinis multo onerosior adde + +Lorem markdownum undas consumpserat malas, nec est lupus; memorant gentisque ab +limine auctore. Eatque et promptu deficit, quam videtur aequa est **faciat**, +locus. Potentia deus habebat pia quam qui coniuge frater, tibi habent fertque +viribus. E et cognoscere arcus, lacus aut sic pro crimina fuit tum **auxilium** +dictis, qua, in. + +In modo. Nomen illa membra. + +> Corpora gratissima parens montibus tum coeperat qua remulus caelum Helenamque? +> Non poenae modulatur Amathunta in concita superi, procerum pariter rapto cornu +> munera. Perrhaebum parvo manus contingere, morari, spes per totiens ut +> dividite proculcat facit, visa. + +Adspicit sequitur diffamatamque superi Phoebo qua quin lammina utque: per? Exit +decus aut hac inpia, seducta mirantia extremo. Vidi pedes vetus. Saturnius +fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. +`, + }, + ], + cwd + ); + + await runVersion({ + githubToken: "@@GITHUB_TOKEN", + cwd, + maxCharactersPerMessage: 1000, + }); + + expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); + expect(mockedGithubMethods.pulls.create.mock.calls[0][0].body).toMatch( + /The changelog information of each package has been omitted from this message/ + ); + }); + + it("does not include any release information if message exceeds size limit", async () => { + let cwd = f.copy("simple-project"); + linkNodeModules(cwd); + + mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( + () => ({ data: { items: [] } }) + ); + + await writeChangesets( + [ + { + releases: [ + { + name: "simple-project-pkg-a", + type: "minor", + }, + ], + summary: `# Non manus superum + +## Nec cornibus aequa numinis multo onerosior adde + +Lorem markdownum undas consumpserat malas, nec est lupus; memorant gentisque ab +limine auctore. Eatque et promptu deficit, quam videtur aequa est **faciat**, +locus. Potentia deus habebat pia quam qui coniuge frater, tibi habent fertque +viribus. E et cognoscere arcus, lacus aut sic pro crimina fuit tum **auxilium** +dictis, qua, in. + +In modo. Nomen illa membra. + +> Corpora gratissima parens montibus tum coeperat qua remulus caelum Helenamque? +> Non poenae modulatur Amathunta in concita superi, procerum pariter rapto cornu +> munera. Perrhaebum parvo manus contingere, morari, spes per totiens ut +> dividite proculcat facit, visa. + +Adspicit sequitur diffamatamque superi Phoebo qua quin lammina utque: per? Exit +decus aut hac inpia, seducta mirantia extremo. Vidi pedes vetus. Saturnius +fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. +`, + }, + ], + cwd + ); + + await runVersion({ + githubToken: "@@GITHUB_TOKEN", + cwd, + maxCharactersPerMessage: 500, + }); + + expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); + expect(mockedGithubMethods.pulls.create.mock.calls[0][0].body).toMatch( + /All release information have been omitted from this message, as the content exceeds the size limit/ + ); + }); }); diff --git a/src/run.ts b/src/run.ts index c03ce39b..35cba265 100644 --- a/src/run.ts +++ b/src/run.ts @@ -4,6 +4,7 @@ import fs from "fs-extra"; import { getPackages, Package } from "@manypkg/get-packages"; import path from "path"; import * as semver from "semver"; +import { PreState } from "@changesets/types"; import { getChangelogEntry, execWithOutput, @@ -174,6 +175,75 @@ const requireChangesetsCliPkgJson = (cwd: string) => { } }; +type GetMessageOptions = { + hasPublishScript: boolean; + branch: string; + changedPackagesInfo: { + highestLevel: number; + private: boolean; + content: string; + header: string; + }[]; + maxCharactersPerMessage: number; + preState?: PreState; +}; + +export async function getChangesetsMessage({ + hasPublishScript, + preState, + changedPackagesInfo, + maxCharactersPerMessage, + branch, +}: GetMessageOptions) { + let messageHeader = `This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${ + hasPublishScript + ? `the packages will be published to npm automatically` + : `publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing)` + }. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${branch}, this PR will be updated. +`; + let messagePrestate = !!preState + ? `⚠️⚠️⚠️⚠️⚠️⚠️ + +\`${branch}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${branch}\`. + +⚠️⚠️⚠️⚠️⚠️⚠️ +` + : ""; + let messageReleases = `# Releases`; + + let fullMessage = [ + messageHeader, + messagePrestate, + messageReleases, + ...changedPackagesInfo.map((info) => `${info.header}\n\n${info.content}`), + ].join("\n"); + + // Check that the message does not exceed the size limit. + // If not, omit the changelog entries of each package. + if (fullMessage.length > maxCharactersPerMessage) { + fullMessage = [ + messageHeader, + messagePrestate, + messageReleases, + `\n> The changelog information of each package has been omitted from this message, as the content exceeds the size limit.\n`, + ...changedPackagesInfo.map((info) => `${info.header}\n\n`), + ].join("\n"); + } + + // Check (again) that the message is within the size limit. + // If not, omit all release content this time. + if (fullMessage.length > maxCharactersPerMessage) { + fullMessage = [ + messageHeader, + messagePrestate, + messageReleases, + `\n> All release information have been omitted from this message, as the content exceeds the size limit.`, + ].join("\n"); + } + + return fullMessage; +} + type VersionOptions = { script?: string; githubToken: string; @@ -181,6 +251,7 @@ type VersionOptions = { prTitle?: string; commitMessage?: string; hasPublishScript?: boolean; + maxCharactersPerMessage?: number; }; type RunVersionResult = { @@ -194,6 +265,7 @@ export async function runVersion({ prTitle = "Version Packages", commitMessage = "Version Packages", hasPublishScript = false, + maxCharactersPerMessage = MAX_CHARACTERS_PER_MESSAGE, }: VersionOptions): Promise { let repo = `${github.context.repo.owner}/${github.context.repo.repo}`; let branch = github.context.ref.replace("refs/heads/", ""); @@ -224,55 +296,29 @@ export async function runVersion({ q: searchQuery, }); let changedPackages = await getChangedPackages(cwd, versionsByDirectory); + let changedPackagesInfo = ( + await Promise.all( + changedPackages.map(async (pkg) => { + let changelogContents = await fs.readFile( + path.join(pkg.dir, "CHANGELOG.md"), + "utf8" + ); - let prBodyPromise = (async () => { - return ( - `This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${ - hasPublishScript - ? `the packages will be published to npm automatically` - : `publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing)` - }. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${branch}, this PR will be updated. -${ - !!preState - ? ` -⚠️⚠️⚠️⚠️⚠️⚠️ - -\`${branch}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${branch}\`. - -⚠️⚠️⚠️⚠️⚠️⚠️ -` - : "" -} -# Releases -` + - ( - await Promise.all( - changedPackages.map(async (pkg) => { - let changelogContents = await fs.readFile( - path.join(pkg.dir, "CHANGELOG.md"), - "utf8" - ); - - let entry = getChangelogEntry( - changelogContents, - pkg.packageJson.version - ); - return { - highestLevel: entry.highestLevel, - private: !!pkg.packageJson.private, - content: - `## ${pkg.packageJson.name}@${pkg.packageJson.version}\n\n` + - entry.content, - }; - }) - ) - ) - .filter((x) => x) - .sort(sortTheThings) - .map((x) => x.content) - .join("\n ") - ); - })(); + let entry = getChangelogEntry( + changelogContents, + pkg.packageJson.version + ); + return { + highestLevel: entry.highestLevel, + private: !!pkg.packageJson.private, + content: entry.content, + header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`, + }; + }) + ) + ) + .filter((x) => x) + .sort(sortTheThings); const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`; @@ -289,23 +335,21 @@ ${ let searchResult = await searchResultPromise; console.log(JSON.stringify(searchResult.data, null, 2)); - let messageBody = await prBodyPromise; - if (messageBody.length > MAX_CHARACTERS_PER_MESSAGE) { - console.log( - `message body too long, truncating at ${MAX_CHARACTERS_PER_MESSAGE} charachters.` - ); - messageBody = [ - messageBody.substring(0, MAX_CHARACTERS_PER_MESSAGE), - "[Too long, message truncated]", - ].join("\n\n"); - } + let prBody = await getChangesetsMessage({ + hasPublishScript, + preState, + branch, + changedPackagesInfo, + maxCharactersPerMessage, + }); + if (searchResult.data.items.length === 0) { console.log("creating pull request"); const { data: newPullRequest } = await octokit.pulls.create({ base: branch, head: versionBranch, title: finalPrTitle, - body: messageBody, + body: prBody, ...github.context.repo, }); @@ -319,7 +363,7 @@ ${ await octokit.pulls.update({ pull_number: pullRequest.number, title: finalPrTitle, - body: messageBody, + body: prBody, ...github.context.repo, }); From 622015496c70f64e298d7bcbd4e2fd284e6c0c4a Mon Sep 17 00:00:00 2001 From: Nicola Molinari Date: Wed, 20 Apr 2022 10:36:02 +0200 Subject: [PATCH 5/7] refactor: minor adjustments based on feedback --- src/run.ts | 68 ++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/src/run.ts b/src/run.ts index 35cba265..a6fd907c 100644 --- a/src/run.ts +++ b/src/run.ts @@ -166,6 +166,7 @@ const requireChangesetsCliPkgJson = (cwd: string) => { try { return require(resolveFrom(cwd, "@changesets/cli/package.json")); } catch (err) { + // @ts-ignore if (err && err.code === "MODULE_NOT_FOUND") { throw new Error( `Have you forgotten to install \`@changesets/cli\` in "${cwd}"?` @@ -184,15 +185,15 @@ type GetMessageOptions = { content: string; header: string; }[]; - maxCharactersPerMessage: number; + prBodyMaxCharacters: number; preState?: PreState; }; -export async function getChangesetsMessage({ +export async function getVersionPrBody({ hasPublishScript, preState, changedPackagesInfo, - maxCharactersPerMessage, + prBodyMaxCharacters, branch, }: GetMessageOptions) { let messageHeader = `This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${ @@ -209,22 +210,22 @@ export async function getChangesetsMessage({ ⚠️⚠️⚠️⚠️⚠️⚠️ ` : ""; - let messageReleases = `# Releases`; + let messageReleasesHeading = `# Releases`; let fullMessage = [ messageHeader, messagePrestate, - messageReleases, + messageReleasesHeading, ...changedPackagesInfo.map((info) => `${info.header}\n\n${info.content}`), ].join("\n"); // Check that the message does not exceed the size limit. // If not, omit the changelog entries of each package. - if (fullMessage.length > maxCharactersPerMessage) { + if (fullMessage.length > prBodyMaxCharacters) { fullMessage = [ messageHeader, messagePrestate, - messageReleases, + messageReleasesHeading, `\n> The changelog information of each package has been omitted from this message, as the content exceeds the size limit.\n`, ...changedPackagesInfo.map((info) => `${info.header}\n\n`), ].join("\n"); @@ -232,11 +233,11 @@ export async function getChangesetsMessage({ // Check (again) that the message is within the size limit. // If not, omit all release content this time. - if (fullMessage.length > maxCharactersPerMessage) { + if (fullMessage.length > prBodyMaxCharacters) { fullMessage = [ messageHeader, messagePrestate, - messageReleases, + messageReleasesHeading, `\n> All release information have been omitted from this message, as the content exceeds the size limit.`, ].join("\n"); } @@ -251,7 +252,7 @@ type VersionOptions = { prTitle?: string; commitMessage?: string; hasPublishScript?: boolean; - maxCharactersPerMessage?: number; + prBodyMaxCharacters?: number; }; type RunVersionResult = { @@ -265,7 +266,7 @@ export async function runVersion({ prTitle = "Version Packages", commitMessage = "Version Packages", hasPublishScript = false, - maxCharactersPerMessage = MAX_CHARACTERS_PER_MESSAGE, + prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE, }: VersionOptions): Promise { let repo = `${github.context.repo.owner}/${github.context.repo.repo}`; let branch = github.context.ref.replace("refs/heads/", ""); @@ -296,29 +297,22 @@ export async function runVersion({ q: searchQuery, }); let changedPackages = await getChangedPackages(cwd, versionsByDirectory); - let changedPackagesInfo = ( - await Promise.all( - changedPackages.map(async (pkg) => { - let changelogContents = await fs.readFile( - path.join(pkg.dir, "CHANGELOG.md"), - "utf8" - ); + let changedPackagesInfoPromises = Promise.all( + changedPackages.map(async (pkg) => { + let changelogContents = await fs.readFile( + path.join(pkg.dir, "CHANGELOG.md"), + "utf8" + ); - let entry = getChangelogEntry( - changelogContents, - pkg.packageJson.version - ); - return { - highestLevel: entry.highestLevel, - private: !!pkg.packageJson.private, - content: entry.content, - header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`, - }; - }) - ) - ) - .filter((x) => x) - .sort(sortTheThings); + let entry = getChangelogEntry(changelogContents, pkg.packageJson.version); + return { + highestLevel: entry.highestLevel, + private: !!pkg.packageJson.private, + content: entry.content, + header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`, + }; + }) + ); const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`; @@ -335,12 +329,16 @@ export async function runVersion({ let searchResult = await searchResultPromise; console.log(JSON.stringify(searchResult.data, null, 2)); - let prBody = await getChangesetsMessage({ + const changedPackagesInfo = (await changedPackagesInfoPromises) + .filter((x) => x) + .sort(sortTheThings); + + let prBody = await getVersionPrBody({ hasPublishScript, preState, branch, changedPackagesInfo, - maxCharactersPerMessage, + prBodyMaxCharacters, }); if (searchResult.data.items.length === 0) { From b083449bbe939770cb482b8b3ced7d55697a2eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 10 May 2022 10:36:10 +0200 Subject: [PATCH 6/7] Apply nits from code review --- src/run.test.ts | 4 ++-- src/run.ts | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/run.test.ts b/src/run.test.ts index e7c4a747..c3d9dd5b 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -158,7 +158,7 @@ describe("version", () => { expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); }); - it("does not include changelog entry if message exceeds size limit", async () => { + it("does not include changelog entries if full message exceeds size limit", async () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); @@ -213,7 +213,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. ); }); - it("does not include any release information if message exceeds size limit", async () => { + it("does not include any release information if a message with simplified release info exceeds size limit", async () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); diff --git a/src/run.ts b/src/run.ts index a6fd907c..21db1181 100644 --- a/src/run.ts +++ b/src/run.ts @@ -165,8 +165,7 @@ export async function runPublish({ const requireChangesetsCliPkgJson = (cwd: string) => { try { return require(resolveFrom(cwd, "@changesets/cli/package.json")); - } catch (err) { - // @ts-ignore + } catch (err: any) { if (err && err.code === "MODULE_NOT_FOUND") { throw new Error( `Have you forgotten to install \`@changesets/cli\` in "${cwd}"?` @@ -357,7 +356,7 @@ export async function runVersion({ } else { const [pullRequest] = searchResult.data.items; - console.log("pull request found, updating"); + console.log(`updating found pull request #${pullRequest.number}`); await octokit.pulls.update({ pull_number: pullRequest.number, title: finalPrTitle, From 8d5da5c4ccde3421864a814af970313cc2290714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 10 May 2022 10:56:07 +0200 Subject: [PATCH 7/7] Fixed tests --- src/__snapshots__/run.test.ts.snap | 4 ++-- src/run.test.ts | 30 +++++++++++++++++++----------- src/run.ts | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/__snapshots__/run.test.ts.snap b/src/__snapshots__/run.test.ts.snap index c20dfbf3..f0367903 100644 --- a/src/__snapshots__/run.test.ts.snap +++ b/src/__snapshots__/run.test.ts.snap @@ -33,7 +33,7 @@ Array [ ] `; -exports[`version does not include any release information if message exceeds size limit 1`] = ` +exports[`version does not include any release information if a message with simplified release info exceeds size limit 1`] = ` Array [ Object { "base": "some-branch", @@ -51,7 +51,7 @@ Array [ ] `; -exports[`version does not include changelog entry if message exceeds size limit 1`] = ` +exports[`version does not include changelog entries if full message exceeds size limit 1`] = ` Array [ Object { "base": "some-branch", diff --git a/src/run.test.ts b/src/run.test.ts index c3d9dd5b..c3518510 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -57,9 +57,9 @@ describe("version", () => { () => ({ data: { items: [] } }) ); - mockedGithubMethods.pulls.create.mockImplementationOnce( - () => ({ data: { number: 123 } }) - ); + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); await writeChangesets( [ @@ -96,9 +96,9 @@ describe("version", () => { () => ({ data: { items: [] } }) ); - mockedGithubMethods.pulls.create.mockImplementationOnce( - () => ({ data: { number: 123 } }) - ); + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); await writeChangesets( [ @@ -131,9 +131,9 @@ describe("version", () => { () => ({ data: { items: [] } }) ); - mockedGithubMethods.pulls.create.mockImplementationOnce( - () => ({ data: { number: 123 } }) - ); + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); await writeChangesets( [ @@ -166,6 +166,10 @@ describe("version", () => { () => ({ data: { items: [] } }) ); + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); + await writeChangesets( [ { @@ -204,7 +208,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. await runVersion({ githubToken: "@@GITHUB_TOKEN", cwd, - maxCharactersPerMessage: 1000, + prBodyMaxCharacters: 1000, }); expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); @@ -221,6 +225,10 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. () => ({ data: { items: [] } }) ); + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); + await writeChangesets( [ { @@ -259,7 +267,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. await runVersion({ githubToken: "@@GITHUB_TOKEN", cwd, - maxCharactersPerMessage: 500, + prBodyMaxCharacters: 500, }); expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); diff --git a/src/run.ts b/src/run.ts index 21db1181..2612393f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -47,7 +47,7 @@ const createRelease = async ( prerelease: pkg.packageJson.version.includes("-"), ...github.context.repo, }); - } catch (err) { + } catch (err: any) { // if we can't find a changelog, the user has probably disabled changelogs if (err.code !== "ENOENT") { throw err;