Skip to content

Commit

Permalink
allow a different webhook to be used to send messages on build failur…
Browse files Browse the repository at this point in the history
…es (#76)

Co-authored-by: Olivér Falvai <[email protected]>
  • Loading branch information
weedmapsmike and ofalvai authored Sep 30, 2021
1 parent b76c350 commit d3ce902
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
29 changes: 15 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ type Config struct {
Debug bool `env:"is_debug_mode,opt[yes,no]"`

// Message
WebhookURL stepconf.Secret `env:"webhook_url"`
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"`

// Attachment
Color string `env:"color,required"`
Expand Down Expand Up @@ -109,7 +110,7 @@ func postMessage(conf Config, msg Message) error {
}
log.Debugf("Request to Slack: %s\n", b)

url := strings.TrimSpace(string(conf.WebhookURL))
url := strings.TrimSpace(selectValue(string(conf.WebhookURL), string(conf.WebhookURLOnError)))
if url == "" {
url = "https://slack.com/api/chat.postMessage"
}
Expand Down
9 changes: 9 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ inputs:
To register an **Incoming WebHook integration** visit: https://api.slack.com/incoming-webhooks
is_required: false
is_sensitive: true
- webhook_url_on_error:
opts:
title: "Slack Webhook URL (Webhook or API token is required) if the build failed"
description: |
**Either webhook\_url or api\_token input is required.**
To register an **Incoming WebHook integration** visit: https://api.slack.com/incoming-webhooks
is_required: false
is_sensitive: true
category: If Build Failed
- api_token:
opts:
title: "Slack API token (Webhook or API token is required)"
Expand Down

0 comments on commit d3ce902

Please sign in to comment.