aboutsummaryrefslogtreecommitdiffstats
path: root/services/webhook/discord.go
diff options
context:
space:
mode:
authorKemal Zebari <60799661+kemzeb@users.noreply.github.com>2024-09-23 20:38:08 -0700
committerGitHub <noreply@github.com>2024-09-24 03:38:08 +0000
commitaadbe0488f454b9f7f5a56765f4530f9d1e2c6ec (patch)
treeefcfb644451a884c4b5de87ae9231bac605ac452 /services/webhook/discord.go
parent2c6fa6c1e05437b5515c7be4f516ac4e4a59bf3c (diff)
downloadgitea-aadbe0488f454b9f7f5a56765f4530f9d1e2c6ec.tar.gz
gitea-aadbe0488f454b9f7f5a56765f4530f9d1e2c6ec.zip
Truncate commit message during Discord webhook push events (#31970)
Resolves #31668.
Diffstat (limited to 'services/webhook/discord.go')
-rw-r--r--services/webhook/discord.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/services/webhook/discord.go b/services/webhook/discord.go
index f27b39dac3..59e87a7e1f 100644
--- a/services/webhook/discord.go
+++ b/services/webhook/discord.go
@@ -11,6 +11,7 @@ import (
"net/url"
"strconv"
"strings"
+ "unicode/utf8"
webhook_model "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git"
@@ -154,8 +155,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
var text string
// for each commit, generate attachment text
for i, commit := range p.Commits {
- text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL,
- strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)
+ // limit the commit message display to just the summary, otherwise it would be hard to read
+ message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 1)[0], "\r")
+
+ // a limit of 50 is set because GitHub does the same
+ if utf8.RuneCountInString(message) > 50 {
+ message = fmt.Sprintf("%.47s...", message)
+ }
+ text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)
// add linebreak to each commit but the last
if i < len(p.Commits)-1 {
text += "\n"