summaryrefslogtreecommitdiffstats
path: root/services/webhook
diff options
context:
space:
mode:
authorPaweł Bogusławski <pawel.boguslawski@ib.pl>2021-02-11 18:34:34 +0100
committerGitHub <noreply@github.com>2021-02-11 12:34:34 -0500
commit7d7007dca75ab3a3a48b9f3fd7cc4350cc626870 (patch)
treea9d4974fc5e990befc682c0725f7adb217491d08 /services/webhook
parentac701637b42d2d6bb5fe9b258f3f54959b6a505e (diff)
downloadgitea-7d7007dca75ab3a3a48b9f3fd7cc4350cc626870.tar.gz
gitea-7d7007dca75ab3a3a48b9f3fd7cc4350cc626870.zip
Added option to disable webhooks (#13176)
* Added option to disable web hooks This mod introduces DISABLE_WEB_HOOKS parameter in [security] section of app.ini (by default set to false). If set to true it disables web hooks feature. Any existing undelivered web hook tasks will be cancelled. Any existing web hook definitions will be left untouched in db but its delivery tasks will be ignored. Author-Change-Id: IB#1105130 * Webhook spelling fixed Webhook spelling fixed. Fixes: 07df6614dc84cdd2e9f39c57577fa1062bd70012 Related: https://github.com/go-gitea/gitea/pull/13176#pullrequestreview-510868421 Author-Change-Id: IB#1105174 * Parameter description fixed Parameter description fixed. Fixes: 07df6614dc84cdd2e9f39c57577fa1062bd70012 Related: https://github.com/go-gitea/gitea/pull/13176#pullrequestreview-514086107 Author-Change-Id: IB#1105174
Diffstat (limited to 'services/webhook')
-rw-r--r--services/webhook/deliver.go4
-rw-r--r--services/webhook/webhook.go5
2 files changed, 9 insertions, 0 deletions
diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go
index 44c1a18b6c..8ac7d8c192 100644
--- a/services/webhook/deliver.go
+++ b/services/webhook/deliver.go
@@ -141,6 +141,10 @@ func Deliver(t *models.HookTask) error {
}
}()
+ if setting.DisableWebhooks {
+ return fmt.Errorf("Webhook task skipped (webhooks disabled): [%d]", t.ID)
+ }
+
resp, err := webhookHTTPClient.Do(req)
if err != nil {
t.ResponseInfo.Body = fmt.Sprintf("Delivery: %v", err)
diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go
index 7b6bc555f7..87f28a5cdc 100644
--- a/services/webhook/webhook.go
+++ b/services/webhook/webhook.go
@@ -120,6 +120,11 @@ func checkBranch(w *models.Webhook, branch string) bool {
}
func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.HookEventType, p api.Payloader) error {
+ // Skip sending if webhooks are disabled.
+ if setting.DisableWebhooks {
+ return nil
+ }
+
for _, e := range w.EventCheckers() {
if event == e.Type {
if !e.Has() {