aboutsummaryrefslogtreecommitdiff
path: root/models/webhook_discord.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-21 11:36:19 -0500
committerUnknwon <u@gogs.io>2017-02-21 11:36:19 -0500
commit8216360da89bec1f3df75fe15ee57bfdcc290339 (patch)
tree3f92632e7353bc02f1cc3362a4aa31c38a954c1b /models/webhook_discord.go
parentc5b85f2733f6684b9efa1941d1a3f8dd2842a663 (diff)
webhook: support color for Discord
Diffstat (limited to 'models/webhook_discord.go')
-rw-r--r--models/webhook_discord.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/models/webhook_discord.go b/models/webhook_discord.go
index 820637fb..aa387fe6 100644
--- a/models/webhook_discord.go
+++ b/models/webhook_discord.go
@@ -7,6 +7,7 @@ package models
import (
"encoding/json"
"fmt"
+ "strconv"
"strings"
"github.com/gogits/git-module"
@@ -32,6 +33,7 @@ type DiscordEmbedObject struct {
Title string `json:"title"`
Description string `json:"description"`
URL string `json:"url"`
+ Color int `json:"color"`
Footer *DiscordEmbedFooterObject `json:"footer"`
Author *DiscordEmbedAuthorObject `json:"author"`
Fields []*DiscordEmbedFieldObject `json:"fields"`
@@ -70,11 +72,13 @@ func getDiscordCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*DiscordPa
refLink := DiscordLinkFormatter(p.Repo.HTMLURL+"/src/"+refName, refName)
content := fmt.Sprintf("Created new %s: %s/%s", p.RefType, repoLink, refLink)
+ color, _ := strconv.ParseInt(strings.TrimLeft(slack.Color, "#"), 16, 32)
return &DiscordPayload{
Username: slack.Username,
AvatarURL: slack.IconURL,
Embeds: []*DiscordEmbedObject{{
Description: content,
+ Color: int(color),
Author: &DiscordEmbedAuthorObject{
Name: p.Sender.UserName,
IconURL: p.Sender.AvatarUrl,
@@ -116,11 +120,13 @@ func getDiscordPushPayload(p *api.PushPayload, slack *SlackMeta) (*DiscordPayloa
}
}
+ color, _ := strconv.ParseInt(strings.TrimLeft(slack.Color, "#"), 16, 32)
return &DiscordPayload{
Username: slack.Username,
AvatarURL: slack.IconURL,
Embeds: []*DiscordEmbedObject{{
Description: content,
+ Color: int(color),
Author: &DiscordEmbedAuthorObject{
Name: p.Sender.UserName,
IconURL: p.Sender.AvatarUrl,
@@ -173,6 +179,7 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (
title = "Pull request synchronized: " + title
}
+ color, _ := strconv.ParseInt(strings.TrimLeft(slack.Color, "#"), 16, 32)
return &DiscordPayload{
Username: slack.Username,
AvatarURL: slack.IconURL,
@@ -180,6 +187,7 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (
Title: title,
Description: content,
URL: url,
+ Color: int(color),
Footer: &DiscordEmbedFooterObject{
Text: p.Repository.FullName,
},