44 "bytes"
55 "context"
66 "crypto/tls"
7+ "errors"
78 "fmt"
89 "io"
910 "net/http"
@@ -48,8 +49,8 @@ type hookQueueItem struct {
4849
4950// Errors produced by this file.
5051var (
51- ErrInvalidStatus = fmt . Errorf ("invalid HTTP status reply" )
52- ErrWebhookNoURL = fmt . Errorf ("webhook without a URL configured; fix it" )
52+ ErrInvalidStatus = errors . New ("invalid HTTP status reply" )
53+ ErrWebhookNoURL = errors . New ("webhook without a URL configured; fix it" )
5354)
5455
5556// ExtractStatuses allows us to create a custom environment variable unmarshaller.
@@ -174,8 +175,13 @@ func (u *Unpackerr) sendWebhookWithLog(hook *WebhookConfig, payload *WebhookPayl
174175
175176// Send marshals an interface{} into json and POSTs it to a URL.
176177func (w * WebhookConfig ) Send (body io.Reader ) ([]byte , error ) {
178+ if w .URL == "" {
179+ return nil , ErrWebhookNoURL
180+ }
181+
177182 w .Lock ()
178183 defer w .Unlock ()
184+
179185 w .posts ++
180186
181187 ctx , cancel := context .WithTimeout (context .Background (), w .Timeout .Duration + time .Second )
@@ -195,7 +201,7 @@ func (w *WebhookConfig) send(ctx context.Context, body io.Reader) ([]byte, error
195201 return nil , fmt .Errorf ("creating request: %w" , err )
196202 }
197203
198- req .Header .Set ("content-type " , w .CType )
204+ req .Header .Set ("Content-Type " , w .CType )
199205
200206 res , err := w .client .Do (req )
201207 if err != nil {
@@ -266,24 +272,24 @@ func (u *Unpackerr) logWebhook() {
266272 pfx = " => Webhook Config: 1 URL"
267273 } else {
268274 u .Printf (" => Webhook Configs: %d URLs" , len (u .Webhook ))
269- pfx = " => URL"
275+ pfx = " => URL" //nolint:wsl
270276 }
271277
272278 for _ , f := range u .Webhook {
273279 if ex = "" ; f .TmplPath != "" {
274- ex = fmt . Sprintf ( ", template: %s , content_type: %s" , f . TmplPath , f .CType )
280+ ex = ", template: " + f . TmplPath + " , content_type: " + f .CType
275281 }
276282
277283 if f .Channel != "" {
278- ex += fmt . Sprintf ( ", channel: %s" , f .Channel )
284+ ex += ", channel: " + f .Channel
279285 }
280286
281287 if f .Nickname != "" {
282- ex += fmt . Sprintf ( ", nickname: %s" , f .Nickname )
288+ ex += ", nickname: " + f .Nickname
283289 }
284290
285291 if len (f .Exclude ) > 0 {
286- ex += fmt . Sprintf ( ", exclude: %q" , strings .Join (f .Exclude , "; " ))
292+ ex += ", exclude: \" " + strings .Join (f .Exclude , "; " ) + `"`
287293 }
288294
289295 u .Printf ("%s: %s, timeout: %v, ignore ssl: %v, silent: %v%s, events: %q" ,
0 commit comments