Skip to content

Commit

Permalink
add service info for slack notification
Browse files Browse the repository at this point in the history
  • Loading branch information
skahack committed Mar 15, 2017
1 parent 528a47a commit 7e2ada9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func NewDeployCommand(out, errOut io.Writer) *cobra.Command {
err := f.execute(cmd, args, out)
if err != nil {
sendFailedMessage(
f.cluster,
f.serviceName,
fmt.Sprintf("failed to deploy. cluster: %s, serviceName: %s\n", f.cluster, f.serviceName),
nil,
f.slackNotify,
Expand Down Expand Up @@ -108,6 +110,8 @@ func (f *deployCmd) execute(_ *cobra.Command, args []string, out io.Writer) erro
}

sendMessage(
f.cluster,
f.serviceName,
fmt.Sprintf("task definition registerd successfully: revision %d -> %d\n", *taskDef.Revision, *newTaskDef.Revision),
out,
f.slackNotify,
Expand All @@ -119,6 +123,8 @@ func (f *deployCmd) execute(_ *cobra.Command, args []string, out io.Writer) erro
}

sendMessage(
f.cluster,
f.serviceName,
fmt.Sprintf("service updating\n"),
out,
f.slackNotify,
Expand All @@ -130,6 +136,8 @@ func (f *deployCmd) execute(_ *cobra.Command, args []string, out io.Writer) erro
}

sendSuccessfulMessage(
f.cluster,
f.serviceName,
fmt.Sprintf("service updated successfully\n"),
out,
f.slackNotify,
Expand Down Expand Up @@ -240,7 +248,7 @@ func specifyRevision(revision int, arn string) (string, error) {
return re.ReplaceAllString(arn, fmt.Sprintf("${1}:%d", revision)), nil
}

func sendMessage(message string, out io.Writer, slackWebhookUrl string) {
func sendMessage(cluster, serviceName, message string, out io.Writer, slackWebhookUrl string) {
if out != nil {
fmt.Fprintf(out, message)
}
Expand All @@ -250,22 +258,22 @@ func sendMessage(message string, out io.Writer, slackWebhookUrl string) {
client := &slack.Client{WebhookURL: slackWebhookUrl}
payload := &slack.Payload{
Username: "deploy-bot",
Text: message,
Text: fmt.Sprintf("cluster: %s, serviceName: %s\n%s", cluster, serviceName, message),
}
client.Post(payload)
}()
}
}

func sendSuccessfulMessage(message string, out io.Writer, slackWebhookUrl string) {
sendEndMessage(true, message, out, slackWebhookUrl)
func sendSuccessfulMessage(cluster, serviceName, message string, out io.Writer, slackWebhookUrl string) {
sendEndMessage(true, cluster, serviceName, message, out, slackWebhookUrl)
}

func sendFailedMessage(message string, out io.Writer, slackWebhookUrl string) {
sendEndMessage(false, message, out, slackWebhookUrl)
func sendFailedMessage(cluster, serviceName, message string, out io.Writer, slackWebhookUrl string) {
sendEndMessage(false, cluster, serviceName, message, out, slackWebhookUrl)
}

func sendEndMessage(isSuccess bool, message string, out io.Writer, slackWebhookUrl string) {
func sendEndMessage(isSuccess bool, cluster, serviceName, message string, out io.Writer, slackWebhookUrl string) {
if out != nil {
fmt.Fprintf(out, message)
}
Expand All @@ -281,7 +289,7 @@ func sendEndMessage(isSuccess bool, message string, out io.Writer, slackWebhookU
client := &slack.Client{WebhookURL: slackWebhookUrl}
attachment := &slack.Attachment{
Color: color,
Text: message,
Text: fmt.Sprintf("cluster: %s, serviceName: %s\n%s", cluster, serviceName, message),
}
payload := &slack.Payload{
Username: "deploy-bot",
Expand Down

0 comments on commit 7e2ada9

Please sign in to comment.