diff --git a/main.go b/main.go index 6da8045..1c26ba6 100644 --- a/main.go +++ b/main.go @@ -19,20 +19,24 @@ type Config struct { Debug bool `env:"is_debug_mode,opt[yes,no]"` // Message - WebhookURL stepconf.Secret `env:"webhook_url"` - WebhookURLOnError stepconf.Secret `env:"webhook_url_on_error"` - APIToken stepconf.Secret `env:"api_token"` - Channel string `env:"channel"` - ChannelOnError string `env:"channel_on_error"` - Text string `env:"text"` - TextOnError string `env:"text_on_error"` - IconEmoji string `env:"emoji"` - IconEmojiOnError string `env:"emoji_on_error"` - IconURL string `env:"icon_url"` - IconURLOnError string `env:"icon_url_on_error"` - LinkNames bool `env:"link_names,opt[yes,no]"` - Username string `env:"from_username"` - UsernameOnError string `env:"from_username_on_error"` + WebhookURL stepconf.Secret `env:"webhook_url"` + WebhookURLOnError stepconf.Secret `env:"webhook_url_on_error"` + APIToken stepconf.Secret `env:"api_token"` + Channel string `env:"channel"` + ChannelOnError string `env:"channel_on_error"` + Text string `env:"text"` + TextOnError string `env:"text_on_error"` + IconEmoji string `env:"emoji"` + IconEmojiOnError string `env:"emoji_on_error"` + IconURL string `env:"icon_url"` + IconURLOnError string `env:"icon_url_on_error"` + LinkNames bool `env:"link_names,opt[yes,no]"` + Username string `env:"from_username"` + UsernameOnError string `env:"from_username_on_error"` + ThreadTs string `env:"thread_ts"` + ThreadTsOnError string `env:"thread_ts_on_error"` + ReplyBroadcast bool `env:"reply_broadcast,opt[yes,no]"` + ReplyBroadcastOnError bool `env:"reply_broadcast_on_error,opt[yes,no]"` // Attachment Color string `env:"color,required"` @@ -67,6 +71,14 @@ func selectValue(ifSuccess, ifFailed string) string { return ifFailed } +// selectBool chooses the right boolean value based on the result of the build. +func selectBool(ifSuccess, ifFailed bool) bool { + if success { + return ifSuccess + } + return ifFailed +} + // ensureNewlines replaces all \n substrings with newline characters. func ensureNewlines(s string) string { return strings.Replace(s, "\\n", "\n", -1) @@ -91,10 +103,12 @@ func newMessage(c Config) Message { FooterIcon: c.FooterIcon, Buttons: parseButtons(c.Buttons), }}, - IconEmoji: selectValue(c.IconEmoji, c.IconEmojiOnError), - IconURL: selectValue(c.IconURL, c.IconURLOnError), - LinkNames: c.LinkNames, - Username: selectValue(c.Username, c.UsernameOnError), + IconEmoji: selectValue(c.IconEmoji, c.IconEmojiOnError), + IconURL: selectValue(c.IconURL, c.IconURLOnError), + LinkNames: c.LinkNames, + Username: selectValue(c.Username, c.UsernameOnError), + ThreadTs: selectValue(c.ThreadTs, c.ThreadTsOnError), + ReplyBroadcast: selectBool(c.ReplyBroadcast, c.ReplyBroadcastOnError), } if c.TimeStamp { msg.Attachments[0].TimeStamp = int(time.Now().Unix()) diff --git a/message.go b/message.go index 0115405..5440cc8 100644 --- a/message.go +++ b/message.go @@ -30,6 +30,12 @@ type Message struct { // Username specifies the bot's username for the message. Username string `json:"username,omitempty"` + + // Provide another message's ts value to make this message a reply. + ThreadTs string `json:"thread_ts,omitempty"` + + // Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation. + ReplyBroadcast bool `json:"reply_broadcast,omitempty"` } // Attachment adds more context to a slack chat message. diff --git a/step.yml b/step.yml index f70683f..497eca9 100644 --- a/step.yml +++ b/step.yml @@ -177,6 +177,31 @@ inputs: leave this option empty then the default one will be used. category: If Build Failed + - thread_ts: + opts: + title: Thread Timestamp + description: Sends the message as a reply to the message with the given ts if set (in a thread). + - thread_ts_on_error: + opts: + title: Thread Timestamp if the build failed + description: Sends the message as a reply to the message with the given ts if set (in a thread) if the build failed. + category: If Build Failed + - reply_broadcast: "no" + opts: + title: Reply Broadcast + description: Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation + value_options: + - "yes" + - "no" + - reply_broadcast_on_error: "no" + opts: + title: Reply Broadcast if the build failed + description: Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation + category: If Build Failed + value_options: + - "yes" + - "no" + # Attachment inputs - color: "#3bc3a3"