This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
/
fluxMessage.go
103 lines (89 loc) · 2.42 KB
/
fluxMessage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package notifications
import (
"fmt"
"strings"
"github.com/gimlet-io/gimletd/model"
githubLib "github.com/google/go-github/v37/github"
)
type fluxMessage struct {
gitopsCommit *model.GitopsCommit
gitopsRepo string
env string
}
func (fm *fluxMessage) AsSlackMessage() (*slackMessage, error) {
msg := &slackMessage{
Text: "",
Blocks: []Block{},
}
switch fm.gitopsCommit.Status {
case model.Progressing:
if strings.Contains(fm.gitopsCommit.StatusDesc, "Health check passed") {
msg.Text = fmt.Sprintf(":heavy_check_mark: Applied resources from %s are up and healthy", commitLink(fm.gitopsRepo, fm.gitopsCommit.Sha))
} else {
msg.Text = fmt.Sprintf(":hourglass_flowing_sand: Applying gitops changes from %s", commitLink(fm.gitopsRepo, fm.gitopsCommit.Sha))
}
case model.ValidationFailed:
fallthrough
case model.ReconciliationFailed:
msg.Text = fmt.Sprintf(":exclamation: Gitops changes from %s failed to apply", commitLink(fm.gitopsRepo, fm.gitopsCommit.Sha))
case model.HealthCheckFailed:
msg.Text = fmt.Sprintf(":ambulance: Gitops changes from %s have health issues", commitLink(fm.gitopsRepo, fm.gitopsCommit.Sha))
default:
msg.Text = fmt.Sprintf("%s: %s", fm.gitopsCommit.Status, commitLink(fm.gitopsRepo, fm.gitopsCommit.Sha))
}
msg.Blocks = append(msg.Blocks,
Block{
Type: section,
Text: &Text{
Type: markdown,
Text: msg.Text,
},
},
)
var contextText string
switch fm.gitopsCommit.Status {
case model.ValidationFailed:
fallthrough
case model.ReconciliationFailed:
fallthrough
case model.HealthCheckFailed:
contextText = fm.gitopsCommit.StatusDesc
case model.Progressing:
if strings.Contains(fm.gitopsCommit.StatusDesc, "Health check passed") {
contextText = fm.gitopsCommit.StatusDesc
}
}
if contextText != "" {
msg.Blocks = append(msg.Blocks,
Block{
Type: contextString,
Elements: []Text{
{
Type: markdown,
Text: contextText,
},
},
},
)
}
return msg, nil
}
func (fm *fluxMessage) Env() string {
return fm.env
}
func (fm *fluxMessage) AsGithubStatus() (*githubLib.RepoStatus, error) {
return nil, nil
}
func NewMessage(gitopsRepo string, gitopsCommit *model.GitopsCommit, env string) Message {
return &fluxMessage{
gitopsCommit: gitopsCommit,
gitopsRepo: gitopsRepo,
env: env,
}
}
func (fm *fluxMessage) RepositoryName() string {
return ""
}
func (fm *fluxMessage) SHA() string {
return ""
}