diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8b2cbce565..0ef49c3e082 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/flake.lock b/flake.lock index aad2340f531..60c6320088b 100644 --- a/flake.lock +++ b/flake.lock @@ -50,17 +50,17 @@ ] }, "locked": { - "lastModified": 1792395246, - "narHash": "sha256-SfVFE7TKuByeQRwhVbaVrvTV/lI41AYK9CYSfB+pIis=", + "lastModified": 1792480937, + "narHash": "sha256-arni7i+yH5ZnkvAN9UotvhMml5+fZyXcMHpiOvI3WFY=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "550547cefc67e01a6fd11a09e4096a3c844ca840", + "rev": "5424e1e6dda30b0626935d2a03a6526db4858d60", "type": "github" }, "original": { "owner": "oxalica", "repo": "rust-overlay", - "rev": "550547cefc67e01a6fd11a09e4096a3c844ca840", + "rev": "5424e1e6dda30b0626935d2a03a6526db4858d60", "type": "github" } } diff --git a/flake.nix b/flake.nix index c73d36d0ccc..41d76f47370 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; }; }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12768440c06..d5f6a2ca25e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -197,7 +197,7 @@ importers: version: 2.0.0-alpha.6 lefthook: specifier: ^2.1.2 - version: 2.2.1 + version: 2.2.2 typedoc: specifier: ^0.28.0 version: 0.28.20(typescript@6.0.3) @@ -1974,58 +1974,63 @@ packages: json-with-bigint@3.5.10: resolution: {integrity: sha512-Vcx+JVNEBts/xfcoCS69sKrOhOk/3TVlvlT+XzUOefVKnnrbYSCKpDCm10pohsJFtsJVYnwa/cXRZ4eElzaM6w==} - lefthook-darwin-arm64@2.2.1: - resolution: {integrity: sha512-SyuDBT5HqNQfi607vMHrYJu45bRN7JoIFdyxLjEPVe34UnZJCesmeYBODEYTyCfRZjPOaTbton4Padu+qvqfCQ==} + lefthook-android-arm64@2.2.2: + resolution: {integrity: sha512-wb9rQQFLX7u1dJLxvMrq9VUfMYi5kxM7tJQ6Y4mWEOwaU+SmIm2wjoT/nromKq27Y8fh2Qd7FgCD3G1wfW8CnQ==} + cpu: [arm64] + os: [android] + + lefthook-darwin-arm64@2.2.2: + resolution: {integrity: sha512-6V8D3bLnD/60Xhqn0o2EQD6H3Fe/U9LGkt4WF1O/3eBHbux+5ZJqoH0hfrC+Bi9Dy1Ve1AWxiAY7U2asYl8qVA==} cpu: [arm64] os: [darwin] - lefthook-darwin-x64@2.2.1: - resolution: {integrity: sha512-qkIdM89T3OxpLp9rssPSdRQ7QKkX0l07xWxxOaZfECn5iB2xVXSD9FQSjYUMNGXtJJWOGqdKqBngGTB/ShDZtQ==} + lefthook-darwin-x64@2.2.2: + resolution: {integrity: sha512-fH/kArZ9ZZ65wCFtvBMgGcq25qwQpkQ5jp93ba+8wpjgxxzjczYGluwHvM/NQDJWLOFXuKXW0yFs76SramQkyQ==} cpu: [x64] os: [darwin] - lefthook-freebsd-arm64@2.2.1: - resolution: {integrity: sha512-0jdr/9Q5cGuazrEVquv29AOD77aPc2jAmFU4EtqVVg3PhMJjAyt7bQeA9qdwHhaHhLnaeUZwMwo3IleVm+D4wg==} + lefthook-freebsd-arm64@2.2.2: + resolution: {integrity: sha512-MCRsU01ju989QQffOfS3gCeFfyVDXs5B/FzR65fmrNvqcxb98fldvfzzoAbnK2q6SBJlRT3QT1tNEMCxddCwlA==} cpu: [arm64] os: [freebsd] - lefthook-freebsd-x64@2.2.1: - resolution: {integrity: sha512-JFKyNZ9qQp9NsuFyAg/CJIBurIHX3AUayFXxuoDMATWAIhhlyK0YMtpWgEFIl1M2iGLBLQ3TiLoCCRnbwndNDg==} + lefthook-freebsd-x64@2.2.2: + resolution: {integrity: sha512-LkKuJU0S2oLimeoHwPTy1TLWB6GcN0t5lLxiXNlsBKUkr6R47QRcvPMZMoXmu3IetQtd+WliXMLE8qTwi2fqBg==} cpu: [x64] os: [freebsd] - lefthook-linux-arm64@2.2.1: - resolution: {integrity: sha512-na8Ezm7pK44+WsQqj9tES7v8VseM1MrNeNJhUnM8eINV22KYptWam8evfjZxY3NYxOTwn6f/Zpe/BBvcLKMaTQ==} + lefthook-linux-arm64@2.2.2: + resolution: {integrity: sha512-d+HFtS2DEKaOnD7vRU0tUz8pNgHwsUYmQ22+1dyXpOrXGyzNXR0AqX5KsIRF36JGhVvO5X5Anw5QYgR3mxVSuA==} cpu: [arm64] os: [linux] - lefthook-linux-x64@2.2.1: - resolution: {integrity: sha512-wl7CR5uNkOiZ38SkW4l9O6wf/Nllbkw90ZZonXRFkbgrnPjLMhZGUt9ucewsPwBQ/ckU1t08JuBHeOywB/CFow==} + lefthook-linux-x64@2.2.2: + resolution: {integrity: sha512-N/OlQyAhcU6RAXjrwFxLsh70sn96rBoi+XkuLJ8CVBkk9Ci3VDXQayDZTNz5B1xML8RwoMcV8Wblniy1xFOmSA==} cpu: [x64] os: [linux] - lefthook-openbsd-arm64@2.2.1: - resolution: {integrity: sha512-UFwL+AGSqkhQ15kuKl5FMRx/UqbcfcQbGFg5ggYzhT7qBOsTu3a9POXRxt3hsalBeMgkDWsv3IaPlj51YGpCAg==} + lefthook-openbsd-arm64@2.2.2: + resolution: {integrity: sha512-6G/gKXcpIwC+XcODg7ELZYP/hIrVIHQxhy2GoRdVyecmpGMFj+BZo3iqcUmeWusQMuL+UdNexbkrUaeJalIkNw==} cpu: [arm64] os: [openbsd] - lefthook-openbsd-x64@2.2.1: - resolution: {integrity: sha512-IMKEuxJLo91C1yjhJ42EadfXUb3ECMkvTKpSt17kwaiyZsvvZ8LGdrXwQZiLNJt2M5ECuTVCQUvDimM6mGraOw==} + lefthook-openbsd-x64@2.2.2: + resolution: {integrity: sha512-eMJGi3/tqKEqu7XCZlqwQWRtK5JlL/9diaqqgRlEdlRD7GxwzHZN21z6awbITum9emea3lALvXFe6V8odQLGOA==} cpu: [x64] os: [openbsd] - lefthook-windows-arm64@2.2.1: - resolution: {integrity: sha512-Pi8vOvObjg8HJDl8d96s7jsI6TN33klpqv6tXSXpoKEeoAwEh5Y9NawO6bzoOpLfAxf2SfMBcuaBzFQ5zE2gjA==} + lefthook-windows-arm64@2.2.2: + resolution: {integrity: sha512-4P1EaQb5xG1zhYD1RLJ6TEGdFkmHkB+Slqx6yRDPKuBDNxMiD0+kTAAdUY2E8xPuRR35xHpVPR+b3/HtzPrjQQ==} cpu: [arm64] os: [win32] - lefthook-windows-x64@2.2.1: - resolution: {integrity: sha512-7FtuPrc1XzxIFLAbzneOF1hr9r/vGi2lcMpX14QG9d/mnLhwu4EyNBh48JNEqsQqrOB9QKavsNqxVl1e8zcukA==} + lefthook-windows-x64@2.2.2: + resolution: {integrity: sha512-9Ck4zancQilBfXT3ZeRipm7Lcq4RQfxyMpy8SAVINw0t/BrbjsT25V46ZuziERcwdajnE4myfMzC33GoCBwr7g==} cpu: [x64] os: [win32] - lefthook@2.2.1: - resolution: {integrity: sha512-aKEwhQzGbLMkZu5vrFYKJzLvLVblWATYITmN7Ak4qRCDPCoFJhmeJZFuYf3nTXuqG9xTBE+J8xaAEPL2tpuWyw==} + lefthook@2.2.2: + resolution: {integrity: sha512-37fYHAhL12r1twaEV0PA5TwoIT491eTGGYjhhXxlYNMq3DSkiGZBQ++Jfk5maXj0vq52NRauLtMikBKtbNJs3Q==} hasBin: true lightningcss-android-arm64@1.33.0: @@ -3950,48 +3955,52 @@ snapshots: json-with-bigint@3.5.10: {} - lefthook-darwin-arm64@2.2.1: + lefthook-android-arm64@2.2.2: optional: true - lefthook-darwin-x64@2.2.1: + lefthook-darwin-arm64@2.2.2: optional: true - lefthook-freebsd-arm64@2.2.1: + lefthook-darwin-x64@2.2.2: optional: true - lefthook-freebsd-x64@2.2.1: + lefthook-freebsd-arm64@2.2.2: optional: true - lefthook-linux-arm64@2.2.1: + lefthook-freebsd-x64@2.2.2: optional: true - lefthook-linux-x64@2.2.1: + lefthook-linux-arm64@2.2.2: optional: true - lefthook-openbsd-arm64@2.2.1: + lefthook-linux-x64@2.2.2: optional: true - lefthook-openbsd-x64@2.2.1: + lefthook-openbsd-arm64@2.2.2: optional: true - lefthook-windows-arm64@2.2.1: + lefthook-openbsd-x64@2.2.2: optional: true - lefthook-windows-x64@2.2.1: + lefthook-windows-arm64@2.2.2: optional: true - lefthook@2.2.1: + lefthook-windows-x64@2.2.2: + optional: true + + lefthook@2.2.2: optionalDependencies: - lefthook-darwin-arm64: 2.2.1 - lefthook-darwin-x64: 2.2.1 - lefthook-freebsd-arm64: 2.2.1 - lefthook-freebsd-x64: 2.2.1 - lefthook-linux-arm64: 2.2.1 - lefthook-linux-x64: 2.2.1 - lefthook-openbsd-arm64: 2.2.1 - lefthook-openbsd-x64: 2.2.1 - lefthook-windows-arm64: 2.2.1 - lefthook-windows-x64: 2.2.1 + lefthook-android-arm64: 2.2.2 + lefthook-darwin-arm64: 2.2.2 + lefthook-darwin-x64: 2.2.2 + lefthook-freebsd-arm64: 2.2.2 + lefthook-freebsd-x64: 2.2.2 + lefthook-linux-arm64: 2.2.2 + lefthook-linux-x64: 2.2.2 + lefthook-openbsd-arm64: 2.2.2 + lefthook-openbsd-x64: 2.2.2 + lefthook-windows-arm64: 2.2.2 + lefthook-windows-x64: 2.2.2 lightningcss-android-arm64@1.33.0: optional: true @@ -4052,7 +4061,7 @@ snapshots: magic-string@0.30.21: dependencies: - '@jridgewell/sourcemap-codec': 1.5.5 + '@jridgewell/sourcemap-codec': 1.6.0 magic-string@1.4.3: dependencies: diff --git a/scripts/check-mergify-batch.mjs b/scripts/check-mergify-batch.mjs index 3cff129ee86..0bea49aafeb 100644 --- a/scripts/check-mergify-batch.mjs +++ b/scripts/check-mergify-batch.mjs @@ -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; } diff --git a/scripts/check-mergify-batch.test.mjs b/scripts/check-mergify-batch.test.mjs index ea937633bc0..bd0f701f5c6 100644 --- a/scripts/check-mergify-batch.test.mjs +++ b/scripts/check-mergify-batch.test.mjs @@ -2,6 +2,7 @@ import assert from "node:assert/strict"; import test from "node:test"; import { batchPullRequestNumbers, + stackDependency, validateBatch, } from "./check-mergify-batch.mjs"; @@ -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.