diff --git a/pkg/slack/app.go b/pkg/slack/app.go index 10bdd3a..1fa68b8 100644 --- a/pkg/slack/app.go +++ b/pkg/slack/app.go @@ -36,6 +36,13 @@ type exposedChannelInfo struct { Conclusions []string `json:"messageFilters"` } +func (f ChannelInfo) String() string { + if len(f.conclusions) == 0 { + return f.channelID + } + return fmt.Sprintf("%s with %s", f.channelID, f.conclusions) +} + func (f ChannelInfo) MarshalJSON() ([]byte, error) { return json.Marshal(exposedChannelInfo{ ChannelID: f.channelID, diff --git a/pkg/slack/filter.go b/pkg/slack/filter.go index 5347a57..7edb0bb 100644 --- a/pkg/slack/filter.go +++ b/pkg/slack/filter.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/oursky/github-actions-manager/pkg/github/jobs" + "github.com/oursky/github-actions-manager/pkg/utils/array" "k8s.io/utils/strings/slices" ) @@ -24,6 +25,24 @@ type exposedMessageFilter struct { Whitelists []messageFilterRule `json:"filters"` } +func (rule messageFilterRule) String() string { + output := "" + if len(rule.Conclusions) > 0 { + output += fmt.Sprintf("conclusions: %s", rule.Conclusions) + } + if len(rule.Branches) > 0 { + output += fmt.Sprintf("branches: %s", rule.Branches) + } + if len(rule.Workflows) > 0 { + output += fmt.Sprintf("workflows: %s", rule.Workflows) + } + return output +} + +func (mf MessageFilter) String() string { + return fmt.Sprintf("whitelists: %s", array.CommaJoin(mf.whitelists)) +} + func (mf MessageFilter) MarshalJSON() ([]byte, error) { return json.Marshal(exposedMessageFilter{ Whitelists: mf.whitelists, @@ -52,6 +71,10 @@ func (rule messageFilterRule) Pass(run *jobs.WorkflowRun) bool { return true } +func (mf MessageFilter) Length() int { + return len(mf.whitelists) +} + func (mf MessageFilter) Any(run *jobs.WorkflowRun) bool { if len(mf.whitelists) == 0 { return true