Skip to content

Commit

Permalink
CodeBuild Events support - add message color for `CodeBuild Build Sta…
Browse files Browse the repository at this point in the history
…te Change` type
  • Loading branch information
danilvalov committed Apr 24, 2024
1 parent 62402de commit 278c5c3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,34 @@ func (p *Plugin) createSNSCodeBuildEventNotificationAttachment(subject string, m
fields = addFields(fields, "Time", messageNotification.Time.Format(time.DateTime), true)
fields = addFields(fields, "Build ID", messageNotification.Detail.BuildID, true)

if len(messageNotification.Detail.BuildStatus) > 0 {
if messageNotification.DetailType == "CodeBuild Build State Change" {
fields = addFields(fields, "Build Status", messageNotification.Detail.BuildStatus, true)
}

if len(messageNotification.Detail.CompletedPhase) > 0 {
if messageNotification.DetailType == "CodeBuild Build Phase Change" {
fields = addFields(fields, "Current Phase", messageNotification.Detail.CurrentPhase, true)
fields = addFields(fields, "Current Phase Context", messageNotification.Detail.CurrentPhaseContext, true)
fields = addFields(fields, "Completed Phase", messageNotification.Detail.CompletedPhase, true)
fields = addFields(fields, "Completed Phase Context", messageNotification.Detail.CompletedPhaseContext, true)
}

var msgColor string
if messageNotification.DetailType == "CodeBuild Build State Change" {
if messageNotification.Detail.BuildStatus == "FAILED" || messageNotification.Detail.BuildStatus == "FAULT" || messageNotification.Detail.BuildStatus == "TIMED_OUT" {
msgColor = "#FF0000"
} else if messageNotification.Detail.BuildStatus == "SUCCEEDED" {
msgColor = "#008000"
} else if messageNotification.Detail.BuildStatus == "IN_PROGRESS" || messageNotification.Detail.BuildStatus == "QUEUED" {
msgColor = "#FFFF00"
} else if messageNotification.Detail.BuildStatus == "STOPPED" {
msgColor = "#AAAAAA"
}
}

attachment := model.SlackAttachment{
Title: subject,
Fields: fields,
Color: msgColor,
}

return attachment
Expand Down

0 comments on commit 278c5c3

Please sign in to comment.