Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
54 changes: 37 additions & 17 deletions scripts/changeset-format.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,44 @@ test("the Changesets formatter produces readable Markdown without encoded metada
if (oldToken === undefined) delete process.env.GITHUB_TOKEN;
else process.env.GITHUB_TOKEN = oldToken;
});
t.mock.method(
globalThis,
"fetch",
async () =>
new Response(
JSON.stringify([
{
number: 10,
title: "Edited title without a category",
user: { login: "Alice" },
merged_at: "2026-01-01",
base: { ref: "main" },
},
]),
),
);
let pulls = [
{
number: 10,
title: "Edited title without a category",
user: { login: "Alice" },
merged_at: "2026-01-01",
base: { ref: "topic-branch" },
merge_commit_sha: commit,
},
];
t.mock.method(globalThis, "fetch", async () => new Response(JSON.stringify(pulls)));
const line = await formatter.getReleaseLine({ id: "example", summary: "Add a tool.", commit });
assert.match(
line,
/#### 🐛 Bug Fixes\n\n- Add a tool\. \[#10\]\(https:\/\/github\.com\/vercel\/eve\/pull\/10\)/u,
);
assert.match(line, /#### Contributors\n\n- \[@Alice\]\(https:\/\/github\.com\/Alice\)/u);
assert.doesNotMatch(line, /<!--/u);
git("commit", "--allow-empty", "-qm", "fix: Update a tool");
const fallbackCommit = git("rev-parse", "HEAD");
pulls = [{ number: 11, user: { login: "Bob" }, merged_at: "2026-01-01" }];
const fallback = await formatter.getReleaseLine({
id: "fallback",
summary: "Update a tool.",
commit: fallbackCommit,
});
assert.match(fallback, /- Update a tool\. \[#11\]/u);
git("commit", "--allow-empty", "-qm", "fix: Repair a tool");
const ambiguousCommit = git("rev-parse", "HEAD");
pulls.push({ number: 12, user: { login: "Carol" }, merged_at: "2026-01-01" });
await assert.rejects(
formatter.getReleaseLine({
id: "ambiguous",
summary: "Repair a tool.",
commit: ambiguousCommit,
}),
/expected one merged pull request.*found 2/u,
);
});

test("version-packages assembles changesets across bump types and preserves old releases", async (t) => {
Expand Down Expand Up @@ -210,7 +225,12 @@ test("version-packages assembles changesets across bump types and preserves old
git("commit", "-qm", "Legacy change");
await write(
"mock-github.mjs",
`globalThis.fetch = async (url) => new Response(JSON.stringify([{number: url.includes(${JSON.stringify(first)}) ? 10 : url.includes(${JSON.stringify(second)}) ? 11 : 12, title: "Edited title", user: {login: "Author"}, merged_at: "2026-01-01", base: {ref: "main"}}]), {status: 200});`,
`globalThis.fetch = async (url) => {
const commit = url.split("/").at(-2);
const pull = {number: commit === ${JSON.stringify(first)} ? 10 : commit === ${JSON.stringify(second)} ? 11 : 12, title: "Edited title", user: {login: "Author"}, merged_at: "2026-01-01", base: {ref: commit === ${JSON.stringify(second)} ? "topic-branch" : "main"}, merge_commit_sha: commit};
const other = {number: 99, user: {login: "Other"}, merged_at: "2026-01-02", base: {ref: "main"}, merge_commit_sha: "another-commit"};
return new Response(JSON.stringify(commit === ${JSON.stringify(second)} ? [other, pull] : [pull]), {status: 200});
};`,
);
assert.throws(() =>
execFileSync(process.execPath, ["scripts/check-release-pr-title.mjs"], {
Expand Down
6 changes: 3 additions & 3 deletions scripts/changeset-github.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export async function pullRequestFor(commit, id) {
throw new Error(
`GitHub pull request lookup for changeset ${id} failed: HTTP ${response.status}.`,
);
const pulls = (await response.json()).filter(
(pull) => pull.merged_at && pull.base?.ref === "main",
);
const merged = (await response.json()).filter((pull) => pull.merged_at);
const matches = merged.filter((pull) => pull.merge_commit_sha === commit);
const pulls = matches.length ? matches : merged;
Comment thread
chadhietala marked this conversation as resolved.
Resolved
if (pulls.length !== 1)
throw new Error(
`Changeset ${id}: expected one merged pull request for commit ${commit}, found ${pulls.length}.`,
Expand Down
Loading