Skip to content

Commit

Permalink
Support conclusion filter when sending slack message oursky#16
Browse files Browse the repository at this point in the history
  • Loading branch information
josephchow102 committed Feb 6, 2023
1 parent 0824a21 commit f2fd984
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/slack/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (a *App) AddChannel(ctx context.Context, repo string, channelInfo ChannelIn
return err
}

// Ref: https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run--parameters
supportedConclusions := []string{"action_required", "cancelled", "failure", "neutral", "success", "skipped", "stale", "timed_out"}
unsupportedConclusions := []string{}
for _, c := range channelInfo.conclusions {
Expand Down
15 changes: 9 additions & 6 deletions pkg/slack/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/slack-go/slack/slackutilsx"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"k8s.io/utils/strings/slices"
)

type JobsState interface {
Expand Down Expand Up @@ -158,12 +159,14 @@ func (n *Notifier) notify(ctx context.Context, run *jobs.WorkflowRun) {
}

for _, channel := range channels {
err := n.app.SendMessage(ctx, channel.channelID, slack.MsgOptionAttachments(slackMsg))
if err != nil {
n.logger.Warn("failed to send message",
zap.Error(err),
zap.String("channelID", channel.channelID),
)
if len(channel.conclusions) == 0 || slices.Contains(channel.conclusions, run.Conclusion) {
err := n.app.SendMessage(ctx, channel.channelID, slack.MsgOptionAttachments(slackMsg))
if err != nil {
n.logger.Warn("failed to send message",
zap.Error(err),
zap.String("channelID", channel.channelID),
)
}
}
}
}

0 comments on commit f2fd984

Please sign in to comment.