Skip to content

Commit

Permalink
Added a fallback text to Slack Webhook message call to hint Slack for…
Browse files Browse the repository at this point in the history
… output where rich text formatting is not available
  • Loading branch information
onix committed Jul 11, 2023
1 parent 603e6b4 commit e83dab3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion slack/main.go
Expand Up @@ -113,13 +113,17 @@ func (s *slackNotifier) writeMessage() (*slack.WebhookMessage, error) {
}

var clr string
var msgText
switch build.Status {
case cbpb.Build_SUCCESS:
clr = "#22bb33"
msgText = "Build success!"
case cbpb.Build_FAILURE, cbpb.Build_INTERNAL_ERROR, cbpb.Build_TIMEOUT:
clr = "#bb2124"
msgText = "Build failed or error occurred"
default:
clr = "#f0ad4e"
msgText = "Build finished with unexpected status"
}

var buf bytes.Buffer
Expand All @@ -133,5 +137,5 @@ func (s *slackNotifier) writeMessage() (*slack.WebhookMessage, error) {
return nil, fmt.Errorf("failed to unmarshal templating JSON: %w", err)
}

return &slack.WebhookMessage{Attachments: []slack.Attachment{{Color: clr, Blocks: blocks}}}, nil
return &slack.WebhookMessage{Attachments: []slack.Attachment{{Color: clr, Blocks: blocks}}, Text: msgText}, nil
}
1 change: 1 addition & 0 deletions slack/main_test.go
Expand Up @@ -97,6 +97,7 @@ func TestWriteMessage(t *testing.T) {
},
},
}},
Text: "Build success!"
}

if diff := cmp.Diff(got, want); diff != "" {
Expand Down

0 comments on commit e83dab3

Please sign in to comment.