# 如何将 GitHub Webhook 接入 Pocket Alert？

> 几个简单步骤，轻松将 GitHub Webhook 接入推送通知

*19.06.2024*

<!-- source: https://pocketalert.app/zh/blog/how-to-integrate-github-webhooks-into-pocket-alert -->

[//]: # '# How to integrate GitHub webhooks into pocket alert'

## 创建新的 Webhook

![create webhook](https://cdn.pocketalert.app/guides/git/webhook-create.gif)

1. 前往 [Webhooks](https://pocketalert.app/webhooks) 页面
2. 点击「Create」按钮
3. 按以下信息填写表单：
   - **Name**：Webhook 的名称
   - **Application**：要关联 Webhook 的应用
   - **Device**：要关联 Webhook 的设备
   - **Message**：Webhook 触发时发送的消息
4. 点击「Create」按钮
5. 复制 Webhook 的 URL

**在消息中指定 \* 可以获取全部 JSON，然后确定你需要的参数。**

## 将 Webhook 添加到 GitHub

![github add webhook](https://cdn.pocketalert.app/guides/git/github-add-webhook.gif)

1. 前往仓库设置
2. 点击「Webhooks」标签页
3. 点击「Add webhook」按钮
4. 按以下信息填写表单：
   - **Payload URL**：粘贴 Webhook 的 URL
   - **Content type**：application/json
   - **Secret**：Webhook 的密钥
   - **Which events would you like to trigger this webhook?**：选择希望触发 Webhook 的事件
   - 点击「Add webhook」按钮
5. 向仓库推送一次提交，测试 Webhook

## 最终设置

在 GitHub 中设置好 Webhook 并向仓库推送提交后，你应该能在 Pocket Alert 应用中看到消息。

你可以定义生成通知所需的变量。

例如，如果你想获取提交信息，可以使用以下代码：

![webhook update](https://cdn.pocketalert.app/guides/git/github-webhook-update.png)

```json Commit: %head_commit.message%
Author: %head_commit.author.name%

Date: %head_commit.timestamp%
```

关于变量的更多信息，请参阅 [Webhook 设置](https://info.pocketalert.app/api/webhooks/settings.html)。

## Pocket Alert 应用中的消息示例

![messages](https://cdn.pocketalert.app/guides/git/github-webhook-messages.png)

---

![message](https://cdn.pocketalert.app/guides/git/github-webhook-message.png)

## 总结

本指南介绍了如何将 GitHub Webhook 接入 Pocket Alert 应用：如何创建新的 Webhook、如何将其添加到 GitHub，以及如何在 Pocket Alert 应用中使用消息。我们还展示了 Pocket Alert 应用中的消息示例。希望本指南对你有所帮助。如有任何问题，欢迎随时向我们提问，我们乐意提供帮助。感谢你阅读本指南。
