aboutsummaryrefslogtreecommitdiffstats
path: root/models/webhook_discord.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-09-03 01:20:24 -0700
committerLauris BH <lauris@nix.lv>2017-09-03 11:20:24 +0300
commitb689bb61804fddfd2df8df7250522b0fc227484e (patch)
tree6cd96dfc3c0c7b2a0b265217f2893aa606307b0a /models/webhook_discord.go
parent79f7839633167bbb146a7b0d17ce0ec1c990d085 (diff)
downloadgitea-b689bb61804fddfd2df8df7250522b0fc227484e.tar.gz
gitea-b689bb61804fddfd2df8df7250522b0fc227484e.zip
Webhooks for repo creation/deletion (#1663)
* Webhooks for repo creation/deletion * add createHookTask * Add handles for GetSlackPayload and GetDiscordPayload
Diffstat (limited to 'models/webhook_discord.go')
-rw-r--r--models/webhook_discord.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/models/webhook_discord.go b/models/webhook_discord.go
index 4426a945b4..631c8174e9 100644
--- a/models/webhook_discord.go
+++ b/models/webhook_discord.go
@@ -228,6 +228,37 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, meta *DiscordMeta)
}, nil
}
+func getDiscordRepositoryPayload(p *api.RepositoryPayload, meta *DiscordMeta) (*DiscordPayload, error) {
+ var title, url string
+ var color int
+ switch p.Action {
+ case api.HookRepoCreated:
+ title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName)
+ url = p.Repository.HTMLURL
+ color = successColor
+ case api.HookRepoDeleted:
+ title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName)
+ color = warnColor
+ }
+
+ return &DiscordPayload{
+ Username: meta.Username,
+ AvatarURL: meta.IconURL,
+ Embeds: []DiscordEmbed{
+ {
+ Title: title,
+ URL: url,
+ Color: color,
+ Author: DiscordEmbedAuthor{
+ Name: p.Sender.UserName,
+ URL: setting.AppURL + p.Sender.UserName,
+ IconURL: p.Sender.AvatarURL,
+ },
+ },
+ },
+ }, nil
+}
+
// GetDiscordPayload converts a discord webhook into a DiscordPayload
func GetDiscordPayload(p api.Payloader, event HookEventType, meta string) (*DiscordPayload, error) {
s := new(DiscordPayload)
@@ -244,6 +275,8 @@ func GetDiscordPayload(p api.Payloader, event HookEventType, meta string) (*Disc
return getDiscordPushPayload(p.(*api.PushPayload), discord)
case HookEventPullRequest:
return getDiscordPullRequestPayload(p.(*api.PullRequestPayload), discord)
+ case HookEventRepository:
+ return getDiscordRepositoryPayload(p.(*api.RepositoryPayload), discord)
}
return s, nil