Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object kind to messages #124

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/notifier/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *Discord) Post(event recorder.Event) error {

a := SlackAttachment{
Color: color,
AuthorName: fmt.Sprintf("%s.%s", event.InvolvedObject.Name, event.InvolvedObject.Namespace),
AuthorName: fmt.Sprintf("%s/%s.%s", strings.ToLower(event.InvolvedObject.Kind), event.InvolvedObject.Name, event.InvolvedObject.Namespace),
Text: event.Message,
MrkdwnIn: []string{"text"},
Fields: sfields,
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDiscord_Post(t *testing.T) {
var payload = SlackPayload{}
err = json.Unmarshal(b, &payload)
require.NoError(t, err)
require.Equal(t, "webapp.gitops-system", payload.Attachments[0].AuthorName)
require.Equal(t, "gitrepository/webapp.gitops-system", payload.Attachments[0].AuthorName)
require.Equal(t, "metadata", payload.Attachments[0].Fields[0].Value)
}))
defer ts.Close()
Expand Down
3 changes: 2 additions & 1 deletion internal/notifier/rocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"net/url"
"strings"

"github.com/fluxcd/pkg/recorder"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ func (s *Rocket) Post(event recorder.Event) error {

a := SlackAttachment{
Color: color,
AuthorName: fmt.Sprintf("%s.%s", event.InvolvedObject.Name, event.InvolvedObject.Namespace),
AuthorName: fmt.Sprintf("%s/%s.%s", strings.ToLower(event.InvolvedObject.Kind), event.InvolvedObject.Name, event.InvolvedObject.Namespace),
Text: event.Message,
MrkdwnIn: []string{"text"},
Fields: sfields,
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/rocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRocket_Post(t *testing.T) {
var payload = SlackPayload{}
err = json.Unmarshal(b, &payload)
require.NoError(t, err)
require.Equal(t, "webapp.gitops-system", payload.Attachments[0].AuthorName)
require.Equal(t, "gitrepository/webapp.gitops-system", payload.Attachments[0].AuthorName)
require.Equal(t, "metadata", payload.Attachments[0].Fields[0].Value)
}))
defer ts.Close()
Expand Down
3 changes: 2 additions & 1 deletion internal/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"net/url"
"strings"

"github.com/fluxcd/pkg/recorder"
)
Expand Down Expand Up @@ -103,7 +104,7 @@ func (s *Slack) Post(event recorder.Event) error {

a := SlackAttachment{
Color: color,
AuthorName: fmt.Sprintf("%s.%s", event.InvolvedObject.Name, event.InvolvedObject.Namespace),
AuthorName: fmt.Sprintf("%s/%s.%s", strings.ToLower(event.InvolvedObject.Kind), event.InvolvedObject.Name, event.InvolvedObject.Namespace),
Text: event.Message,
MrkdwnIn: []string{"text"},
Fields: sfields,
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSlack_Post(t *testing.T) {
var payload = SlackPayload{}
err = json.Unmarshal(b, &payload)
require.NoError(t, err)
require.Equal(t, "webapp.gitops-system", payload.Attachments[0].AuthorName)
require.Equal(t, "gitrepository/webapp.gitops-system", payload.Attachments[0].AuthorName)
require.Equal(t, "metadata", payload.Attachments[0].Fields[0].Value)
}))
defer ts.Close()
Expand Down
3 changes: 2 additions & 1 deletion internal/notifier/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package notifier
import (
"fmt"
"net/url"
"strings"

"github.com/fluxcd/pkg/recorder"
)
Expand Down Expand Up @@ -78,7 +79,7 @@ func (s *MSTeams) Post(event recorder.Event) error {
})
}

objName := fmt.Sprintf("%s.%s", event.InvolvedObject.Name, event.InvolvedObject.Namespace)
objName := fmt.Sprintf("%s/%s.%s", strings.ToLower(event.InvolvedObject.Kind), event.InvolvedObject.Name, event.InvolvedObject.Namespace)
payload := MSTeamsPayload{
Type: "MessageCard",
Context: "http://schema.org/extensions",
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestTeams_Post(t *testing.T) {
err = json.Unmarshal(b, &payload)
require.NoError(t, err)

require.Equal(t, "webapp.gitops-system", payload.Sections[0].ActivitySubtitle)
require.Equal(t, "gitrepository/webapp.gitops-system", payload.Sections[0].ActivitySubtitle)
require.Equal(t, "metadata", payload.Sections[0].Facts[0].Value)
}))
defer ts.Close()
Expand Down