> This page is for version v1 (default).
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.butterix.com/llms.txt
> - v0: https://docs.butterix.com/v0/llms.txt

> For the MDX source of any page, append .mdx to the page URL.
> For a complete documentation index, see https://docs.butterix.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.butterix.com/_mcp/server.
> If something on this page is wrong or missing, POST JSON {"page": "<page URL>", "message": "<what is wrong>"} to https://docs.butterix.com/_biti/feedback/agent.

# 接收 GitHub Webhook

`POST /webhooks/github/{siteId}`

由 GitHub（或兼容的 Git 服务）调用，无需 API 认证，但必须带正确的 `X-Hub-Signature-256` 签名（HMAC-SHA256，密钥为站点的 webhook secret）。

- `push` 到生产分支 → 生产部署。
- `pull_request` 的 `opened` / `synchronize` / `reopened` → 该分支的预览部署。
- `ping` → `{ ok: true }`；其他事件 → `{ ignored: true }`。

Base URL: https://api.butterix.com/v1

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `siteId` | string | yes | 站点 id（不是 slug） |

## Header parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `X-GitHub-Event` | enum | yes | Allowed: `push`, `pull_request`, `ping`. |
| `X-Hub-Signature-256` | string | yes |  |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `ref` | string | no |  |
| `after` | string | no |  |
| `head_commit` | object | no |  |
| `head_commit.message` | string | no |  |
| `action` | string | no |  |
| `pull_request` | object | no |  |
| `pull_request.number` | integer | no |  |
| `pull_request.title` | string | no |  |
| `pull_request.head` | object | no |  |
| `pull_request.head.ref` | string | no |  |
| `pull_request.head.sha` | string | no |  |

## Example request

```bash
curl -X POST https://api.butterix.com/v1/webhooks/github/site_2m4k8p \
     -H "X-GitHub-Event: push" \
     -H "X-Hub-Signature-256: sha256=4f1c…" \
     -H "Content-Type: application/json" \
     -d '{}'
```

## Responses

### 200

ping 或被忽略的事件

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `ok` | boolean | no |  |
| `ignored` | boolean | no |  |

### 202

已创建部署

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `deploymentId` | string | no |  |

### 401

签名错误

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | 人类可读的错误信息 |
| `code` | string | no | 机器可读的错误码（部分接口提供） |

### Example response (200)

```json
{
  "ok": true,
  "ignored": true
}
```
