diff --git a/.github/workflows/pull-request-auto-merge.yml b/.github/workflows/pull-request-auto-merge.yml index c420de94ca..3095aa60c7 100644 --- a/.github/workflows/pull-request-auto-merge.yml +++ b/.github/workflows/pull-request-auto-merge.yml @@ -7,9 +7,10 @@ name: Pull request auto-merge # checks again on the merge-group commit. # # A pull request is held (auto-merge off, and out of the queue) while it is a -# draft, carries the `blocked` label, or its description states a merge order or -# hold. Keep a pull request that must merge after another one in draft until its -# pair has landed. +# draft or carries the `blocked` label. The description is not read: only GitHub +# state holds a pull request, so an edit can neither hold nor release one. Keep +# a pull request that must merge after another one in draft, or label it +# `blocked`, until its pair has landed. # # Only pull requests whose branch lives in this repository are handled: only # people with write access can push one. Fork pull requests are never armed and @@ -23,7 +24,7 @@ name: Pull request auto-merge on: pull_request_target: - types: [opened, reopened, ready_for_review, converted_to_draft, labeled, unlabeled, edited] + types: [opened, reopened, ready_for_review, converted_to_draft, labeled, unlabeled] permissions: {} @@ -73,25 +74,12 @@ jobs: # Read the pull request now, not from the event: a later edit or label # may already have changed it. gh pr view "$PR" --repo "$GITHUB_REPOSITORY" \ - --json state,isDraft,baseRefName,labels,body,autoMergeRequest > "$RUNNER_TEMP/pr.json" + --json state,isDraft,baseRefName,labels,autoMergeRequest > "$RUNNER_TEMP/pr.json" state="$(jq -r .state "$RUNNER_TEMP/pr.json")" base="$(jq -r .baseRefName "$RUNNER_TEMP/pr.json")" draft="$(jq -r .isDraft "$RUNNER_TEMP/pr.json")" blocked="$(jq -r '[.labels[].name] | index("blocked") != null' "$RUNNER_TEMP/pr.json")" armed="$(jq -r '.autoMergeRequest != null' "$RUNNER_TEMP/pr.json")" - # A hold is an explicit instruction, or a merge order or dependency that - # names another pull request ("depends on #123", "merges after - # veryfront-api#45", a /pull/ link). Ordinary prose such as "depends on - # zod" or "waits for the worker" is not one. - ref='(pr |pull request )?(https://github\.com/)?(([a-z0-9_.-]+/)?[a-z0-9_.-]+)?(#|/pull/)[0-9]+' - hold="(do not|don.t) (merge|queue)|merge order|required pair|on hold|hold (until|off|for now)|^[[:space:]]*hold[.!:]?[[:space:]]*$" - dependency="(merged?|merges|lands?|landed) (after|before|with)|blocked (by|on)|depends on|dependent on|wait(s|ing)? (for|on|until)" - held_by_body=false - if jq -r '.body // ""' "$RUNNER_TEMP/pr.json" \ - | grep -qiE "($hold)|($dependency) $ref"; then - held_by_body=true - fi - if [ "$state" != OPEN ] || [ "$base" != main ]; then echo "Pull request #$PR is $state against $base; nothing to do." exit 0 @@ -100,7 +88,6 @@ jobs: reason="" [ "$draft" = true ] && reason="it is a draft" [ "$blocked" = true ] && reason="it has the blocked label" - [ "$held_by_body" = true ] && reason="its description states a merge order or hold" if [ -n "$reason" ]; then if [ "$armed" = true ]; then diff --git a/AGENTS.md b/AGENTS.md index 2831effcb2..f71123ccac 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -278,10 +278,10 @@ the required checks on the generated `merge_group` commit. pull request checks pass. Do not mutate the pull request branch while it is queued. - A ready pull request from a branch in this repository, opened by a person, arms auto-merge by itself (`pull-request-auto-merge.yml`): it joins the queue once the required checks, the automated review - and thread resolution pass. To hold one, keep it draft, add the `blocked` label, or state the hold - in its description: "on hold", "do not merge", or a merge order naming the other pull request - ("merges after #123", "depends on owner/repo#45"). Fork and bot pull requests are never armed; - queue them by hand. + and thread resolution pass. To hold one, keep it draft or add the `blocked` label; the description + is never read, so a note there holds nothing. A pull request that must merge after another stays + draft or `blocked` until its pair has landed. Fork and bot pull requests are never armed; queue + them by hand. ## Architecture map diff --git a/tests/integration/ci/pull-request-auto-merge-workflow.test.ts b/tests/integration/ci/pull-request-auto-merge-workflow.test.ts index be4bada296..3d4f0a6376 100644 --- a/tests/integration/ci/pull-request-auto-merge-workflow.test.ts +++ b/tests/integration/ci/pull-request-auto-merge-workflow.test.ts @@ -29,7 +29,7 @@ interface PullRequestFixture { state?: string; isDraft?: boolean; baseRefName?: string; - labels?: string[]; + labels?: readonly string[]; body?: string; armed?: boolean; inMergeQueue?: boolean; @@ -172,18 +172,7 @@ describe("pull request auto-merge workflow", () => { const [reason, pr] of [ ["a draft", { isDraft: true }], ["the blocked label", { labels: ["blocked"] }], - ["a merge order in the description", { body: "Merges after #123." }], - ["a hold in the description", { body: "Please hold until the release." }], - ["a bare hold line in the description", { body: "Adds a flag.\n\nHold.\n" }], - ["an on-hold note in the description", { body: "On hold for the launch." }], - ["a do-not-merge note in the description", { body: "Do not merge yet." }], - ["a cross-repository dependency", { body: "Depends on veryfront/veryfront-api#8005." }], - ["a dependency on a sibling repository", { body: "Merges after veryfront-api#8005." }], - [ - "a dependency given as a link", - { body: "Blocked by https://github.com/veryfront/veryfront-api/pull/8005" }, - ], - ["a wait on a pull request", { body: "Waits for PR #42 to land." }], + ["the blocked label among others", { labels: ["ci", "blocked"] }], ] as const ) { it(`holds and dequeues a pull request with ${reason}`, async () => { @@ -194,21 +183,28 @@ describe("pull request auto-merge workflow", () => { }); } - for ( - const body of [ - "This component depends on zod for parsing.", - "The adapter waits for the worker before it replies.", - "Holds: drafts stay out of the queue.", - "Hold the lock while the cache refreshes.", - "Fixes #123 and lands the retry after the timeout change.", - ] - ) { - it(`arms a pull request whose description only says: ${body}`, async () => { - const outcome = await runScript({ pr: { body } }); - assertEquals(outcome.code, 0); - assertEquals(merges(outcome.calls), [`pr merge 7 --repo ${REPOSITORY} --auto`]); - }); - } + it("neither holds nor releases on the description", async () => { + // Only GitHub state holds: an edit to the text can neither hold nor release. + const body = "Do not merge. Hold.\n\nDepends on #123 and merges after veryfront/other#9."; + const unarmed = await runScript({ pr: { body } }); + assertEquals(unarmed.code, 0); + assertEquals(merges(unarmed.calls), [`pr merge 7 --repo ${REPOSITORY} --auto`]); + const armed = await runScript({ pr: { body, armed: true, inMergeQueue: true } }); + assertEquals(armed.code, 0); + assertEquals(merges(armed.calls), []); + assertEquals(dequeues(armed.calls), []); + }); + + it("does not wake on or read the description", async () => { + const workflow = await loadWorkflow(); + const trigger = (workflow.on as YamlRecord).pull_request_target as YamlRecord; + assert(!(trigger.types as string[]).includes("edited"), "edits do not wake the workflow"); + const steps = await loadSteps(); + assert( + steps.every((step) => !/\bbody\b/.test(String(step.run ?? ""))), + "no step reads the body", + ); + }); it("holds a bot pull request too", async () => { const outcome = await runScript({