Skip to main content

Eventos y cargas de webhook

Aprende sobre cuándo se produce cada evento de webhook y qué contiene la carga.

Sobre eventos y cargas de webhook

Puedes crear webhooks que se suscriban a los eventos listados en esta página. Para limitar el número de solicitudes HTTP al servidor, solo debes suscribirte a los eventos específicos que planees controlar. Para más información, consulta Crear webhooks.

Cada evento webhook en esta página incluye una descripción de las propiedades del webhook para ese evento. Si el evento tiene varias acciones, se incluyen las propiedades correspondientes a cada acción.

Cada evento solo está disponible para tipos específicos de webhooks. Por ejemplo, un webhook de organización puede suscribirse al evento team, pero un webhook de repositorio no puede. La descripción de cada evento de webhook enumera la disponibilidad de ese evento. Para más información, consulta Tipos de webhooks.

La propiedad sender

La mayoría de las cargas de webhook incluyen una sender propiedad que identifica al usuario que desencadenó el evento. A veces, GitHub no puede identificar a un usuario específico, por ejemplo, cuando un evento proviene de un proceso interno en lugar de una persona, o cuando la acción que lo desencadena no tiene asociado ningún usuario. Para algunos eventos, como check_run y check_suite, esto incluye acciones sin un push de Git ni un actor de API autenticado.

En estos casos, sender se rellena con el usuario ghost, una cuenta de marcador de posición cuya login es ghost y cuyo id no está vinculado a ningún usuario real vigente. No asuma que sender siempre identifica a la persona que causó un evento, y tenga en cuenta al usuario ghost en cualquier lógica de negocio o de seguridad que dependa de ello.

Límite de carga útil

Las cargas se limitan a 25 MB. Si un evento genera una carga mayor, GitHub no entregará una carga para ese evento de webhook. Esto puede pasar, por ejemplo, en un evento create si se insertan muchas ramas o etiquetas al mismo tiempo. Te sugerimos monitorear el tamaño de tu carga útil para garantizar la entrega.

Encabezados de entrega

Las cargas útiles de HTTP POST que se entregan a la terminal URL configurada para tu webhook contendrán varios encabezados especiales:

  • X-GitHub-Hook-ID: identificador único del webhook.
  • X-GitHub-Event: nombre del evento que desencadenó la entrega.
  • X-GitHub-Delivery: un identificador único global (GUID) para identificar el evento.
  • X-Hub-Signature: este encabezado se envía si el webhook está configurado con secret. Este es el resumen hexadecimal de HMAC para el cuerpo de la solicitud y se genera mediante la función de hash SHA-1 y secret como key de HMAC. X-Hub-Signature se proporciona para la compatibilidad con las integraciones existentes. Se recomienda usar la función X-Hub-Signature-256 más segura en su lugar.
  • X-Hub-Signature-256: este encabezado se envía si el webhook está configurado con secret. Este es el resumen hexadecimal de HMAC para el cuerpo de la solicitud y se genera mediante la función de hash SHA-256 y secret como key de HMAC. Para más información, consulta Validación de entregas de webhook.
  • User-Agent: este encabezado siempre tendrá el prefijo GitHub-Hookshot/.
  • X-GitHub-Hook-Installation-Target-Type: tipo de recurso donde se creó el webhook.
  • X-GitHub-Hook-Installation-Target-ID: identificador único del recurso donde se creó el webhook.

Para ver el aspecto de cada encabezado en una carga de webhook, consulte Entrega de webhook de ejemplo.

Ejemplo de entrega de webhook

Puede elegir que las cargas se entreguen en formato JSON (application/json) o como datos con codificación URL (x-www-form-urlencoded). A continuación se muestra un ejemplo de una solicitud POST de webhook que usa el formato JSON.

> 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.

Disponibilidad para branch_protection_configuration

  • Repositorios
  • Las organizaciones
  • aplicaciones de GitHub

Objeto de carga útil del webhook para branch_protection_configuration

All branch protections were disabled for a repository.

Parámetros del cuerpo de la solicitud de webhook
Nombre, Tipo, Descripción
action string Obligatorio

Valor: disabled

enterprise object

An enterprise on GitHub. Webhook payloads contain the enterprise property when the webhook is configured on an enterprise account or an organization that's part of an enterprise account. For more information, see "About enterprise accounts."

installation object

The GitHub App installation. Webhook payloads contain the installation property when the event is configured for and sent to a GitHub App. For more information, see "Using webhooks with GitHub Apps."

organization object

A GitHub organization. Webhook payloads contain the organization property when the webhook is configured for an organization, or when the event occurs from activity in a repository owned by an organization.

repository object Obligatorio

The repository on GitHub where the event occurred. Webhook payloads contain the repository property when the event occurs from activity in a repository.

sender object Obligatorio

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.

Disponibilidad para branch_protection_rule

  • Repositorios
  • Las organizaciones
  • aplicaciones de GitHub

Objeto de carga útil del webhook para branch_protection_rule

A branch protection rule was created.

Parámetros del cuerpo de la solicitud de webhook
Nombre, Tipo, Descripción
action string Obligatorio

Valor: created

enterprise object

An enterprise on GitHub. Webhook payloads contain the enterprise property when the webhook is configured on an enterprise account or an organization that's part of an enterprise account. For more information, see "About enterprise accounts."

installation object

The GitHub App installation. Webhook payloads contain the installation property when the event is configured for and sent to a GitHub App. For more information, see "Using webhooks with GitHub Apps."

organization object

A GitHub organization. Webhook payloads contain the organization property when the webhook is configured for an organization, or when the event occurs from activity in a repository owned by an organization.

repository object Obligatorio

The repository on GitHub where the event occurred. Webhook payloads contain the repository property when the event occurs from activity in a repository.

rule object Obligatorio

The branch protection rule. Includes a name and all the branch protection settings applied to branches that match the name. Binary settings are boolean. Multi-level configurations are one of off, non_admins, or everyone. Actor and build lists are arrays of strings.

sender object Obligatorio

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.

Disponibilidad para check_run

  • Repositorios
  • Las organizaciones
  • aplicaciones de GitHub

Objeto de carga útil del webhook para check_run

A check run was completed, and a conclusion is available.

Parámetros del cuerpo de la solicitud de webhook
Nombre, Tipo, Descripción
action string

Valor: completed

check_run object Obligatorio

A check performed on the code of a given code change

installation object

The GitHub App installation. Webhook payloads contain the installation property when the event is configured for and sent to a GitHub App. For more information, see "Using webhooks with GitHub Apps."

enterprise object