Skip to content

Commit

Permalink
Add String methods for human-readable printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuixz committed Aug 16, 2024
1 parent e4e8ff8 commit 1b5aea8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/slack/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions pkg/slack/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b5aea8

Please sign in to comment.