Skip to content

Commit

Permalink
trim commit messages to single line in release messages
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Aug 12, 2024
1 parent bc1b6ce commit 303f1da
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions routes/github_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"regexp"
"strings"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/webhook"
"github.com/google/go-github/v44/github"

"github.com/disgoorg/disgo-butler/butler"
)

var (
Expand Down Expand Up @@ -96,19 +97,14 @@ func processReleaseEvent(b *butler.Butler, e *github.ReleaseEvent) error {
message += "\n\n__**Commits:**__\n"
out:
for _, commit := range comparison.Commits {
commitLines := strings.Split(commit.GetCommit().GetMessage(), "\n")
for i, commitLine := range commitLines {
shortId := "......."
if i == 0 {
shortId = substr(commit.GetSHA(), 0, 7)
}
line := fmt.Sprintf("[`%s`](%s) %s\n", shortId, commit.GetHTMLURL(), commitLine)
if len(message)+len(line) > 4068 {
message += "…"
break out
}
message += line
commitLine := strings.SplitN(commit.GetCommit().GetMessage(), "\n", 2)[0]
shortId := substr(commit.GetSHA(), 0, 7)
line := fmt.Sprintf("[`%s`](%s) %s\n", shortId, commit.GetHTMLURL(), commitLine)
if len(message)+len(line) > 4068 {
message += "…"
break out
}
message += line
}

msg, err := webhookClient.CreateMessage(discord.NewWebhookMessageCreateBuilder().
Expand Down

0 comments on commit 303f1da

Please sign in to comment.