diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-08-28 13:06:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 13:06:45 +0800 |
commit | ced50e0ec13085504fa19c82f018a2eecb70ff68 (patch) | |
tree | 10dff3ff685a86bad683c731f8329743f217617e /models/webhook.go | |
parent | e41da3845d72e3adc7ae2cd3a02fc1f3943ebee6 (diff) | |
download | gitea-ced50e0ec13085504fa19c82f018a2eecb70ff68.tar.gz gitea-ced50e0ec13085504fa19c82f018a2eecb70ff68.zip |
Implementation of discord webhook (#2402)
* implementation of discord webhook
* fix webhooks
* fix typo and unnecessary color values
* fix typo
* fix imports and revert changes to webhook_slack.go
Diffstat (limited to 'models/webhook.go')
-rw-r--r-- | models/webhook.go | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/models/webhook.go b/models/webhook.go index b7e687a461..61840a9811 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -13,15 +13,14 @@ import ( "strings" "time" - "github.com/go-xorm/xorm" - gouuid "github.com/satori/go.uuid" - - api "code.gitea.io/sdk/gitea" - "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/sync" + api "code.gitea.io/sdk/gitea" + + "github.com/go-xorm/xorm" + gouuid "github.com/satori/go.uuid" ) // HookQueue is a global queue of web hooks @@ -150,6 +149,15 @@ func (w *Webhook) GetSlackHook() *SlackMeta { return s } +// GetDiscordHook returns discord metadata +func (w *Webhook) GetDiscordHook() *DiscordMeta { + s := &DiscordMeta{} + if err := json.Unmarshal([]byte(w.Meta), s); err != nil { + log.Error(4, "webhook.GetDiscordHook(%d): %v", w.ID, err) + } + return s +} + // History returns history of webhook by given conditions. func (w *Webhook) History(page int) ([]*HookTask, error) { return HookTasks(w.ID, page) @@ -314,12 +322,14 @@ const ( GOGS HookTaskType = iota + 1 SLACK GITEA + DISCORD ) var hookTaskTypes = map[string]HookTaskType{ - "gitea": GITEA, - "gogs": GOGS, - "slack": SLACK, + "gitea": GITEA, + "gogs": GOGS, + "slack": SLACK, + "discord": DISCORD, } // ToHookTaskType returns HookTaskType by given name. @@ -336,6 +346,8 @@ func (t HookTaskType) Name() string { return "gogs" case SLACK: return "slack" + case DISCORD: + return "discord" } return "" } @@ -515,6 +527,11 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err if err != nil { return fmt.Errorf("GetSlackPayload: %v", err) } + case DISCORD: + payloader, err = GetDiscordPayload(p, event, w.Meta) + if err != nil { + return fmt.Errorf("GetDiscordPayload: %v", err) + } default: p.SetSecret(w.Secret) payloader = p |