Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
1f097f9f
Commit
1f097f9f
authored
5 months ago
by
Jano Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Limit blocks to 50 per message
parent
fac51e5f
No related branches found
No related tags found
1 merge request
!53
Slack utils
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
slack_utils/slack_utils.go
+45
-32
45 additions, 32 deletions
slack_utils/slack_utils.go
with
45 additions
and
32 deletions
slack_utils/slack_utils.go
+
45
−
32
View file @
1f097f9f
...
@@ -51,17 +51,26 @@ func (s *SlackClient) SendAlertWithFields(message string, channel string, slackF
...
@@ -51,17 +51,26 @@ func (s *SlackClient) SendAlertWithFields(message string, channel string, slackF
return
""
return
""
}
}
slackFieldsPerMessage
:=
lo
.
Chunk
(
slackFields
,
50
)
// Slack has a limit of 50 blocks per message
var
messageTimestamp
string
for
i
,
slackFieldsForMessage
:=
range
slackFieldsPerMessage
{
messageText
:=
message
if
len
(
slackFieldsPerMessage
)
>
1
{
messageText
=
fmt
.
Sprintf
(
"%s (%d/%d)"
,
message
,
i
+
1
,
len
(
slackFieldsPerMessage
))
}
blocks
:=
[]
slack
.
Block
{
slack
.
NewSectionBlock
(
slack
.
NewTextBlockObject
(
blocks
:=
[]
slack
.
Block
{
slack
.
NewSectionBlock
(
slack
.
NewTextBlockObject
(
"plain_text"
,
"plain_text"
,
message
,
message
Text
,
hasEmoji
(
message
),
hasEmoji
(
message
Text
),
false
),
false
),
nil
,
nil
,
nil
,
nil
,
),
),
}
}
slackFieldsChunked
:=
lo
.
Chunk
(
slackFields
,
2
)
slackFieldsChunked
:=
lo
.
Chunk
(
slackFields
ForMessage
,
2
)
for
_
,
slackFieldsChunk
:=
range
slackFieldsChunked
{
for
_
,
slackFieldsChunk
:=
range
slackFieldsChunked
{
fieldBlocksForChunk
:=
[]
*
slack
.
TextBlockObject
{}
fieldBlocksForChunk
:=
[]
*
slack
.
TextBlockObject
{}
...
@@ -92,7 +101,11 @@ func (s *SlackClient) SendAlertWithFields(message string, channel string, slackF
...
@@ -92,7 +101,11 @@ func (s *SlackClient) SendAlertWithFields(message string, channel string, slackF
slackMessageOptions
=
append
(
slackMessageOptions
,
slack
.
MsgOptionTS
(
parentMessageTimestamp
[
0
]))
slackMessageOptions
=
append
(
slackMessageOptions
,
slack
.
MsgOptionTS
(
parentMessageTimestamp
[
0
]))
}
}
return
s
.
postMessage
(
channel
,
slackMessageOptions
)
messageTimestamp
=
s
.
postMessage
(
channel
,
slackMessageOptions
)
}
// Return the last message timestamp
return
messageTimestamp
}
}
func
(
s
*
SlackClient
)
postMessage
(
channel
string
,
messageOptions
[]
slack
.
MsgOption
)
string
{
func
(
s
*
SlackClient
)
postMessage
(
channel
string
,
messageOptions
[]
slack
.
MsgOption
)
string
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment