Decrease inline limit for plugin message formating (#53358)

* Decrese in line limit for plugin message formating

Also truncate message blocks that still exceed max slack text block length

* Add link to slack docs explaining text block char limit
This commit is contained in:
Edward Dowling
2025-03-27 17:16:24 +00:00
committed by GitHub
parent ccffd6b5be
commit 55e187c560
4 changed files with 26 additions and 9 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ import (
// for message section texts, so we truncate all reasons to a generous but
// conservative limit
const (
requestInlineLimit = 500
requestInlineLimit = 400
requestReasonLimit
resolutionReasonLimit
ReviewReasonLimit
+2 -2
View File
@@ -164,7 +164,7 @@ func (s *DiscordSuiteOSS) TestMessagePosting() {
matches := requestReasonRegexp.FindAllStringSubmatch(messages[0].Text, -1)
require.Len(t, matches, 1)
require.Len(t, matches[0], 3)
assert.Equal(t, "because of "+strings.Repeat("A", 489), matches[0][1])
assert.Equal(t, "because of "+strings.Repeat("A", 389), matches[0][1])
assert.Equal(t, " (truncated)", matches[0][2])
status, err := parseMessageField(messages[0], "Status")
@@ -690,7 +690,7 @@ func (s *DiscordSuiteOSS) TestMessagePostingWithAMR() {
matches := requestReasonRegexp.FindAllStringSubmatch(messages[0].Text, -1)
require.Len(t, matches, 1)
require.Len(t, matches[0], 3)
assert.Equal(t, "because of "+strings.Repeat("A", 489), matches[0][1])
assert.Equal(t, "because of "+strings.Repeat("A", 389), matches[0][1])
assert.Equal(t, " (truncated)", matches[0][2])
status, err := parseMessageField(messages[0], "Status")
+21 -4
View File
@@ -41,6 +41,11 @@ import (
)
const slackMaxConns = 100
// textObjectMaxCharLimit is the max length for a slack 'text' object.
// See https://api.slack.com/reference/block-kit/composition-objects#text for more details.
const textObjectMaxCharLimit = 3000
const slackHTTPTimeout = 10 * time.Second
const statusEmitTimeout = 10 * time.Second
@@ -309,7 +314,7 @@ func (b Bot) slackAccessListReminderMsgSection(accessList *accesslist.AccessList
sections := []BlockItem{
NewBlockItem(SectionBlock{
Text: NewTextObjectItem(MarkdownObject{Text: msg}),
Text: NewTextObjectItem(MarkdownObject{Text: truncateTextObjectString(msg)}),
}),
}
@@ -348,7 +353,7 @@ func (b Bot) slackAccessListBatchedReminderMsgSection(accessLists []*accesslist.
sections := []BlockItem{
NewBlockItem(SectionBlock{
Text: NewTextObjectItem(MarkdownObject{Text: fmt.Sprintf("%d Access Lists are due for reviews, %s\n%s", numOfReviewsRequired, dueDate, link)}),
Text: NewTextObjectItem(MarkdownObject{Text: truncateTextObjectString(fmt.Sprintf("%d Access Lists are due for reviews, %s\n%s", numOfReviewsRequired, dueDate, link))}),
}),
}
@@ -365,14 +370,26 @@ func (b Bot) slackAccessRequestMsgSections(reqID string, reqData pd.AccessReques
Text: NewTextObjectItem(MarkdownObject{Text: "You have a new Role Request:"}),
}),
NewBlockItem(SectionBlock{
Text: NewTextObjectItem(MarkdownObject{Text: fields}),
Text: NewTextObjectItem(MarkdownObject{
Text: truncateTextObjectString(fields),
}),
}),
NewBlockItem(ContextBlock{
ElementItems: []ContextElementItem{
NewContextElementItem(MarkdownObject{Text: statusText}),
NewContextElementItem(MarkdownObject{
Text: truncateTextObjectString(statusText),
}),
},
}),
}
return sections
}
func truncateTextObjectString(s string) string {
truncateMsg := " (truncated)"
if len(s) <= textObjectMaxCharLimit {
return s
}
return s[:textObjectMaxCharLimit-len(truncateMsg)] + truncateMsg
}
+2 -2
View File
@@ -184,7 +184,7 @@ func (s *SlackSuiteOSS) TestMessagePosting() {
matches := requestReasonRegexp.FindAllStringSubmatch(block.Text.GetText(), -1)
require.Len(t, matches, 1)
require.Len(t, matches[0], 3)
assert.Equal(t, "because of "+strings.Repeat("A", 489), matches[0][1])
assert.Equal(t, "because of "+strings.Repeat("A", 389), matches[0][1])
assert.Equal(t, " (truncated)", matches[0][2])
statusLine, err := getStatusLine(messages[0])
@@ -494,7 +494,7 @@ func (s *SlackSuiteOSS) TestDenial() {
s.checkNewMessageUpdateByAPI(t, ctx, msgs, matchByTimestamp, func(t *testing.T, msgUpdate slack.Message) {
statusLine, err := getStatusLine(msgUpdate)
require.NoError(t, err)
assert.Equal(t, "*Status*: ❌ DENIED\n*Resolution reason*: ```\nnot okay "+strings.Repeat("A", 491)+"``` (truncated)", statusLine)
assert.Equal(t, "*Status*: ❌ DENIED\n*Resolution reason*: ```\nnot okay "+strings.Repeat("A", 391)+"``` (truncated)", statusLine)
})
}