aboutsummaryrefslogtreecommitdiffstats
path: root/services/webhook/discord_test.go
diff options
context:
space:
mode:
authorKemal Zebari <60799661+kemzeb@users.noreply.github.com>2024-11-07 11:56:53 -0800
committerGitHub <noreply@github.com>2024-11-07 19:56:53 +0000
commitfb030624780f426472b8464aac0d50228f93017a (patch)
treef544b8ed1aff6ea01771bb2e5f8654954d734e2a /services/webhook/discord_test.go
parent331e878e81d57235a53199383087c7649797a887 (diff)
downloadgitea-fb030624780f426472b8464aac0d50228f93017a.tar.gz
gitea-fb030624780f426472b8464aac0d50228f93017a.zip
Only provide the commit summary for Discord webhook push events (#32432)
Resolves #32371. #31970 should have just showed the commit summary, but `strings.SplitN()` was misused such that we did not perform any splitting at all and just used the message. This was not caught in the unit test made in that PR since the test commit summary was > 50 (which truncated away the commit description). This snapshot resolves this and adds another unit test to ensure that we only show the commit summary.
Diffstat (limited to 'services/webhook/discord_test.go')
-rw-r--r--services/webhook/discord_test.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/services/webhook/discord_test.go b/services/webhook/discord_test.go
index fbb4b24ef1..36b99d452e 100644
--- a/services/webhook/discord_test.go
+++ b/services/webhook/discord_test.go
@@ -80,7 +80,7 @@ func TestDiscordPayload(t *testing.T) {
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
})
- t.Run("PushWithLongCommitMessage", func(t *testing.T) {
+ t.Run("PushWithMultilineCommitMessage", func(t *testing.T) {
p := pushTestMultilineCommitMessagePayload()
pl, err := dc.Push(p)
@@ -88,6 +88,20 @@ func TestDiscordPayload(t *testing.T) {
assert.Len(t, pl.Embeds, 1)
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
+ assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) chore: This is a commit summary - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) chore: This is a commit summary - user1", pl.Embeds[0].Description)
+ assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
+ assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
+ assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
+ })
+
+ t.Run("PushWithLongCommitSummary", func(t *testing.T) {
+ p := pushTestPayloadWithCommitMessage("This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好 ⚠️⚠️️\n\nThis is the message body")
+
+ pl, err := dc.Push(p)
+ require.NoError(t, err)
+
+ assert.Len(t, pl.Embeds, 1)
+ assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1", pl.Embeds[0].Description)
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)