Skip to content

refactor(repos): wait for and merge the onboard template PR with gh #7512

Done

Description

@dan-petty

Problem

Part of #7499. The template pull request of devops repos onboard polls its check runs and sends its own GraphQL enablePullRequestAutoMerge and mergePullRequest mutations (src/devops_cli/github/onboard/template_pr.py:31-55, :137-146, :312-377).

Change

  • Read or wait for the checks with gh pr checks <n> --json or --watch.
  • Merge with gh pr merge <n> --auto --squash --match-head-commit <sha>. GitHub merges only that head commit, after the required checks pass. Who may merge does not change.

Done when

  • The poll and the two mutations of template_pr.py are deleted.
  • A test proves the gh pr checks and gh pr merge arguments and the map of their answers to the row of the template pull request.

Existing tool considered

GitHub CLI (https://github.com/cli/cli), MIT, v2.106.0: gh pr merge --auto --squash --match-head-commit.

Source

Source: #7499

Alternatives check of 2026-11-28: not-applicable.
Class: refactor, no model call.
Tool: none found.

Proposed design

Problem statement

The template pull request of devops repos onboard polls its check runs through the REST API and sends its own GraphQL enablePullRequestAutoMerge and mergePullRequest mutations. This change deletes that poll and those mutations: the row waits and reads every check with gh pr checks, maps gh's answer to the row states that rows 9, 10 and 11 need, and merges the head that the checks ran on with gh pr merge --auto --squash --match-head-commit. The ready-for-review call, the head check and who may merge do not change. The route table, its read list, the spec of the row and the tests move with it.

Acceptance criteria

Requirement: Wait for the checks with gh

The template pull request row SHALL wait for the checks with gh pr checks <number> --repo <repo> --watch --interval 15 in a confirmed run.

Scenario: A confirmed run waits

  • WHEN A confirmed run fakes gh pr checks 42 --repo owner/name --watch --interval 15 and it exits 0.
  • THEN The test sees that command, and then the read gh pr checks 42 --repo owner/name --json name,state,bucket,workflow,link.

Requirement: Read every check, not only the required ones

The row SHALL read every check of the template pull request with gh pr checks <number> --repo <repo> --json name,state,bucket,workflow,link, with no --required flag.

Scenario: A non-required check fails

  • WHEN The fake gh pr checks --json lists Trivy with bucket fail, and no ruleset of the repository requires Trivy.
  • THEN Row 9 is failed and names Trivy, and the fake process sees no gh pr merge call.

Requirement: A pending check waits

The row SHALL map a check of bucket pending to the waiting state of row 9.

Scenario: A check is pending

  • WHEN The fake gh pr checks --json lists Tests & Coverage with bucket pending.
  • THEN Row 9 is waiting, names Tests & Coverage, and the fake process sees no gh pr merge call.

Requirement: A head with no check waits

The row SHALL map the no checks reported answer of gh pr checks to the waiting state of row 9.

Scenario: No check reported

  • WHEN The fake gh pr checks --json exits 1 with no checks reported on the 'ci/repository-template' branch.
  • THEN Row 9 is waiting, and the fake process sees no gh pr merge call.

Requirement: A watch that reaches its limit waits

The row SHALL give gh pr checks --watch the timeout _CHECKS_WAIT_SECONDS and SHALL map exit code 124 to the waiting state of row 9.

Scenario: The watch reaches the limit

  • WHEN The fake gh pr checks --watch answers exit code 124 with GitHub API command timed out after 900.0 seconds.
  • THEN Row 9 is waiting, and the fake process sees no gh pr merge call.

Requirement: Successful and skipped names reach row 10

The row SHALL record the names of state SUCCESS as successful_checks and the names of state SKIPPED as skipped_checks of the row context.

Scenario: A skipped check is not required

  • WHEN The fake gh pr checks --json lists K8s with state SKIPPED and Lint with state SUCCESS, and --confirm runs.
  • THEN The ruleset of row 10 requires Lint and not K8s.

Requirement: Merge with the head that the checks ran on

Row 11 SHALL merge the template pull request with gh pr merge <number> --repo <repo> --auto --squash --match-head-commit <sha> after the checks pass.

Scenario: The checks pass

  • WHEN Row 9 passed for head abc123 and a confirmed run reaches row 11.
  • THEN The test sees gh pr merge 42 --repo owner/name --auto --squash --match-head-commit abc123, and the fake GitHub sees no enablePullRequestAutoMerge or mergePullRequest mutation.

Requirement: A plan records the merge and sends it only with confirm

The row 11 merge SHALL go through the route pull-merge, which records RUN gh pr merge <number> in a plan and sends the command only with --confirm.

Scenario: A plan of a repository whose checks passed

  • WHEN --plan runs on a repository whose template pull request passed its checks.
  • THEN The recorded writes hold RUN gh pr merge 42, and the fake process sees no gh pr merge call.

Requirement: The poll and the GraphQL mutations leave the module

The module SHALL delete _read_checks, _wait_for_checks, _AUTO_MERGE_MUTATION, _MERGE_MUTATION, _MERGE_STATE_QUERY and _MERGEABLE_NOW.

Scenario: The legacy code is gone

  • WHEN A test imports the template pull request module.
  • THEN The module holds none of those names, and its source holds no enablePullRequestAutoMerge or mergePullRequest.

Requirement: The route table holds no removed mutation

The route table SHALL hold the pull-merge route of row 11 and SHALL hold no route that names enablePullRequestAutoMerge or mergePullRequest.

Scenario: The route table is read

  • WHEN A test reads ROUTES.
  • THEN No route names enablePullRequestAutoMerge or mergePullRequest, pull-merge matches RUN gh pr merge 42, and pull-ready still names markPullRequestReadyForReview.

Existing Tool Considered

GitHub CLI (gh), MIT, v2.106.0 (https://github.com/cli/cli, fetched 2026-11-28), which the repository already uses to read checks (src/devops_cli/github/check_verdict.py:327) and to merge the release pull request (.github/workflows/release-merge.yml:84). It covers the wait (gh pr checks --watch), the read (--json name,state,bucket,workflow,link) and the merge (gh pr merge --auto --squash --match-head-commit). It lacks the onboard row model: it returns a list of checks and an exit code, not a row state, and it records nothing in the --plan output, so the change adds the map to RowState and the pull-merge route.

Key questions

  • Which gh pr checks command should the template row use to wait and to read?: Wait with gh pr checks <n> --repo <repo> --watch --interval 15 in a confirmed run, then read the names and states with gh pr checks <n> --repo <repo> --json name,state,bucket,workflow,link through the existing read_pr_checks. The watch deletes the poll loop; the read gives row 10 the successful and skipped names. (best practice) [sources: src/devops_cli/github/check_verdict.py:327, src/devops_cli/github/check_verdict.py:333, openspec/changes/archive/2026-10-28-2443-pr-ready-monitor-verdict/proposal.md:46, src/devops_cli/github/onboard/template_pr.py:137]
    • Chosen: gh pr checks --watch --interval 15, then a --json read. The watch waits as the poll did and the read gives every name and state that rows 9 and 10 need.
    • Rejected: One gh pr checks --json read with no wait. The issue asks the row to wait with gh; a confirmed run would leave row 9 waiting and need another run.
    • Rejected: One gh pr checks --watch --json call. The repository uses the two flags apart and holds no source that shows them together; the read after the watch is one cheap call.
  • Should the row wait for all checks or only required checks?: Read every check, with no --required flag. The project decided this on 2026-11-28 for the same gh read (refactor(pr): read the readiness checks with gh pr checks #7508): --required exits 1 with no required checks reported both for a branch that requires no check and for required checks that have not started, and it drops a failed check that no ruleset requires. Row 9 fails a failed check today, row 10 needs the successful and skipped names, and AGENTS.md rule 5 forbids lowering that gate. (best practice) [sources: AGENTS.md:11, openspec/changes/archive/2026-11-28-7508-readiness-checks-gh/design.md:5, openspec/changes/archive/2026-11-28-7508-readiness-checks-gh/design.md:13, src/devops_cli/github/onboard/template_pr.py:43, src/devops_cli/github/onboard/settings_rows.py:683]
    • Chosen: Read every check with gh pr checks --json name,state,bucket. It keeps the gate that row 9 applies today, gives row 10 each successful and skipped name, and never fails a new repository before row 10 has written the ruleset.
    • Rejected: Read only the required checks with --required. gh answers a branch that requires no check, or whose required checks have not started, with exit 1 no required checks reported, so row 9 would fail before row 10 writes the ruleset; it also drops a failed check that no ruleset requires, which rule 5 of AGENTS.md forbids.
  • What does each gh pr checks answer mean for the row?: Use read_pr_checks, which maps the no checks reported answer (exit 1) and an empty list to the pending stand-in, and each listed bucket to a CheckBucket. The row then maps fail and cancel to failed, pending to waiting, and pass and skipping to passed; the names of state SUCCESS are the successful names and the names of state SKIPPED the skipped names. A read that fails or prints no list is failed with the reason. (best practice) [sources: src/devops_cli/github/check_verdict.py:31, src/devops_cli/github/check_verdict.py:111, src/devops_cli/github/check_verdict.py:340, tests/github/test_pr_check_verdict.py:274, src/devops_cli/github/onboard/template_pr.py:216]
    • Chosen: Judge the items of read_pr_checks. It already tells gh's no checks reported answer from a failed check and gives each bucket and state; devops pr ready and the merge readiness read the checks with it.
    • Rejected: Judge the exit code of gh pr checks alone. Exit 1 is both a failed check and no checks reported, so the row would fail a head whose checks have not started.
  • Which merge command should replace the GraphQL mutations?: Use gh pr merge <n> --repo <repo> --auto --squash --match-head-commit <sha>. GitHub then merges only that head commit, after the required checks pass, and merges at once when nothing is left to wait for, so the merge-state read and the choice of mergePullRequest go. (best practice) [sources: src/devops_cli/github/onboard/template_pr.py:46, src/devops_cli/github/onboard/template_pr.py:56, .github/workflows/release-merge.yml:84, openspec/specs/release-scheduled-merge/spec.md:16, RELEASE_CYCLE.md:46]
    • Chosen: gh pr merge --auto --squash --match-head-commit. It keeps the required-check gate and the head check in GitHub, and it merges at once when the checks already passed.
    • Rejected: gh pr merge --squash --match-head-commit without --auto. It merges at once even when GitHub still waits for a required check, so the row would no longer keep the gate in GitHub.
    • Rejected: Keep GraphQL enablePullRequestAutoMerge and mergePullRequest. The issue deletes both mutations.
  • How does the plan record the merge that gh sends?: Add the route pull-merge of row 11 with method RUN, path form gh pr merge {pull} and owner PERSON_LOGIN, and call it through writer.run, which records RUN gh pr merge <number> in a plan and sends the command only with --confirm. The ready mark stays on the pull-ready route. (best practice) [sources: src/devops_cli/github/onboard/routes.py:462, src/devops_cli/github/onboard/routes.py:332, src/devops_cli/github/onboard/routes.py:200, src/devops_cli/github/onboard/routes.py:282]
    • Chosen: A RUN route pull-merge that records gh pr merge <number>. It names the command that the row starts, and the plan and the route-ownership test see it as the write that it is.
    • Rejected: A route on PUT /repos/{repo}/pulls/{pull}/merge. gh pr merge --auto sends the GraphQL enablePullRequestAutoMerge mutation, not the REST merge endpoint, so the plan would name a request that the row does not send.
    • Rejected: Keep the GraphQL pull-auto-merge route. No row sends either mutation after the change.
  • Which other repository files must change when the poll and the two mutations leave the template row?: Change src/devops_cli/github/onboard/routes.py to replace the pull-auto-merge GraphQL route with pull-merge, and change the read list from the check-runs read of row 9 and the mergeStateStatus read of row 11 to the gh pr checks read of row 9. Change openspec/specs/repos-onboard/spec.md so the requirement and its CLEAN scenario say that row 11 marks the pull request ready and merges it with gh pr merge --auto --squash --match-head-commit, with no mergePullRequest. Change the tests at tests/github/onboard/test_onboard_rows.py and tests/github/onboard/test_onboard_routes.py. [sources: src/devops_cli/github/onboard/routes.py:282, src/devops_cli/github/onboard/routes.py:372, src/devops_cli/github/onboard/routes.py:376, openspec/specs/repos-onboard/spec.md:186, openspec/specs/repos-onboard/spec.md:191, tests/github/onboard/test_onboard_rows.py:118, tests/github/onboard/test_onboard_rows.py:552, tests/github/onboard/test_onboard_routes.py:47]
  • Which tests prove the gh arguments and the result map?: Extend tests/github/onboard/test_onboard_rows.py, whose onboard_github fixture already routes gh to the process fake: script the gh pr checks --watch and --json answers and the gh pr merge answer, assert each argv, the row states and the names that row 10 requires. Add the pull-merge case to the route test at tests/github/onboard/test_onboard_routes.py:47. [sources: tests/github/onboard/test_onboard_rows.py:535, tests/github/onboard/test_onboard_rows.py:552, tests/support/github_repository.py:886, tests/support/github_repository.py:901, tests/github/onboard/test_onboard_routes.py:47]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/refactor
    source/agent
    status/new
    value/medium
    effort/medium
    scope/repos
    on Nov 28, 2026
  2. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  5. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  6. added
    status/in-review
    and removed
    status/ready
    on Nov 29, 2026
  7. removed
    status/in-review
    on Nov 29, 2026
  8. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 22:09 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/repossource/agenttype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions