Skip to content

Commit 0fbc8ba

Browse files
authored
Merge pull request #86 from devatherock/handle-failing-status
fix: Handled 'failing' CircleCI status
2 parents d05d1fe + fcc54b8 commit 0fbc8ba

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ docker_auth: &docker_auth
55

66
vm_executor_image: &vm_executor_image
77
machine:
8-
image: ubuntu-2204:2023.04.2
8+
image: ubuntu-2204:2024.05.1
99

1010
workspace: &workspace
1111
at: ~/simple-slack

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
### Changed
88
- Fixed bug in deployment step
99
- Upgraded go to `1.22`
10-
- chore(deps): update alpine docker tag to v3.20.2
1110
- Upgraded `circleci-templates` to `0.7.0`
1211
- Upgraded `golang.org/x/crypto` to `0.21.0`
1312
- chore(deps): update alpine docker tag to v3.20.3
13+
- [#73](https://github.com/devatherock/simple-slack/issues/73): Handled `failing` CircleCI status
1414

1515
## [1.1.0] - 2024-06-07
1616
### Added

cmd/app/app_integration_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net"
1313
"net/http"
1414
"net/http/httptest"
15+
"slices"
1516
"testing"
1617
"time"
1718

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

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

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

38-
if requestIndex == 0 || requestIndex == 3 {
40+
if slices.Contains(inProgressIndexes, requestIndex) {
3941
requestUrl = request.Host + request.URL.Path
4042
headers = request.Header
4143

@@ -44,7 +46,9 @@ func TestSendNotificationWithBuildId(test *testing.T) {
4446
fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"success"}`)
4547
} else if requestIndex == 4 {
4648
fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"failed"}`)
47-
} else {
49+
} else if requestIndex == 7 {
50+
fmt.Fprintln(writer, `{"project_slug":"gh/devatherock/email-sender","pipeline_number":292,"status":"failing"}`)
51+
} else { // 2, 5, 8 For the slack send call
4852
fmt.Fprintln(writer, `{"success":true}`)
4953
}
5054

@@ -73,6 +77,10 @@ func TestSendNotificationWithBuildId(test *testing.T) {
7377
"Failed",
7478
"#a1040c",
7579
},
80+
{
81+
"Failing",
82+
"#a1040c",
83+
},
7684
}
7785

7886
progressIndex := 0

cmd/app/notifier.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io"
1111
"net/http"
1212
"os"
13+
"slices"
1314
"strconv"
1415
"strings"
1516
"time"
@@ -18,6 +19,7 @@ import (
1819
log "github.com/sirupsen/logrus"
1920
)
2021

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

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

98100
buildStatus = circleCiWorkFlow.Status
99-
if buildStatus == "success" || buildStatus == "failed" {
101+
if slices.Contains(exitStatuses, buildStatus) {
100102
if slackRequest.Text == "" {
101103
slackRequest.Text = fmt.Sprintf(
102104
"%s: <https://app.circleci.com/pipelines/%s/%d|%s-%d>",

fly/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM devatherock/simple-slack-api:1.1.0
1+
FROM devatherock/simple-slack-api:1.2.0

0 commit comments

Comments
 (0)