--- date: "2016-12-01T16:00:00+02:00" title: "Webhook" slug: "webhooks" weight: 10 toc: false draft: false menu: sidebar: parent: "features" name: "Webhook" weight: 30 identifier: "webhooks" --- # Webhook Gitea 的儲存庫事件支援 web hook。這可以有儲存庫管理員在設定頁 `/:username/:reponame/settings/hooks` 中調整。Webhook 也可以按照組織調整或按照全系統調整。 所有的事件推送都是 POST 請求。此方法目前被下列服務支援: - Gitea (也可以是 GET 請求) - Gogs - Slack - Discord - Dingtalk - Telegram - Microsoft Teams - Feishu - Wechatwork - Packagist ### 事件資訊 **警告**: Payload 中的 `secret` 欄位已經在 Gitea 1.13.0 棄用,並且將在 1.14.0 移除: https://github.com/go-gitea/gitea/issues/11755 下面是一個將由 Gitea 發送到 Payload URL 的事件資訊的範例: ``` X-GitHub-Delivery: f6266f16-1bf3-46a5-9ea4-602e06ead473 X-GitHub-Event: push X-Gogs-Delivery: f6266f16-1bf3-46a5-9ea4-602e06ead473 X-Gogs-Event: push X-Gitea-Delivery: f6266f16-1bf3-46a5-9ea4-602e06ead473 X-Gitea-Event: push ``` ```json { "secret": "3gEsCfjlV2ugRwgpU#w1*WaW*wa4NXgGmpCfkbG3", "ref": "refs/heads/develop", "before": "28e1879d029cb852e4844d9c718537df08844e03", "after": "bffeb74224043ba2feb48d137756c8a9331c449a", "compare_url": "http://localhost:3000/gitea/webhooks/compare/28e1879d029cb852e4844d9c718537df08844e03...bffeb74224043ba2feb48d137756c8a9331c449a", "commits": [ { "id": "bffeb74224043ba2feb48d137756c8a9331c449a", "message": "Webhooks Yay!", "url": "http://localhost:3000/gitea/webhooks/commit/bffeb74224043ba2feb48d137756c8a9331c449a", "author": { "name": "Gitea", "email": "someone@gitea.io", "username": "gitea" }, "committer": { "name": "Gitea", "email": "someone@gitea.io", "username": "gitea" }, "timestamp": "2017-03-13T13:52:11-04:00" } ], "repository": { "id": 140, "owner": { "id": 1, "login": "gitea", "full_name": "Gitea", "email": "someone@gitea.io", "avatar_url": "https://localhost:3000/avatars/1", "username": "gitea" }, "name": "webhooks", "full_name": "gitea/webhooks", "description": "", "private": false, "fork": false, "html_url": "http://localhost:3000/gitea/webhooks", "ssh_url": "ssh://gitea@localhost:2222/gitea/webhooks.git", "clone_url": "http://localhost:3000/gitea/webhooks.git", "website": "", "stars_count": 0, "forks_count": 1, "watchers_count": 1, "open_issues_count": 7, "default_branch": "master", "created_at": "2017-02-26T04:29:06-05:00", "updated_at": "2017-03-13T13:51:58-04:00" }, "pusher": { "id": 1, "login": "gitea", "full_name": "Gitea", "email": "someone@gitea.io", "avatar_url": "https://localhost:3000/avatars/1", "username": "gitea" }, "sender": { "id": 1, "login": "gitea", "full_name": "Gitea", "email": "someone@gitea.io", "avatar_url": "https://localhost:3000/avatars/1", "username": "gitea" } } ``` ### 範例 此範例示範在發生推送事件時,如何使用 webhook 觸發 php 程式。 使用下列參數在您的儲存庫設定 Webhook 中建立一個 Gitea webhook: - 目標 URL: http://mydomain.com/webhook.php - HTTP 請求方法:POST - POST Content Type:application/json - Secret:123 - 觸發條件:推送事件 - 啟用:勾選 現在請到您的伺服器上建立 webhook.php 檔案 ``` 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188