Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ docker_auth: &docker_auth

vm_executor_image: &vm_executor_image
machine:
image: ubuntu-2204:2023.04.2
image: ubuntu-2204:2024.05.1

workspace: &workspace
at: ~/simple-slack
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
### Changed
- Fixed bug in deployment step
- Upgraded go to `1.22`
- chore(deps): update alpine docker tag to v3.20.2
- Upgraded `circleci-templates` to `0.7.0`
- Upgraded `golang.org/x/crypto` to `0.21.0`
- chore(deps): update alpine docker tag to v3.20.3
- [#73](https://github.com/devatherock/simple-slack/issues/73): Handled `failing` CircleCI status

## [1.1.0] - 2024-06-07
### Added
Expand Down
12 changes: 10 additions & 2 deletions cmd/app/app_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"slices"
"testing"
"time"

Expand All @@ -22,6 +23,7 @@ import (
const baseUrl string = "http://localhost:8082"

var client = &http.Client{}
var inProgressIndexes = []int{0, 3, 6}

func TestSendNotificationWithBuildId(test *testing.T) {
var requestIndex = 0
Expand All @@ -35,7 +37,7 @@ func TestSendNotificationWithBuildId(test *testing.T) {
capturedRequest, _ = ioutil.ReadAll(request.Body)
writer.Header().Set("Content-Type", "application/json")

if requestIndex == 0 || requestIndex == 3 {
if slices.Contains(inProgressIndexes, requestIndex) {
requestUrl = request.Host + request.URL.Path
headers = request.Header

Expand All @@ -44,7 +46,9 @@ func TestSendNotificationWithBuildId(test *testing.T) {
fmt.Fprintln(writer, `{"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"}`)
} else {
} else if requestIndex == 7 {
fmt.Fprintln(writer, `{"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 @@ -73,6 +77,10 @@ func TestSendNotificationWithBuildId(test *testing.T) {
"Failed",
"#a1040c",
},
{
"Failing",
"#a1040c",
},
}

progressIndex := 0
Expand Down
4 changes: 3 additions & 1 deletion cmd/app/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net/http"
"os"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -18,6 +19,7 @@ import (
log "github.com/sirupsen/logrus"
)

var exitStatuses = []string{"success", "failed", "failing"}
var httpClient = &http.Client{}

type CircleCiWorkFlow struct {
Expand Down Expand Up @@ -96,7 +98,7 @@ func monitor(buildId string, token string, slackRequest slack.SlackRequest) {
circleCiResponse.Body.Close()

buildStatus = circleCiWorkFlow.Status
if buildStatus == "success" || buildStatus == "failed" {
if slices.Contains(exitStatuses, buildStatus) {
if slackRequest.Text == "" {
slackRequest.Text = fmt.Sprintf(
"%s: <https://app.circleci.com/pipelines/%s/%d|%s-%d>",
Expand Down
2 changes: 1 addition & 1 deletion fly/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM devatherock/simple-slack-api:1.1.0
FROM devatherock/simple-slack-api:1.2.0