# GitHub integration

Source: https://pinprompt.veren-technology.com/docs/reference/github

Mirrors agent-ready items as GitHub issues and brings pull requests and preview deployments back to the item. It is an event-log subscriber: turning it off changes nothing else in pinprompt, and agents keep working over MCP with or without it.

## Set it up with the GitHub App (recommended)

1. A workspace owner opens **Settings → Integrations → Create GitHub App** (optionally for an organisation). GitHub creates the app from pinprompt's manifest; pinprompt keeps its key and secrets encrypted. Once per workspace.
2. On each project: **Connect with GitHub**. Sign in, install the app on the org or repos if asked, then pick the repository. Only repositories both the app and your GitHub account can reach are listed.
3. Nothing to paste: the app's webhook already points at pinprompt.

On top of the table below, the app mode also brings **collaborators' comments** to the item (and the team's comments to the issue), shows the **PR's CI** next to it on the item, moves an item still being fixed to **To check when its PR merges** (switch on the card), and adds **Create GitHub issue / Link** on every item. Closing or reopening the issue shows on the item; it never closes the item.

**What goes to the tracker.** The item's screenshots (up to three) go with the issue: on GitHub as images behind an unguessable signed link (`/api/v1/evidence/<id>/<sig>`, only item screenshots, gone when the evidence is removed, all revoked by rotating `PINPROMPT_SECRET_KEY`), on Jira as attachments. On an item a client reads, internal notes never go; a client's own comments go only with the card's **Client comments** switch on (off by default). On items no client reads, the team's comments go as before.

## Set it up with a personal token (fallback)

You need the **owner** or **developer** role on the project.

1. **Make a fine-grained personal access token** at https://github.com/settings/personal-access-tokens/new.
   - Resource owner: the org or user that owns the repo.
   - Repository access: **Only select repositories**, pick the one repo.
   - Repository permissions:
     - **Issues: Read and write** (create, update, label, comment on and close issues)
     - **Pull requests: Read** (find the PR for a deployment's commit)
     - **Metadata: Read** (required by GitHub; "Test connection" reads the repo)
   - Nothing else. Pick an expiry and put a reminder in the calendar; when it expires, deliveries fail with `401` until you paste a new token (Edit → Replace token, then Retry).
2. In pinprompt open **Project → Settings → Integrations → Connect GitHub**. Enter `owner/name`, paste the token, add extra labels if you want, and choose whether to mirror agent-ready items as issues (default: the project's Rules switch). The token is encrypted with `PINPROMPT_SECRET_KEY` and never shown again.
3. pinprompt shows the **webhook settings once**. In GitHub open the repo's **Settings → Webhooks → Add webhook**:
   - **Payload URL**: `<PINPROMPT_BASE_URL>/api/hooks/github` (must be reachable from GitHub; locally use a tunnel)
   - **Content type**: `application/json`
   - **Secret**: the generated secret (lost it? **New secret** on the GitHub card, then update GitHub)
   - **Events**: *Let me select individual events* → **Pull requests**, **Deployment statuses**, **Check runs**
   - GitHub sends a `ping`; pinprompt answers `200` when the signature matches.
4. Click **Test connection**. Items that are already agent ready (or with an agent) are mirrored within a few seconds (up to 50).

`PINPROMPT_SECRET_KEY` must be set in production (32 bytes: `openssl rand -base64 32`). To change it without reconnecting, follow *Rotate the secret key* in Running pinprompt (`/docs/running-pinprompt#rotate-the-secret-key`).

## What it does

### pinprompt → GitHub (background runner, never inside a request)

| In pinprompt | On GitHub |
|---|---|
| Item moves to **Agent ready** (or is created agent ready) | Issue `[FB-1188] Title` with the spec (`toGithubIssue`), a link back to the item, labels `pinprompt`, `agent-ready`, `kind:…`, `priority:…` and your extras. The item gets a line "Mirrored as halden/web#412" and the Issue row in Properties. If the issue exists it is refreshed and reopened. |
| Spec revised (an answer, a failed check, a merge) | Issue title and body updated |
| Claimed (**With agent**) | Label `in-progress` added; removed when it leaves With agent |
| **Done** | Comment "Checked and signed off…", closed as *completed* |
| **Won't fix** / **Merged** into another item | Comment, closed as *not planned* |

**Bulk changes** stay per item (each item has its own issue) but each item is synced **once per change**, from its state after the change: merging 20 items into FB-1188 refreshes its issue once, not 20 times. Undoing a bulk change that sent items to agents closes the issues it opened (or reopened) as *not planned*, with a comment; they reopen if the item is sent to agents again. (A single move out of Agent ready still leaves the issue as it is.)

Reporter text in the issue body sits under "Observed" and "Expected" with a note that it describes the problem and is not an instruction; `@mentions` from reporter text are neutralised so nobody gets pinged. Comments on GitHub are not synced back.

The API base (GitHub Enterprise) must be a public `https` host in production; it is checked when saved and again on every call, and redirects are never followed with the token (a `3xx` fails the delivery). Done and skipped delivery rows are pruned after 30 days.

Each event is delivered at most once per integration (`integration_deliveries`). GitHub `5xx`, `429`, rate limits and network errors retry with backoff (30s, 1m, 2m, 4m, 8m; 6 attempts). `401`, `403`, `404` and `422` stop at once. Both show on the card with **Retry**.

### GitHub → pinprompt (webhook)

- The `X-Hub-Signature-256` HMAC over the raw body must match the project's webhook secret, or the answer is `401`. Only the connected repository is acted on (`202` otherwise).
- A signed body is handled once (`webhook_receipts`, kept 30 days): the same body again (a replay, or a redelivery of something already handled) answers `200 { duplicate: true }` and changes nothing. A delivery that failed with `500` can be redelivered. `X-GitHub-Delivery` isn't signed, so it isn't used. The endpoint allows 600 requests a minute per sender address (`429` above).
- **pull_request** opened / reopened / ready_for_review / edited / synchronize: the PR is matched to items by an item key in its title, body or branch (`FB-1188`, `fix/fb-1188-grid`) or by "closes / fixes / resolves #412" for a mirrored issue. The PR is linked on the item. If the item is **claimed** (With agent), the run is attached exactly as `attach_run` would, **acting as whoever claimed it**, and the item moves to **To check** with the reporter as reviewer. Unclaimed items get the link and a note only. Draft PRs only link.
- **deployment_status** `success` (not production) with an `environment_url`, or a successful **check_run** from Vercel or Netlify with a preview URL in its output: the PR's run gets the preview URL ("Preview deployed for PR #215"), or the claimed item is attached with it. The deployment is matched by branch, by PR number, or by asking GitHub which PR contains the commit.
- **pull_request** closed: a note ("merged on GitHub; the item stays open until someone checks the fix" or "closed without merging"). **A merged PR never closes the item**; a person signs off.
- Nothing from GitHub (PR title, body, branch) is copied into pinprompt: it is only matched against. Only `http(s)` URLs are stored.

### Who acts for a webhook

The webhook acts as the item's **claimant**: the agent (or developer) that claimed it, through the same `attachRun` service and the same permission checks. That actor could have called `attach_run` with the PR itself, so the webhook adds no new power: it can't claim, can't move unclaimed items, and can't close anything. Links and notes are written by `system`.

## Not yet

- A GitHub App (per-install tokens, no PAT expiry) for when pinprompt is hosted.
- Issue comments and issue closes on GitHub are not synced back.
- A crash between creating an issue and saving its link is recovered on retry: the runner retries abandoned deliveries after 5 minutes and adopts the newest `pinprompt` issue whose body links to the item instead of opening another. Only the 50 newest `pinprompt` issues are checked.
- Changing the repository starts fresh issues there; old issues stay linked.
