Skip to content
Closed
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
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ See [Mergify priorities](https://docs.mergify.com/merge-queue/priority/) and
[Mergify stacks](https://docs.mergify.com/merge-queue/stacks/) (`stack/*`
heads pushed by `mergify stack push --no-github-native`) use the `changes`
queue. A member above the bottom targets the branch below it and carries a
`Depends-On: #N` marker; the queue accepts it on that basis and lands the whole
`Depends-On: #N` or same-repository `Depends-On: https://github.com/OWNER/REPO/pull/N`
marker; the queue accepts it on that basis and lands the whole
chain on the stack root, bottom-up. Queueing the top member queues every member
below it. The batch validator resolves each member's root through the same
marker chain, so a stack branch without it is still refused.
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
};
rust-overlay = {
# Pin the revision explicitly so Renovate can group overlay and Rust updates.
url = "github:oxalica/rust-overlay/550547cefc67e01a6fd11a09e4096a3c844ca840";
url = "github:oxalica/rust-overlay/5424e1e6dda30b0626935d2a03a6526db4858d60";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand Down
99 changes: 54 additions & 45 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions scripts/check-mergify-batch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ export function batchPullRequestNumbers(metadata) {
// Mergify's queue lands stack members on the stack root, while each member
// targets the head branch of the member below it. Resolve that root through
// the `Depends-On:` chain, matching the queue's own stack recognition.
export function stackDependency(repository, body) {
const marker =
/^Depends-On: (?:#([1-9]\d*)|https:\/\/github\.com\/([^/\s]+\/[^/\s]+)\/pull\/([1-9]\d*))\s*$/m.exec(body ?? "");
if (
!marker ||
(marker[2] && marker[2].toLowerCase() !== repository.toLowerCase())
)
return null;
const number = Number(marker[1] ?? marker[3]);
return Number.isSafeInteger(number) ? number : null;
}

export async function stackRootRef(repository, pull, api = githubJson) {
for (let depth = 0; depth < 20; depth++) {
const ref = pull.base?.ref;
const below = /^Depends-On: #(\d+)\s*$/m.exec(pull.body ?? "");
const below = stackDependency(repository, pull.body);
if (!ref?.startsWith("stack/") || !below) return ref;
pull = await api(`/repos/${repository}/pulls/${below[1]}`);
pull = await api(`/repos/${repository}/pulls/${below}`);
if (pull.head?.ref !== ref || pull.head?.repo?.full_name !== repository)
return ref;
}
Expand Down
80 changes: 51 additions & 29 deletions scripts/check-mergify-batch.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
batchPullRequestNumbers,
stackDependency,
validateBatch,
} from "./check-mergify-batch.mjs";

Expand Down Expand Up @@ -103,37 +104,58 @@ test("rejects source PRs with invalid titles or another target branch", async ()
}
});

test("stack members are validated against the stack root", async () => {
const f = fixture();
const top = {
...f.source,
head: {
sha: sourceSha,
ref: "stack/u/feat/b--2",
repo: { full_name: "o/r" },
},
base: { ref: "stack/u/feat/a--1" },
body: "Adds b.\n\nDepends-On: #12\n",
};
const bottom = {
...f.source,
head: {
sha: sourceSha,
ref: "stack/u/feat/a--1",
repo: { full_name: "o/r" },
},
};
const api = async (path) => {
if (path === "/repos/o/r/pulls/12") return bottom;
if (path === "/repos/o/r/pulls/13") return top;
return f.api(path);
};
assert.deepEqual(
await validateBatch(f.input, api, f.commits, f.policy),
[12, 13],
);
test("stack dependencies accept local shorthand and same-repository GitHub URLs", () => {
for (const body of [
"Depends-On: #12",
"Text\n\nDepends-On: https://github.com/o/r/pull/12\r\n",
"Depends-On: https://github.com/O/R/pull/12",
])
assert.equal(stackDependency("o/r", body), 12);
for (const body of [
undefined,
"Depends-On: #0",
"Depends-On: #9007199254740992",
"Depends-On: https://github.com/other/r/pull/12",
"Depends-On: https://github.com/o/r/pull/12/extra",
"Depends-On: https://github.com.evil/o/r/pull/12",
"Depends-On: http://github.com/o/r/pull/12",
"Depends-On: #12 extra",
])
assert.equal(stackDependency("o/r", body), null);
});

for (const dependency of ["#12", "https://github.com/o/r/pull/12"])
test(`stack members with ${dependency} are validated against the stack root`, async () => {
const f = fixture();
const top = {
...f.source,
head: {
sha: sourceSha,
ref: "stack/u/feat/b--2",
repo: { full_name: "o/r" },
},
base: { ref: "stack/u/feat/a--1" },
body: `Adds b.\n\nDepends-On: ${dependency}\n`,
};
const bottom = {
...f.source,
head: {
sha: sourceSha,
ref: "stack/u/feat/a--1",
repo: { full_name: "o/r" },
},
};
const api = async (path) => {
if (path === "/repos/o/r/pulls/12") return bottom;
if (path === "/repos/o/r/pulls/13") return top;
return f.api(path);
};
assert.deepEqual(
await validateBatch(f.input, api, f.commits, f.policy),
[12, 13],
);
});

test("rejects stack-like PRs whose chain does not reach the batch base", async () => {
for (const [body, below] of [
// No marker: the queue keeps the literal stack branch as the target.
Expand Down
Loading