Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

PermissionLevelRequiredPurpose
MetadataReadyesMandatory; every App has it.
ContentsRead & WriteyesCreate candidate branch/commit; squash merge.
Pull requestsRead & WriteyesRead PR state; merge.
IssuesRead & Writeyesqueue / urgent labels and PR comments.
ChecksRead & WriteyesCreate/read the mergespan check run on the PR head.
ActionsRead & WriteyesCancel candidate workflow runs.
WorkflowsNot requirednoDirect workflow writes were not tested in v0.1; the App does not request this.
AdministrationNo—Never requested.
MembersNo—Never requested.
OrganizationNo—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 — publish mergespan check (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):

  • push
  • pull_request
  • check_run
  • check_suite
  • workflow_run
  • issue_comment

Missing subscriptions are surfaced in the console setup check app_events as FAILED with the missing event names.

Why each event

EventPurpose
pushCandidate creation/update on mergespan/queue/**; also base branch advance.
pull_requestLabel changes, open/close/ready/draft/retarget; the source of truth for queue eligibility.
check_runCandidate check status transitions; the primary validation signal.
check_suiteCompletion of the candidate’s check suite.
workflow_runCandidate 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_SECRET in 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-Delivery is 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 200 pong.
  • 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 with wrangler tail. No headers, tokens, or bodies are persisted.

Secrets

NameStorageNotes
GITHUB_APP_IDWorker var (plain text)Not a secret. The numeric App ID.
GITHUB_APP_PRIVATE_KEYWrangler 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_SECRETWrangler secretSame 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

ConcernFile
App permissions / events validationcrates/engine/src/dashboard/setup.rs (app_permissions, app_events)
Webhook verification / hint extractioncrates/engine/src/hint.rs
API endpoints usedcrates/github/src/endpoints.rs
Installation token mintingcrates/github/src/auth.rs
Cloudflare webhook handlerruntimes/cloudflare/src/ingress.rs
Ingress-only Workerruntimes/cloudflare-ingress/src/index.mjs
Native runtime authruntimes/native/src/ingress.rs