summaryrefslogtreecommitdiffstats
path: root/models/webhook.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/webhook.go')
-rw-r--r--models/webhook.go33
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