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 141e2fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ linters:

issues:
exclude-rules:
- path: plugin.go
linters:
- goconst
- path: server/manifest.go
linters:
- deadcode
Expand Down
21 changes: 19 additions & 2 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,35 @@ 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" {
switch messageNotification.Detail.BuildStatus {
case "FAILED", "FAULT", "TIMED_OUT":
msgColor = "#FF0000"
case "SUCCEEDED":
msgColor = "#008000"
case "IN_PROGRESS", "QUEUED":
msgColor = "#008000"
case "STOPPED":
msgColor = "#AAAAAA"
}
}

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

return attachment
Expand Down

0 comments on commit 141e2fb

Please sign in to comment.