Skip to content

Commit

Permalink
Merge pull request #89 from devatherock/workflow-name
Browse files Browse the repository at this point in the history
feat: Included CircleCI workflow name in message
  • Loading branch information
devatherock authored Sep 22, 2024
2 parents 33bafc5 + a1064ac commit 957af0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased]
### Added
- [#78](https://github.com/devatherock/simple-slack/issues/78): Included CircleCI workflow name in message

### Changed
- Used machine executor in deployment step
- Upgraded `flyctl` to `0.2.93`
Expand Down
10 changes: 5 additions & 5 deletions cmd/app/app_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestSendNotificationWithBuildId(test *testing.T) {
requestUrl = request.Host + request.URL.Path
headers = request.Header

fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"running"}`)
fmt.Fprintln(writer, `{"name":"publish","project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"running"}`)
} else if requestIndex == 1 {
fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"success"}`)
fmt.Fprintln(writer, `{"name":"publish","project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"success"}`)
} else if requestIndex == 4 {
fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"failed"}`)
fmt.Fprintln(writer, `{"name":"publish","project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"failed"}`)
} else if requestIndex == 7 {
fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"failing"}`)
fmt.Fprintln(writer, `{"name":"publish","project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"failing"}`)
} else { // 2, 5, 8 For the slack send call
fmt.Fprintln(writer, `{"success":true}`)
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestSendNotificationWithBuildId(test *testing.T) {

// Verify slack request
helper.VerifySlackRequest(test, capturedRequest, map[string]string{
"text": fmt.Sprintf("%s: <https://app.circleci.com/pipelines/gh/devatherock/email-sender/292|gh/devatherock/email-sender-292>", data.expectedStatus),
"text": fmt.Sprintf("%s: <https://app.circleci.com/pipelines/gh/devatherock/email-sender/292|gh/devatherock/email-sender-292>(publish)", data.expectedStatus),
"color": data.expectedColor,
"title": "Build completed",
})
Expand Down
4 changes: 3 additions & 1 deletion cmd/app/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var exitStatuses = []string{"success", "failed", "failing"}
var httpClient = &http.Client{}

type CircleCiWorkFlow struct {
Name string `json:",omitempty"`
Project string `json:"project_slug,omitempty"`
Status string `json:",omitempty"`
PipelineNumber int `json:"pipeline_number,omitempty"`
Expand Down Expand Up @@ -101,12 +102,13 @@ func monitor(buildId string, token string, slackRequest slack.SlackRequest) {
if slices.Contains(exitStatuses, buildStatus) {
if slackRequest.Text == "" {
slackRequest.Text = fmt.Sprintf(
"%s: <https://app.circleci.com/pipelines/%s/%d|%s-%d>",
"%s: <https://app.circleci.com/pipelines/%s/%d|%s-%d>(%s)",
strings.ToUpper(buildStatus[:1])+buildStatus[1:],
circleCiWorkFlow.Project,
circleCiWorkFlow.PipelineNumber,
circleCiWorkFlow.Project,
circleCiWorkFlow.PipelineNumber,
circleCiWorkFlow.Name,
)
}

Expand Down

0 comments on commit 957af0f

Please sign in to comment.