Skip to content

Commit

Permalink
change the warning log if both of the webhookURL and API token are pr…
Browse files Browse the repository at this point in the history
…ovided (#55)

* change the warning log if both of the webhookURL and API token are provided; if both of them provided then use the API token and remove the webhookURL

* typo

* Update main.go

Co-Authored-By: Karol Wrótniak <[email protected]>

* Update main.go

Co-Authored-By: Karol Wrótniak <[email protected]>
  • Loading branch information
2 people authored and trapacska committed May 31, 2019
1 parent b1e4974 commit 178fc89
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func postMessage(conf Config, msg Message) error {
client := &http.Client{}

resp, err := client.Do(req)

if err != nil {
return fmt.Errorf("failed to send the request: %s", err)
}
Expand All @@ -145,13 +144,15 @@ func postMessage(conf Config, msg Message) error {
return nil
}

func validate(conf Config) error {
func validate(conf *Config) error {
if conf.APIToken == "" && conf.WebhookURL == "" {
return fmt.Errorf("Both API Token and WebhookURL is empty. You need to provide one of them. If you want to use incoming webhooks provide the webhook url. I you want to use a bot to send a message provide the bot API token")
return fmt.Errorf("Both API Token and WebhookURL are empty. You need to provide one of them. If you want to use incoming webhooks provide the webhook url. If you want to use a bot to send a message provide the bot API token")
}

if conf.APIToken != "" && conf.WebhookURL != "" {
log.Warnf("Both API Token and WebhookURL is provided. Using the webhook url")
log.Warnf("Both API Token and WebhookURL are provided. Using the API Token")
conf.WebhookURL = ""

}
return nil
}
Expand All @@ -165,7 +166,7 @@ func main() {
stepconf.Print(conf)
log.SetEnableDebugLog(conf.Debug)

if err := validate(conf); err != nil {
if err := validate(&conf); err != nil {
log.Errorf("Error: %s\n", err)
os.Exit(1)
}
Expand Down

0 comments on commit 178fc89

Please sign in to comment.