有关 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 |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
sender object 必须A GitHub user. |
branch_protection_rule
This event occurs when there is activity relating to branch protection rules. For more information, see "About protected branches." For information about the APIs to manage branch protection rules, see 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_rule 的可用性
- 存储库
- 组织
- GitHub应用
branch_protection_rule 的 Webhook 有效负载对象
A branch protection rule was created.
| 名称, 类型, 说明 |
|---|
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 |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
rule object 必须The branch protection rule. Includes a |
Properties of |
sender object 必须A GitHub user. |
check_run
This event occurs when there is activity relating to a check run. For information about check runs, see "Getting started with the Checks API." For information about the APIs to manage check runs, see the GraphQL API documentation or "Check Runs" in the REST API documentation.
For activity relating to check suites, use the check-suite event.
To subscribe to this event, a GitHub App must have at least read-level access for the "Checks" repository permission. To receive the rerequested and requested_action event types, the app must have at least write-level access for the "Checks" permission. GitHub Apps with write-level access for the "Checks" permission are automatically subscribed to this webhook event.
Repository and organization webhooks only receive payloads for the created and completed event types in repositories.
The API only looks for pushes in the repository where the check run was created. Pushes to a branch in a forked repository are not detected and return an empty pull_requests array and a null value for head_branch.
check_run 的可用性
- 存储库
- 组织
- GitHub应用
check_run 的 Webhook 有效负载对象
A check run was completed, and a conclusion is available.
| 名称, 类型, 说明 |
|---|
action string 值: |
check_run object 必须A check performed on the code of a given code change |
Properties of |
installation object The GitHub App installation. Webhook payloads contain the |
enterprise object An enterprise on GitHub. Webhook payloads contain the |
organization object A GitHub organization. Webhook payloads contain the |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
sender object 必须A GitHub user. |
check_suite
This event occurs when there is activity relating to a check suite. For information about check suites, see "Getting started with the Checks API." For information about the APIs to manage check suites, see the GraphQL API documentation or "Check Suites" in the REST API documentation.
For activity relating to check runs, use the check_run event.
To subscribe to this event, a GitHub App must have at least read-level access for the "Checks" permission. To receive the requested and rerequested event types, the app must have at least write-level access for the "Checks" permission. GitHub Apps with write-level access for the "Checks" permission are automatically subscribed to this webhook event.
Repository and organization webhooks only receive payloads for the completed event types in repositories.
The API only looks for pushes in the repository where the check suite was created. Pushes to a branch in a forked repository are not detected and return an empty pull_requests array and a null value for head_branch.
check_suite 的可用性
- 存储库
- 组织
- GitHub应用
check_suite 的 Webhook 有效负载对象
All check runs in a check suite have completed, and a conclusion is available.
| 名称, 类型, 说明 |
|---|
action string 必须值: |
check_suite object 必须The check_suite. |
Properties of |
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 |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
sender object 必须A GitHub user. |
code_scanning_alert
This event occurs when there is activity relating to code scanning alerts in a repository. For more information, see "About code scanning" and "About code scanning alerts." For information about the API to manage code scanning, see "Code scanning" in the REST API documentation.
To subscribe to this event, a GitHub App must have at least read-level access for the "Code scanning alerts" repository permission.
code_scanning_alert 的可用性
- 存储库
- 组织
- GitHub应用
code_scanning_alert 的 Webhook 有效负载对象
A previously created code scanning alert appeared in another branch. This can happen when a branch is merged into or created from a branch with a pre-existing code scanning alert.
| 名称, 类型, 说明 |
|---|
action string 必须值: |
alert object 必须The code scanning alert involved in the event. |
Properties of |
commit_oid string 必须The commit SHA of the code scanning alert. When the action is |
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 |
ref string 必须The Git reference of the code scanning alert. When the action is |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
sender object 必须A GitHub user. |
commit_comment
This event occurs when there is activity relating to commit comments. For more information about commit comments, see "Commenting on a pull request." For information about the APIs to manage commit comments, see the GraphQL API documentation or "Commit comments" in the REST API documentation.
For activity relating to comments on pull request reviews, use the pull_request_review_comment event. For activity relating to issue comments, use the issue_comment event. For activity relating to discussion comments, use the discussion_comment event.
To subscribe to this event, a GitHub App must have at least read-level access for the "Contents" repository permission.
commit_comment 的可用性
- 存储库
- 组织
- GitHub应用
commit_comment 的 Webhook 有效负载对象
Someone commented on a commit.
| 名称, 类型, 说明 |
|---|
action string 必须The action performed. Can be 值: |
comment object 必须The commit comment resource. |
Properties of |
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 |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
sender object 必须A GitHub user. |
create
This event occurs when a Git branch or tag is created.
To subscribe to this event, a GitHub App must have at least read-level access for the "Contents" repository permission.
Notes:
- This event will not occur when more than three tags are created at once.
- Payloads are capped at 25 MB. If an event generates a larger payload, GitHub will not deliver a payload for that webhook event. This may happen, for example, if many branches or tags are pushed at once. We suggest monitoring your payload size to ensure delivery.
create 的可用性
- 存储库
- 组织
- GitHub应用
create 的 Webhook 有效负载对象
| 名称, 类型, 说明 |
|---|
description string or null 必须The repository's current description. |
enterprise object An enterprise on GitHub. Webhook payloads contain the |
installation object The GitHub App installation. Webhook payloads contain the |
master_branch string 必须The name of the repository's default branch (usually |
organization object A GitHub organization. Webhook payloads contain the |
pusher_type string 必须The pusher type for the event. Can be either |
ref string 必须The |
ref_type string 必须The type of Git ref object created in the repository. 可以是以下选项之一: |
repository object 必须The repository on GitHub where the event occurred. Webhook payloads contain the |
sender object 必须A GitHub user. |
custom_property
This event occurs when there is activity relating to a custom property.
For more information, see "Managing custom properties for repositories in your organization". For information about the APIs to manage custom properties, see "Custom properties" in the REST API documentation.
To subscribe to this event, a GitHub App must have at least read-level access for the "Custom properties" organization permission.
custom_property 的可用性
- 企业
- 组织
- GitHub应用