@@ -1,23 +1,172 @@ |
| 1 | 1 | # Pull requests |
| 2 | 2 | |
| 3 | | -> **Planned.** Pull request endpoints are not yet shipped. |
| 4 | | - |
| 5 | | -## Planned routes |
| 6 | | - |
| 7 | | -| Method | Path | Scope | |
| 8 | | -|--------|----------------------------------------------------------|--------------| |
| 9 | | -| GET | `/api/v1/repos/{owner}/{repo}/pulls` | `repo:read` | |
| 10 | | -| GET | `/api/v1/repos/{owner}/{repo}/pulls/{number}` | `repo:read` | |
| 11 | | -| POST | `/api/v1/repos/{owner}/{repo}/pulls` | `repo` | |
| 12 | | -| PATCH | `/api/v1/repos/{owner}/{repo}/pulls/{number}` | `repo` | |
| 13 | | -| GET | `/api/v1/repos/{owner}/{repo}/pulls/{number}/files` | `repo:read` | |
| 14 | | -| GET | `/api/v1/repos/{owner}/{repo}/pulls/{number}/commits` | `repo:read` | |
| 15 | | -| GET | `/api/v1/repos/{owner}/{repo}/pulls/{number}/reviews` | `repo:read` | |
| 16 | | -| POST | `/api/v1/repos/{owner}/{repo}/pulls/{number}/reviews` | `repo` | |
| 17 | | -| PUT | `/api/v1/repos/{owner}/{repo}/pulls/{number}/merge` | `repo` | |
| 18 | | -| GET | `/api/v1/repos/{owner}/{repo}/pulls/{number}/comments` | `repo:read` | |
| 19 | | -| POST | `/api/v1/repos/{owner}/{repo}/pulls/{number}/comments` | `repo` | |
| 20 | | - |
| 21 | | -The merge endpoint is gated by branch protection: status checks, |
| 22 | | -required reviewers, and conversation-resolution rules apply |
| 23 | | -identically to API-driven and UI-driven merges. |
| 3 | +Pull requests live per repo. They share the `issues` row for |
| 4 | +title/body/state/timeline; this surface exposes the PR-specific |
| 5 | +shape (refs, oids, mergeability, merge state). Reviews and review |
| 6 | +comments live in a sibling batch that ships later. |
| 7 | + |
| 8 | +## Pull request shape |
| 9 | + |
| 10 | +```json |
| 11 | +{ |
| 12 | + "id": 19, |
| 13 | + "number": 1, |
| 14 | + "title": "wire up foo", |
| 15 | + "body": "first cut", |
| 16 | + "state": "open", |
| 17 | + "draft": false, |
| 18 | + "base_ref": "trunk", |
| 19 | + "head_ref": "feature", |
| 20 | + "base_oid": "abc…", |
| 21 | + "head_oid": "def…", |
| 22 | + "mergeable": true, |
| 23 | + "mergeable_state": "clean", |
| 24 | + "merged": false, |
| 25 | + "author_id": 42, |
| 26 | + "created_at": "2026-05-12T05:00:00Z", |
| 27 | + "updated_at": "2026-05-12T05:00:00Z" |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +`mergeable` is omitted while the worker hasn't computed it yet |
| 32 | +(treat absence as "unknown"). `mergeable_state` mirrors GitHub's |
| 33 | +vocabulary (`clean`, `dirty`, `blocked`, `unknown`, `unstable`, |
| 34 | +`has_hooks`, etc. — depending on what the worker recorded). |
| 35 | + |
| 36 | +When `merged` is true, `merge_commit_sha`, `merge_method`, and |
| 37 | +`merged_at` are populated. |
| 38 | + |
| 39 | +## List pull requests |
| 40 | + |
| 41 | +``` |
| 42 | +GET /api/v1/repos/{owner}/{repo}/pulls |
| 43 | +``` |
| 44 | + |
| 45 | +Required scope: `repo:read`. Paginated; `?per_page=` (≤100) and |
| 46 | +`?page=` apply, with the standard `Link:` header. |
| 47 | + |
| 48 | +Optional `?state=open|closed|all` filter (defaults to all); |
| 49 | +optional `?draft=true|false` filter. |
| 50 | + |
| 51 | +## Get a single pull request |
| 52 | + |
| 53 | +``` |
| 54 | +GET /api/v1/repos/{owner}/{repo}/pulls/{number} |
| 55 | +``` |
| 56 | + |
| 57 | +Required scope: `repo:read`. `404` when the number refers to an |
| 58 | +issue (use the issues surface) or when the caller can't see the |
| 59 | +repo. |
| 60 | + |
| 61 | +## Create a pull request |
| 62 | + |
| 63 | +``` |
| 64 | +POST /api/v1/repos/{owner}/{repo}/pulls |
| 65 | +``` |
| 66 | + |
| 67 | +Required scope: `repo:write`. Policy: `ActionPullCreate`. |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "title": "wire up foo", |
| 72 | + "body": "first cut", |
| 73 | + "base": "trunk", |
| 74 | + "head": "feature", |
| 75 | + "draft": false |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +| Field | Type | Notes | |
| 80 | +|---------|--------|----------------------------------------------------| |
| 81 | +| `title` | string | Required, 1–256 chars. | |
| 82 | +| `body` | string | Optional markdown body, ≤65535 chars. | |
| 83 | +| `base` | string | Required, branch name on the target repo. | |
| 84 | +| `head` | string | Required, must differ from `base`. | |
| 85 | +| `draft` | bool | Open as draft; flip to ready via PATCH. | |
| 86 | + |
| 87 | +Returns `201` with the PR envelope. `422` when `head` or `base` |
| 88 | +don't resolve, when they're equal, or when no commits are ahead |
| 89 | +of `base`. |
| 90 | + |
| 91 | +## Update a pull request |
| 92 | + |
| 93 | +``` |
| 94 | +PATCH /api/v1/repos/{owner}/{repo}/pulls/{number} |
| 95 | +``` |
| 96 | + |
| 97 | +Required scope: `repo:write`. Send only the fields you want to |
| 98 | +change. |
| 99 | + |
| 100 | +```json |
| 101 | +{ |
| 102 | + "title": "renamed", |
| 103 | + "body": "updated body", |
| 104 | + "state": "closed", |
| 105 | + "draft": false |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +Permission rules: |
| 110 | + |
| 111 | +- **Title / body** — PR author OR a repo collaborator with write |
| 112 | + access. Other callers `403`. |
| 113 | +- **State** — `ActionPullClose` on the repo. |
| 114 | +- **Draft** — flipping `true` → `false` (mark ready) is |
| 115 | + author-only. `false` → `true` is not supported (`422`). |
| 116 | + |
| 117 | +## List commits in a pull request |
| 118 | + |
| 119 | +``` |
| 120 | +GET /api/v1/repos/{owner}/{repo}/pulls/{number}/commits |
| 121 | +``` |
| 122 | + |
| 123 | +Required scope: `repo:read`. Returns the commit set ahead of base |
| 124 | +in order, populated by the synchronize worker after open. |
| 125 | + |
| 126 | +## List files changed by a pull request |
| 127 | + |
| 128 | +``` |
| 129 | +GET /api/v1/repos/{owner}/{repo}/pulls/{number}/files |
| 130 | +``` |
| 131 | + |
| 132 | +Required scope: `repo:read`. Each entry carries `path`, `status` |
| 133 | +(`added`/`modified`/`removed`/`renamed`), `additions`, |
| 134 | +`deletions`, and `changes`. `old_path` is set on renames. |
| 135 | + |
| 136 | +## Merge a pull request |
| 137 | + |
| 138 | +``` |
| 139 | +PUT /api/v1/repos/{owner}/{repo}/pulls/{number}/merge |
| 140 | +``` |
| 141 | + |
| 142 | +Required scope: `repo:write`. Policy: `ActionPullMerge`. |
| 143 | + |
| 144 | +```json |
| 145 | +{ |
| 146 | + "commit_title": "Optional override", |
| 147 | + "commit_message": "Optional body", |
| 148 | + "merge_method": "merge", |
| 149 | + "sha": "<head_oid>" |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +| Field | Type | Notes | |
| 154 | +|------------------|--------|----------------------------------------------------| |
| 155 | +| `commit_title` | string | Subject override; falls back to `"<title> (#<number>)"`. | |
| 156 | +| `commit_message` | string | Body for the merge commit. Ignored on rebase. | |
| 157 | +| `merge_method` | string | `"merge"`, `"squash"`, `"rebase"` — must be enabled on the repo. Defaults to the repo's default merge method. | |
| 158 | +| `sha` | string | Optional `head_oid` guard; `409` on mismatch. | |
| 159 | + |
| 160 | +Returns `200` with the freshly-loaded PR (state now `closed`, |
| 161 | +`merged` true). `409` when the PR is already merged/closed or |
| 162 | +when `mergeable_state` isn't `clean`. `422` when the requested |
| 163 | +merge method is disabled on the repo or when no commits are |
| 164 | +ahead of base. `503` if another merge is in flight. |
| 165 | + |
| 166 | +## Not yet shipped |
| 167 | + |
| 168 | +- Reviews (`/pulls/{n}/reviews`) |
| 169 | +- Review comments (`/pulls/{n}/comments`) |
| 170 | +- Requested reviewers |
| 171 | +- `PUT /pulls/{n}/update-branch` |
| 172 | +- `PUT /pulls/{n}/auto-merge` |