diff --git a/notifier/microsoftteamsnotifier/notifier.go b/notifier/microsoftteamsnotifier/notifier.go index 52c830a7325..62a6e9fdd43 100644 --- a/notifier/microsoftteamsnotifier/notifier.go +++ b/notifier/microsoftteamsnotifier/notifier.go @@ -3,6 +3,7 @@ package microsoftteamsnotifier import ( "fmt" "os" + "sort" "strings" goteamsnotify "github.com/atc0005/go-teams-notify/v2" @@ -37,15 +38,35 @@ func (c *Notifier) Notify(diff notifier.DiffCache) error { func convertToMicrosoftTeamsMessage(diffCache notifier.DiffCache) string { hostname, _ := os.Hostname() msgText := fmt.Sprintf("Changes detected in your feature flag file on: **%s**", hostname) - for key := range diffCache.Deleted { + + // Deleted + deletedKeys := make([]string, 0, len(diffCache.Deleted)) + for k := range diffCache.Deleted { + deletedKeys = append(deletedKeys, k) + } + sort.Strings(deletedKeys) + for _, key := range deletedKeys { msgText += fmt.Sprintf("\n * ❌ Flag **%s** deleted", key) } - for key := range diffCache.Added { + // Added + addedKeys := make([]string, 0, len(diffCache.Added)) + for k := range diffCache.Added { + addedKeys = append(addedKeys, k) + } + sort.Strings(addedKeys) + for _, key := range addedKeys { msgText += fmt.Sprintf("\n * 🆕 Flag **%s** created", key) } - for key, value := range diffCache.Updated { + // Updated + updatedKeys := make([]string, 0, len(diffCache.Updated)) + for k := range diffCache.Updated { + updatedKeys = append(updatedKeys, k) + } + sort.Strings(updatedKeys) + for _, key := range updatedKeys { + value := diffCache.Updated[key] msgText += fmt.Sprintf("\n * ✏️ Flag **%s** updated", key) changelog, _ := diff.Diff(value.Before, value.After, diff.AllowTypeMismatch(true)) for _, change := range changelog {