diff --git a/config.go b/config.go index 10a405f..1ce5e00 100644 --- a/config.go +++ b/config.go @@ -29,6 +29,7 @@ type labels struct { type labelConfig struct { Priority string + Tags []string } func readConfig(path string) (*config, error) { @@ -101,6 +102,16 @@ func readConfig(path string) (*config, error) { } } + d = labelDir.Children.Get("tags") + if d != nil { + var tags string + if err := d.ParseParams(&tags); err != nil { + return nil, err + } + + labelConfig.Tags = strings.Split(tags, ",") + } + labels[fmt.Sprintf("%s:%s", labelName, name)] = *labelConfig } } diff --git a/functions.go b/functions.go new file mode 100644 index 0000000..8395f8e --- /dev/null +++ b/functions.go @@ -0,0 +1,11 @@ +package main + +func sliceContains(s []string, e string) bool { + for _, v := range s { + if e == v { + return true + } + } + + return false +} diff --git a/main.go b/main.go index c15dcf0..dc06fe2 100644 --- a/main.go +++ b/main.go @@ -100,6 +100,7 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) { req.Header.Set("X-Title", title) var priority string + var tags []string for _, labelName := range rcv.cfg.labels.Order { val, ok := event.CommonLabels[labelName] if !ok { @@ -114,12 +115,23 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) { if priority == "" { priority = labelConfig.Priority } + + for _, val := range labelConfig.Tags { + if !sliceContains(tags, val) { + tags = append(tags, val) + } + } } if priority != "" { req.Header.Set("X-Priority", priority) } + tagString := strings.Join(tags, ",") + if tagString != "" { + req.Header.Set("X-Tags", tagString) + } + resp, err := client.Do(req) if err != nil { rcv.logger.Error(err)