Skip to content
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
100 changes: 77 additions & 23 deletions .changeset/changelog-generator.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info";
import { getCommitInfo, getPullRequestInfo } from "@changesets/get-github-info";

/** @typedef {import("@changesets/types").ChangelogFunctions} ChangelogFunctions */
/** @import { ChangelogFunctions } from "@changesets/types" */
/** @import { CommitInfo, PullRequestInfo } from "@changesets/get-github-info" */

/**
* @typedef {object} Links
* @property {string | null} commit markdown link to the commit
* @property {string | null} pull markdown link to the pull request
* @property {string | null} user markdown link to the author
*/

/**
* @returns {{ GITHUB_SERVER_URL: string }} value
Expand All @@ -11,6 +19,44 @@ function readEnv() {
return { GITHUB_SERVER_URL };
}

// Retry GitHub API calls so a transient drop (e.g. GraphQL "Premature close") doesn't fail the release.
/**
* @template T
* @param {() => Promise<T>} fn operation to retry
* @returns {Promise<T>} result
*/
async function withRetry(fn) {
const maxAttempts = 5;
let lastError;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await fn();
} catch (err) {
lastError = err;
if (attempt === maxAttempts) break;
const delay = Math.min(1000 * 2 ** (attempt - 1), 8000);
await new Promise((resolve) => {
setTimeout(resolve, delay);
});
}
}
throw lastError;
}

/**
* Flattens a lookup result into the markdown links a changelog line is built
* from; a lookup that found nothing leaves every link `null`.
* @param {CommitInfo | PullRequestInfo | undefined} info lookup result
* @returns {Links} links
*/
function toLinks(info) {
return {
commit: info && info.commit ? info.commit.markdownLink : null,
pull: info && info.pull ? info.pull.markdownLink : null,
user: info && info.author ? info.author.markdownLink : null
};
}

/** @type {ChangelogFunctions} */
const changelogFunctions = {
getDependencyReleaseLine: async (
Expand All @@ -29,11 +75,13 @@ const changelogFunctions = {
await Promise.all(
changesets.map(async (cs) => {
if (cs.commit) {
const { links } = await getInfo({
repo: options.repo,
commit: cs.commit
});
return links.commit;
const info = await withRetry(() =>
getCommitInfo({
repo: options.repo,
commit: cs.commit
})
);
return toLinks(info).commit;
}
})
)
Expand Down Expand Up @@ -72,7 +120,7 @@ const changelogFunctions = {
commitFromSummary = commit;
return "";
})
.replaceAll(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
return "";
})
Expand All @@ -84,26 +132,28 @@ const changelogFunctions = {

const links = await (async () => {
if (prFromSummary !== undefined) {
let { links } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary
});
const info = await withRetry(() =>
getPullRequestInfo({
repo: options.repo,
pull: prFromSummary
})
);
const links = toLinks(info);
if (commitFromSummary) {
const shortCommitId = commitFromSummary.slice(0, 7);
links = {
...links,
commit: `[\`${shortCommitId}\`](${GITHUB_SERVER_URL}/${options.repo}/commit/${commitFromSummary})`
};
links.commit = `[\`${shortCommitId}\`](${GITHUB_SERVER_URL}/${options.repo}/commit/${commitFromSummary})`;
}
return links;
}
const commitToFetchFrom = commitFromSummary || changeset.commit;
if (commitToFetchFrom) {
const { links } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom
});
return links;
const info = await withRetry(() =>
getCommitInfo({
repo: options.repo,
commit: commitToFetchFrom
})
);
return toLinks(info);
}
return {
commit: null,
Expand All @@ -123,10 +173,14 @@ const changelogFunctions = {

let suffix = "";
if (links.pull || links.commit || users) {
suffix = `(${users ? `by ${users} ` : ""}in ${links.pull || links.commit})`;
suffix = `(${users ? `by ${users} ` : ""}in ${
links.pull || links.commit
})`;
}

return `\n\n- ${firstLine} ${suffix}\n${futureLines.map((l) => ` ${l}`).join("\n")}`;
return `\n\n- ${firstLine} ${suffix}\n${futureLines
.map((l) => ` ${l}`)
.join("\n")}`;
}
};

Expand Down
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
"$schema": "https://unpkg.com/@changesets/config@3.1.4/schema.json",
"changelog": ["./changelog-generator.mjs", { "repo": "webpack/tapable" }],
"fixed": [],
"linked": [],
Expand Down
5 changes: 5 additions & 0 deletions .changeset/typed-hook-map-interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tapable": patch
---

Declare `TypedHookMap` as an interface, as no such class is exported.
5 changes: 5 additions & 0 deletions .changeset/typed-interceptor-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tapable": patch
---

Type the `call` and `loop` interceptor arguments as the hook's own.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
id: changesets
uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2
with:
version: npm run version
publish: npm run release
commit: "chore(release): new release"
title: "chore(release): new release"
github-token: ${{ secrets.GITHUB_TOKEN }}
version-script: npm run version
publish-script: npm run release
commit-message: "chore(release): new release"
pr-title: "chore(release): new release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: "" # https://github.com/changesets/changesets/issues/1152#issuecomment-3190884868
8 changes: 0 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# tapable

## 2.3.4

### Patch Changes

- Declare `TypedHookMap` as an interface, as no such class is exported. (by [@alexander-akait](https://github.com/alexander-akait) in [#291](https://github.com/webpack/tapable/pull/291))

- Type the `call` and `loop` interceptor arguments as the hook's own. (by [@alexander-akait](https://github.com/alexander-akait) in [#288](https://github.com/webpack/tapable/pull/288))

## 2.3.3

### Patch Changes
Expand Down
Loading
Loading