Skip to content

Commit 710e725

Browse files
committed
Fix mapping of plural to singular kind
1 parent 5c0bcb7 commit 710e725

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

internal/notification/slack.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"log/slog"
910
"net/http"
1011
"strings"
1112
"time"
1213
)
1314

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+
1430
// SlackNotifier sends notifications to Slack via a webhook
1531
type SlackNotifier struct {
1632
client *http.Client
@@ -65,7 +81,7 @@ func (sn *SlackNotifier) Notify(ctx context.Context, notif Notification) error {
6581
color = "good"
6682
}
6783

68-
kind := strings.TrimSuffix(notif.Resource.Type.Kind, "s")
84+
kind := singularKind(notif.Resource.Type.Kind)
6985

7086
reqBody, err := json.Marshal(SlackWebhook{
7187
Attachments: []SlackAttachment{
@@ -104,3 +120,12 @@ func (sn *SlackNotifier) Notify(ctx context.Context, notif Notification) error {
104120
}
105121
return nil
106122
}
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

Comments
 (0)