@@ -6,11 +6,27 @@ import (
6
6
"encoding/json"
7
7
"errors"
8
8
"fmt"
9
+ "log/slog"
9
10
"net/http"
10
11
"strings"
11
12
"time"
12
13
)
13
14
15
+ var kindPluralToSingular = map [string ]string {
16
+ "alerts" : "alert" ,
17
+ "buckets" : "bucket" ,
18
+ "gitrepositories" : "gitrepository" ,
19
+ "helmcharts" : "helmchart" ,
20
+ "helmreleases" : "helmrelease" ,
21
+ "imagepolicies" : "imagepolicy" ,
22
+ "imagerepositories" : "imagerepository" ,
23
+ "imageupdateautomations" : "imageupdateautomation" ,
24
+ "kustomizations" : "kustomization" ,
25
+ "ocirepositories" : "ocirepository" ,
26
+ "providers" : "provider" ,
27
+ "receivers" : "receiver" ,
28
+ }
29
+
14
30
// SlackNotifier sends notifications to Slack via a webhook
15
31
type SlackNotifier struct {
16
32
client * http.Client
@@ -65,7 +81,7 @@ func (sn *SlackNotifier) Notify(ctx context.Context, notif Notification) error {
65
81
color = "good"
66
82
}
67
83
68
- kind := strings . TrimSuffix (notif .Resource .Type .Kind , "s" )
84
+ kind := singularKind (notif .Resource .Type .Kind )
69
85
70
86
reqBody , err := json .Marshal (SlackWebhook {
71
87
Attachments : []SlackAttachment {
@@ -104,3 +120,12 @@ func (sn *SlackNotifier) Notify(ctx context.Context, notif Notification) error {
104
120
}
105
121
return nil
106
122
}
123
+
124
+ func singularKind (pluralKind string ) string {
125
+ singular , found := kindPluralToSingular [strings .ToLower (pluralKind )]
126
+ if found {
127
+ return singular
128
+ }
129
+ slog .Warn ("unrecognized kind" , slog .String ("kind" , pluralKind ))
130
+ return strings .TrimSuffix (pluralKind , "s" ) // best effort
131
+ }
0 commit comments