mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 15:20:01 +01:00
webhook: minor improvements on Discord
This commit is contained in:
2
gogs.go
2
gogs.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.164.0220 / 0.10 RC"
|
const APP_VER = "0.9.165.0220 / 0.10 RC"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
|
|
||||||
"github.com/gogits/git-module"
|
"github.com/gogits/git-module"
|
||||||
api "github.com/gogits/go-gogs-client"
|
api "github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiscordEmbedFooterObject struct {
|
type DiscordEmbedFooterObject struct {
|
||||||
@@ -56,6 +58,10 @@ func (p *DiscordPayload) JSONPayload() ([]byte, error) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DiscordTextFormatter(s string) string {
|
||||||
|
return strings.Split(s, "\n")[0]
|
||||||
|
}
|
||||||
|
|
||||||
func DiscordLinkFormatter(url string, text string) string {
|
func DiscordLinkFormatter(url string, text string) string {
|
||||||
return fmt.Sprintf("[%s](%s)", text, url)
|
return fmt.Sprintf("[%s](%s)", text, url)
|
||||||
}
|
}
|
||||||
@@ -78,6 +84,7 @@ func getDiscordCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*DiscordPa
|
|||||||
AvatarURL: slack.IconURL,
|
AvatarURL: slack.IconURL,
|
||||||
Embeds: []*DiscordEmbedObject{{
|
Embeds: []*DiscordEmbedObject{{
|
||||||
Description: content,
|
Description: content,
|
||||||
|
URL: setting.AppUrl + p.Sender.UserName,
|
||||||
Color: int(color),
|
Color: int(color),
|
||||||
Author: &DiscordEmbedAuthorObject{
|
Author: &DiscordEmbedAuthorObject{
|
||||||
Name: p.Sender.UserName,
|
Name: p.Sender.UserName,
|
||||||
@@ -113,7 +120,7 @@ func getDiscordPushPayload(p *api.PushPayload, slack *SlackMeta) (*DiscordPayloa
|
|||||||
|
|
||||||
// for each commit, generate attachment text
|
// for each commit, generate attachment text
|
||||||
for i, commit := range p.Commits {
|
for i, commit := range p.Commits {
|
||||||
content += fmt.Sprintf("%s %s - %s", DiscordSHALinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), commit.Author.Name)
|
content += fmt.Sprintf("%s %s - %s", DiscordSHALinkFormatter(commit.URL, commit.ID[:7]), DiscordTextFormatter(commit.Message), commit.Author.Name)
|
||||||
// add linebreak to each commit but the last
|
// add linebreak to each commit but the last
|
||||||
if i < len(p.Commits)-1 {
|
if i < len(p.Commits)-1 {
|
||||||
content += "\n"
|
content += "\n"
|
||||||
@@ -126,6 +133,7 @@ func getDiscordPushPayload(p *api.PushPayload, slack *SlackMeta) (*DiscordPayloa
|
|||||||
AvatarURL: slack.IconURL,
|
AvatarURL: slack.IconURL,
|
||||||
Embeds: []*DiscordEmbedObject{{
|
Embeds: []*DiscordEmbedObject{{
|
||||||
Description: content,
|
Description: content,
|
||||||
|
URL: setting.AppUrl + p.Sender.UserName,
|
||||||
Color: int(color),
|
Color: int(color),
|
||||||
Author: &DiscordEmbedAuthorObject{
|
Author: &DiscordEmbedAuthorObject{
|
||||||
Name: p.Sender.UserName,
|
Name: p.Sender.UserName,
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.9.164.0220 / 0.10 RC
|
0.9.165.0220 / 0.10 RC
|
||||||
Reference in New Issue
Block a user