有关 Webhook 事件和有效负载
您可以创建订阅此页所列事件的 web 挂钩。 若要限制对服务器的 HTTP 请求数,应仅订阅计划处理的特定事件。 有关详细信息,请参阅“创建网络钩子”。
此页面上的每个 Webhook 事件都包含该事件的 Webhook 属性的说明。 如果某个事件包含多个操作,则会包含与每个操作对应的属性。
每个事件仅适用于特定类型的 Webhook。 例如,组织 Webhook 可以订阅 team 事件,但存储库 Webhook 无法订阅。 各个 Webhook 事件的说明中列出该事件的可用性。 有关详细信息,请参阅“Webhook 的类型”。
sender 属性
大多数 Webhook 的有效负载都包含一个名为 sender 的属性,用于标识触发该事件的用户。
GitHub有时无法解析特定用户,例如,当事件来自内部进程而不是人员或触发操作没有关联用户时。 对于某些事件,例如 check_run 和 check_suite,这包括没有 Git 推送或经过身份验证的 API 参与者的操作。
在这些情况下,sender 会填入 ghost 用户,这是一个占位账户,其 login 为 ghost,并且其 id 不与真实的当前用户关联。 不要假设 sender 始终标识的是触发事件的人,并在任何依赖它的安全或业务逻辑中将 ghost 用户考虑在内。
有效负载上限
有效负载上限为 25 MB。 如果事件生成的有效负载较大,GitHub 将不会为该 Webhook 事件传递有效负载。 例如,如果同时推送多个分支或标记,这种情况可能会发生在 create 事件中。 我们建议监控有效负载的大小以确保成功递送。
"传输标头"
通过 HTTP POST 方式递送到您的 Webhook 配置的 URL 端点的有效负载将包含几个特殊标头。
X-GitHub-Hook-ID:Webhook 的唯一标识符。X-GitHub-Event:触发传递的事件的名称。X-GitHub-Delivery:用于标识事件的全局唯一标识符(GUID)。X-Hub-Signature:如果 Webhook 配置了secret,则会发送此标头。 这是请求正文的 HMAC 十六进制摘要,使用 SHA-1 哈希函数,并以secret作为 HMACkey生成。 提供X-Hub-Signature以便与现有集成兼容。 建议改用更加安全的X-Hub-Signature-256。X-Hub-Signature-256:如果 Webhook 配置了secret,则会发送此标头。 这是请求正文的 HMAC 十六进制摘要,使用 SHA-256 哈希函数并以secret作为 HMACkey生成。 有关详细信息,请参阅“验证 Webhook 交付”。User-Agent:此标头将始终具有前缀GitHub-Hookshot/。X-GitHub-Hook-Installation-Target-Type:创建 webhook 的资源类型。X-GitHub-Hook-Installation-Target-ID:创建 Webhook 的资源的唯一标识符。
若要查看每个标头在 Webhook 有效负载中可能呈现的内容,请参阅 Webhook 交付示例。
Webhook交付示例
可以选择将有效负载以 JSON 格式 (application/json) 或作为 URL 编码数据 (x-www-form-urlencoded) 传递。 下面是一个使用 JSON 格式的 Webhook POST 请求的示例。
> POST /payload HTTP/1.1
> X-GitHub-Delivery: 72d3162e-cc78-11e3-81ab-4c9367dc0958
> X-Hub-Signature: sha1=7d38cdd689735b008b3c702edd92eea23791c5f6
> X-Hub-Signature-256: sha256=d57c68ca6f92289e6987922ff26938930f6e66a2d161ef06abdf1859230aa23c
> User-Agent: GitHub-Hookshot/044aadd
> Content-Type: application/json
> Content-Length: 6615
> X-GitHub-Event: issues
> X-GitHub-Hook-ID: 292430182
> X-GitHub-Hook-Installation-Target-ID: 79929171
> X-GitHub-Hook-Installation-Target-Type: repository
> {
> "action": "opened",
> "issue": {
> "url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
> "number": 1347,
> ...
> },
> "repository" : {
> "id": 1296269,
> "full_name": "octocat/Hello-World",
> "owner": {
> "login": "octocat",
> "id": 1,
> ...
> },
> ...
> },
> "sender": {
> "login": "octocat",
> "id": 1,
> ...
> }
> }
branch_protection_configuration
This event occurs when there is a change to branch protection configurations for a repository. For more information, see "About protected branches." For information about using the APIs to manage branch protection rules, see "Branch protection rule" in the GraphQL documentation or "Branch protection" in the REST API documentation.
To subscribe to this event, a GitHub App must have at least read-level access for the "Administration" repository permission.
branch_protection_configuration 的可用性
- 存储库
- 组织
- GitHub应用
branch_protection_configuration 的 Webhook 有效负载对象
All branch protections were disabled for a repository.
| 名称, 类型, 说明 |
|---|
action string 必须值: |
enterprise object An enterprise on GitHub. Webhook payloads contain the |
installation object The GitHub App installation. Webhook payloads contain the |
organization object A GitHub organization. Webhook payloads contain the |