Skip to content

Commit aeb71f9

Browse files
authored
Merge branch 'main' into refactor-sidebar
2 parents f409dfa + fb03062 commit aeb71f9

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

services/webhook/discord.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
156156
// for each commit, generate attachment text
157157
for i, commit := range p.Commits {
158158
// limit the commit message display to just the summary, otherwise it would be hard to read
159-
message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 1)[0], "\r")
159+
message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 2)[0], "\r")
160160

161161
// a limit of 50 is set because GitHub does the same
162162
if utf8.RuneCountInString(message) > 50 {

services/webhook/discord_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,26 @@ func TestDiscordPayload(t *testing.T) {
8080
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
8181
})
8282

83-
t.Run("PushWithLongCommitMessage", func(t *testing.T) {
83+
t.Run("PushWithMultilineCommitMessage", func(t *testing.T) {
8484
p := pushTestMultilineCommitMessagePayload()
8585

8686
pl, err := dc.Push(p)
8787
require.NoError(t, err)
8888

89+
assert.Len(t, pl.Embeds, 1)
90+
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
91+
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)
92+
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
93+
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
94+
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
95+
})
96+
97+
t.Run("PushWithLongCommitSummary", func(t *testing.T) {
98+
p := pushTestPayloadWithCommitMessage("This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好 ⚠️⚠️️\n\nThis is the message body")
99+
100+
pl, err := dc.Push(p)
101+
require.NoError(t, err)
102+
89103
assert.Len(t, pl.Embeds, 1)
90104
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
91105
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)

services/webhook/general_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func pushTestPayload() *api.PushPayload {
6868
}
6969

7070
func pushTestMultilineCommitMessagePayload() *api.PushPayload {
71-
return pushTestPayloadWithCommitMessage("This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好 ⚠️⚠️️\n\nThis is the message body.")
71+
return pushTestPayloadWithCommitMessage("chore: This is a commit summary\n\nThis is a commit description.")
7272
}
7373

7474
func pushTestPayloadWithCommitMessage(message string) *api.PushPayload {

0 commit comments

Comments
 (0)