diff options
author | Rémy Boulanouar <rboulanouar@gmail.com> | 2017-05-29 09:17:15 +0200 |
---|---|---|
committer | Bo-Yi Wu <appleboy.tw@gmail.com> | 2017-05-29 02:17:15 -0500 |
commit | e0c6ab2d44d17b72a7ea6f8b4c829c42baeaae3b (patch) | |
tree | 44e906f5ac3a322832e5d9a55ea59bf613d36b24 /models | |
parent | e67ece26f0b97437200998b9b153b4c3a87a65aa (diff) | |
download | gitea-e0c6ab2d44d17b72a7ea6f8b4c829c42baeaae3b.tar.gz gitea-e0c6ab2d44d17b72a7ea6f8b4c829c42baeaae3b.zip |
Add Gitea Webhook (#1755)
* Replace Gogs by Gitea
* Fix missing changes
* Create Gitea webhook and put Gogs webhook apart.
Diffstat (limited to 'models')
-rw-r--r-- | models/webhook.go | 9 | ||||
-rw-r--r-- | models/webhook_test.go | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/models/webhook.go b/models/webhook.go index 3fb1e57e78..5cb2e13a6d 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -312,9 +313,11 @@ type HookTaskType int const ( GOGS HookTaskType = iota + 1 SLACK + GITEA ) var hookTaskTypes = map[string]HookTaskType{ + "gitea": GITEA, "gogs": GOGS, "slack": SLACK, } @@ -327,6 +330,8 @@ func ToHookTaskType(name string) HookTaskType { // Name returns the name of an hook task type func (t HookTaskType) Name() string { switch t { + case GITEA: + return "gitea" case GOGS: return "gogs" case SLACK: @@ -503,7 +508,7 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err } } - // Use separate objects so modifications won't be made on payload on non-Gogs type hooks. + // Use separate objects so modifications won't be made on payload on non-Gogs/Gitea type hooks. switch w.HookTaskType { case SLACK: payloader, err = GetSlackPayload(p, event, w.Meta) @@ -536,6 +541,8 @@ func (t *HookTask) deliver() { timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second req := httplib.Post(t.URL).SetTimeout(timeout, timeout). + Header("X-Gitea-Delivery", t.UUID). + Header("X-Gitea-Event", string(t.EventType)). Header("X-Gogs-Delivery", t.UUID). Header("X-Gogs-Event", string(t.EventType)). Header("X-GitHub-Delivery", t.UUID). diff --git a/models/webhook_test.go b/models/webhook_test.go index 3f377eae7a..a637a16999 100644 --- a/models/webhook_test.go +++ b/models/webhook_test.go @@ -191,16 +191,19 @@ func TestDeleteWebhookByOrgID(t *testing.T) { func TestToHookTaskType(t *testing.T) { assert.Equal(t, GOGS, ToHookTaskType("gogs")) assert.Equal(t, SLACK, ToHookTaskType("slack")) + assert.Equal(t, GITEA, ToHookTaskType("gitea")) } func TestHookTaskType_Name(t *testing.T) { assert.Equal(t, "gogs", GOGS.Name()) assert.Equal(t, "slack", SLACK.Name()) + assert.Equal(t, "gitea", GITEA.Name()) } func TestIsValidHookTaskType(t *testing.T) { assert.True(t, IsValidHookTaskType("gogs")) assert.True(t, IsValidHookTaskType("slack")) + assert.True(t, IsValidHookTaskType("gitea")) assert.False(t, IsValidHookTaskType("invalid")) } @@ -221,7 +224,7 @@ func TestCreateHookTask(t *testing.T) { hookTask := &HookTask{ RepoID: 3, HookID: 3, - Type: GOGS, + Type: GITEA, URL: "http://www.example.com/unit_test", Payloader: &api.PushPayload{}, } |