2020-10-29 22:09:02 +02:00
|
|
|
package webhook
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-octo-tasks/server/model"
|
|
|
|
"github.com/mattermost/mattermost-octo-tasks/server/services/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NotifyUpdate calls webhooks
|
2020-10-29 22:42:43 +02:00
|
|
|
func (wh *Client) NotifyUpdate(block model.Block) {
|
2020-10-29 22:32:51 +02:00
|
|
|
if len(wh.config.WebhookUpdate) < 1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-29 22:09:02 +02:00
|
|
|
json, err := json.Marshal(block)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("NotifyUpdate: json.Marshal", err)
|
|
|
|
}
|
|
|
|
for _, url := range wh.config.WebhookUpdate {
|
|
|
|
http.Post(url, "application/json", bytes.NewBuffer(json))
|
|
|
|
log.Printf("webhook.NotifyUpdate: %s", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 22:42:43 +02:00
|
|
|
// Client is a webhook client
|
|
|
|
type Client struct {
|
2020-10-29 22:09:02 +02:00
|
|
|
config *config.Configuration
|
|
|
|
}
|
|
|
|
|
2020-10-29 22:42:43 +02:00
|
|
|
// NewClient creates a new Client
|
|
|
|
func NewClient(config *config.Configuration) *Client {
|
|
|
|
return &Client{
|
2020-10-29 22:09:02 +02:00
|
|
|
config: config,
|
|
|
|
}
|
|
|
|
}
|