GitHub App
MergeSpan requires a GitHub App installed on the target repository. This page documents the exact permissions, event subscriptions, webhook contract, and secrets.
Permissions
| Permission | Level | Required | Purpose |
|---|---|---|---|
| Metadata | Read | yes | Mandatory; every App has it. |
| Contents | Read & Write | yes | Create candidate branch/commit; squash merge. |
| Pull requests | Read & Write | yes | Read PR state; merge. |
| Issues | Read & Write | yes | queue / urgent labels and PR comments. |
| Checks | Read & Write | yes | Create/read the mergespan check run on the PR head. |
| Actions | Read & Write | yes | Cancel candidate workflow runs. |
| Workflows | Not required | no | Direct workflow writes were not tested in v0.1; the App does not request this. |
| Administration | No | — | Never requested. |
| Members | No | — | Never requested. |
| Organization | No | — | Never requested. |
These permissions map exactly to the GitHub API endpoints the runtime calls (see crates/github/src/endpoints.rs and queue_api.rs):
GET /repos/{owner}/{repo}/pulls/{number}— pull request details (Pull requests: read).GET /repos/{owner}/{repo}/pulls— list open PRs on base (Pull requests: read).PUT /repos/{owner}/{repo}/pulls/{number}/merge— squash merge (Pull requests: write).GET /repos/{owner}/{repo}/git/refs/heads/...— branch heads (Contents: read).POST /repos/{owner}/{repo}/git/refs— create candidate branch (Contents: write).POST /repos/{owner}/{repo}/git/commits— create candidate commit (Contents: write).DELETE /repos/{owner}/{repo}/git/refs/heads/mergespan/queue/<n>— cleanup (Contents: write).GET /repos/{owner}/{repo}/contents/.github/mergespan.toml?ref=<sha>— read config (Contents: read).GET /repos/{owner}/{repo}/commits/{sha}/check-runs— read checks on candidate (Checks: read).POST /repos/{owner}/{repo}/check-runs— publishmergespancheck (Checks: write).POST /repos/{owner}/{repo}/issues/{number}/comments— comment on PR (Issues: write).DELETE /repos/{owner}/{repo}/issues/{number}/labels/{name}— remove labels (Issues: write).POST /repos/{owner}/{repo}/actions/runs/{id}/cancel— cancel candidate workflow (Actions: write).
Event subscriptions
The App must subscribe to these events (exact names, case-sensitive):
pushpull_requestcheck_runcheck_suiteworkflow_runissue_comment
Missing subscriptions are surfaced in the console setup check app_events as FAILED with the missing event names.
Why each event
| Event | Purpose |
|---|---|
push | Candidate creation/update on mergespan/queue/**; also base branch advance. |
pull_request | Label changes, open/close/ready/draft/retarget; the source of truth for queue eligibility. |
check_run | Candidate check status transitions; the primary validation signal. |
check_suite | Completion of the candidate’s check suite. |
workflow_run | Candidate workflow run lifecycle; used for cancellation. |
issue_comment | @mergespan command comments (queue, urgent, dequeue, refresh, help). |
Webhook contract
- URL:
https://<worker-host>/webhook(or ingress Worker). Active, JSON. - Secret: The same value stored as
GITHUB_WEBHOOK_SECRETin the Worker and in the App’s webhook settings. - Verification: The Worker verifies
X-Hub-Signature-256(HMAC-SHA256 over the exact raw body bytes). Missing signature → 401. Missing event → 400. Missing delivery ID → 400. Missing secret → 500. Body > 1 MiB → 413/400. Signature mismatch → 401. - Deduplication:
X-GitHub-Deliveryis deduplicated transactionally in SQLite. A replay returns the original acceptance status (202) and only adds a diagnostic attempt row; the state is never rewritten. - Filtering: Unsupported events (e.g.,
release,deployment) return 202 ignored. Ping returns 200pong. - Internal marker: The alarm transport emits one non-secret structured marker
{"event":"installation_token","result":"ok"}when an App-JWT installation-token exchange passes the client’s acceptance checks. Failures emit no marker. Observable withwrangler tail. No headers, tokens, or bodies are persisted.
Secrets
| Name | Storage | Notes |
|---|---|---|
GITHUB_APP_ID | Worker var (plain text) | Not a secret. The numeric App ID. |
GITHUB_APP_PRIVATE_KEY | Wrangler secret (PEM) | Full PEM including BEGIN/END lines and newlines. Never on command line, in shell history, wrangler.toml, repo, chat, PR/issue, or logs. |
GITHUB_WEBHOOK_SECRET | Wrangler secret | Same value in the App’s webhook settings. Never on command line, in history, repo, chat, PR/issue, or logs. |
cd runtimes/cloudflare
wrangler secret put GITHUB_APP_PRIVATE_KEY # paste the full PEM at the prompt
wrangler secret put GITHUB_WEBHOOK_SECRET # or: ... < /path/outside/repo/secret
The native runtime reads both secrets from files via systemd LoadCredential= (or --app-private-key-file / --webhook-secret-file flags). They are never accepted in the environment, config file, command line, or stdout.
Installation scope
Install the App on exactly one repository per queue. The sandbox installation lists only mergespan-sandbox. The console discovers repositories through the App’s installations and lists only those the App is installed on and the user has access to. Do not install on the ModelRouter organization or all repositories; the cutover is a separate step (U6 in the sandbox record).
Source map
| Concern | File |
|---|---|
| App permissions / events validation | crates/engine/src/dashboard/setup.rs (app_permissions, app_events) |
| Webhook verification / hint extraction | crates/engine/src/hint.rs |
| API endpoints used | crates/github/src/endpoints.rs |
| Installation token minting | crates/github/src/auth.rs |
| Cloudflare webhook handler | runtimes/cloudflare/src/ingress.rs |
| Ingress-only Worker | runtimes/cloudflare-ingress/src/index.mjs |
| Native runtime auth | runtimes/native/src/ingress.rs |