Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Allow for posting to multiple slack channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven E. Newton committed Feb 15, 2019
1 parent 8b051a2 commit 3e7bf11
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions ankh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func reconcileMissingConfigs(ctx *ankh.ExecutionContext, ankhFile *ankh.AnkhFile
}

// we should finally have a tag value
if ctx.SlackChannel != "" {
if len(ctx.SlackChannels) > 0 {
ctx.SlackDeploymentVersion = *chart.Tag
}
}
Expand Down Expand Up @@ -414,7 +414,7 @@ func execute(ctx *ankh.ExecutionContext) {
executeContext(ctx, &rootAnkhFile)
}

if ctx.SlackChannel != "" {
if len(ctx.SlackChannels) > 0 {
if ctx.Mode == ankh.Rollback {
ctx.SlackDeploymentVersion = "rollback"
}
Expand Down Expand Up @@ -889,7 +889,7 @@ func main() {
ctx.LocalChart = true
}
ctx.Mode = ankh.Apply
ctx.SlackChannel = *slackChannel
ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel)
ctx.SlackMessageOverride = *slackMessageOverride
filters := []string{}
for _, filter := range *filter {
Expand Down Expand Up @@ -921,7 +921,7 @@ func main() {
ctx.LocalChart = true
}
ctx.Mode = ankh.Rollback
ctx.SlackChannel = *slackChannel
ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel)
ctx.SlackMessageOverride = *slackMessageOverride
ctx.Filters = []string{"deployment", "statfulset"}

Expand Down
4 changes: 2 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type ExecutionContext struct {
DataDir string
HelmSetValues map[string]string

SlackChannel string
SlackChannels []string
SlackMessageOverride string
SlackDeploymentVersion string

Expand All @@ -78,7 +78,7 @@ type Context struct {
Release string `yaml:"release,omitempty"`
HelmRegistryURL string `yaml:"helm-registry-url,omitempty"` // deprecated in favor of top-level config `helm.registry`
ClusterAdminUnused bool `yaml:"cluster-admin,omitempty"` // deprecated
Global map[string]interface{} `yaml:"global",omitempty"`
Global map[string]interface{} `yaml:"global,omitempty"`
}

// An Environment is a collection of contexts over which operations should be applied
Expand Down
26 changes: 16 additions & 10 deletions slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,22 @@ func PingSlackChannel(ctx *ankh.ExecutionContext) error {
Username: username,
}

channelId, err := getSlackChannelIDByName(api, ctx.SlackChannel)
if err != nil {
return err
}

if !ctx.DryRun {
_, _, err = api.PostMessage(channelId, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams))
} else {
ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, ctx.SlackChannel)
}
channels := make(map[string]string, len(ctx.SlackChannels))
for _, ch := range ctx.SlackChannels {
channelId, err := getSlackChannelIDByName(api, ch)
if err != nil {
return err
}
channels[ch] = channelId
}

for name, id := range channels {
if !ctx.DryRun {
_, _, err = api.PostMessage(id, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams))
} else {
ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, name)
}
}

return err
}
Expand Down

0 comments on commit 3e7bf11

Please sign in to comment.