From 98f4b652d86064982c2014a28364e08e4e5898a5 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 10 Oct 2024 09:23:01 +1100 Subject: [PATCH 1/2] chore: remove unused code --- .../internal/lagoon/client/client_test.go | 81 ------ .../internal/lagoon/client/helper_test.go | 6 - .../lagoon/client/lgraphql/lgraphql.go | 249 ------------------ .../internal/lagoon/jwt/jwt.go | 30 --- 4 files changed, 366 deletions(-) delete mode 100644 services/logs2notifications/internal/lagoon/client/client_test.go delete mode 100644 services/logs2notifications/internal/lagoon/client/helper_test.go delete mode 100644 services/logs2notifications/internal/lagoon/client/lgraphql/lgraphql.go delete mode 100644 services/logs2notifications/internal/lagoon/jwt/jwt.go diff --git a/services/logs2notifications/internal/lagoon/client/client_test.go b/services/logs2notifications/internal/lagoon/client/client_test.go deleted file mode 100644 index 52c69411a5..0000000000 --- a/services/logs2notifications/internal/lagoon/client/client_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package client_test - -import ( - "reflect" - "testing" - - "github.com/uselagoon/lagoon/services/logs2notifications/internal/lagoon/client" -) - -type testStruct0 struct { - Foo string `json:"foo"` - Bar uint `json:"bar"` - Baz string `json:"baz,omitempty"` - Quux uint `json:"quux,omitempty"` -} - -func TestStructToVarMap(t *testing.T) { - var testCases = map[string]struct { - input testStruct0 - expect map[string]interface{} - }{ - "simple struct": { - input: testStruct0{ - Foo: "abc", - Bar: 8, - }, - expect: map[string]interface{}{ - "foo": "abc", - "bar": float64(8), - }, - }, - "keep zero values": { - input: testStruct0{ - Foo: "abc", - Bar: 0, - }, - expect: map[string]interface{}{ - "foo": "abc", - "bar": float64(0), - }, - }, - "omit zero values": { - input: testStruct0{ - Foo: "abc", - Bar: 0, - Baz: "", - Quux: 0, - }, - expect: map[string]interface{}{ - "foo": "abc", - "bar": float64(0), - }, - }, - "keep non-zero values": { - input: testStruct0{ - Foo: "abc", - Bar: 0, - Baz: "hi", - Quux: 9, - }, - expect: map[string]interface{}{ - "foo": "abc", - "bar": float64(0), - "baz": "hi", - "quux": float64(9), - }, - }, - } - for name, tc := range testCases { - t.Run(name, func(tt *testing.T) { - vars, err := client.StructToVarMap(&tc.input) - if err != nil { - tt.Error(err) - } - if !reflect.DeepEqual(vars, tc.expect) { - tt.Logf("result:\n%s\nexpected:\n%s", vars, tc.expect) - tt.Errorf("result does not match expected") - } - }) - } -} diff --git a/services/logs2notifications/internal/lagoon/client/helper_test.go b/services/logs2notifications/internal/lagoon/client/helper_test.go deleted file mode 100644 index 39591e0080..0000000000 --- a/services/logs2notifications/internal/lagoon/client/helper_test.go +++ /dev/null @@ -1,6 +0,0 @@ -package client - -// StructToVarMap exposes the private client.structToVarMap for tests. -func StructToVarMap(varStruct interface{}) (map[string]interface{}, error) { - return structToVarMap(varStruct) -} diff --git a/services/logs2notifications/internal/lagoon/client/lgraphql/lgraphql.go b/services/logs2notifications/internal/lagoon/client/lgraphql/lgraphql.go deleted file mode 100644 index f2d7f8d358..0000000000 --- a/services/logs2notifications/internal/lagoon/client/lgraphql/lgraphql.go +++ /dev/null @@ -1,249 +0,0 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. - -//Package lgraphql generated by go-bindata.// sources: -// _lgraphql/projectNotifications.graphql -package lgraphql - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" -) - -func bindataRead(data []byte, name string) ([]byte, error) { - gz, err := gzip.NewReader(bytes.NewBuffer(data)) - if err != nil { - return nil, fmt.Errorf("read %q: %v", name, err) - } - - var buf bytes.Buffer - _, err = io.Copy(&buf, gz) - clErr := gz.Close() - - if err != nil { - return nil, fmt.Errorf("read %q: %v", name, err) - } - if clErr != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -type asset struct { - bytes []byte - info os.FileInfo -} - -type bindataFileInfo struct { - name string - size int64 - mode os.FileMode - modTime time.Time -} - -// Name return file name -func (fi bindataFileInfo) Name() string { - return fi.name -} - -// Size return file size -func (fi bindataFileInfo) Size() int64 { - return fi.size -} - -// Mode return file mode -func (fi bindataFileInfo) Mode() os.FileMode { - return fi.mode -} - -// ModTime return file modify time -func (fi bindataFileInfo) ModTime() time.Time { - return fi.modTime -} - -// IsDir return file whether a directory -func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 -} - -// Sys return file is sys mode -func (fi bindataFileInfo) Sys() interface{} { - return nil -} - -var __lgraphqlProjectnotificationsGraphql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x92\xc1\x4a\xc4\x30\x10\x86\xcf\xf6\x29\x46\xf0\xb0\x5e\xfa\x00\xde\x54\x3c\xba\x07\x5b\xf0\xb8\xc4\x74\xd6\x8c\x6d\x67\x6a\x32\x2a\x41\xfa\xee\x92\x96\xc5\xb6\x2a\x45\x50\xd8\xff\x94\xfc\xf9\x66\xf8\x93\xc9\xf3\x0b\xfa\x08\x9b\x0c\xe0\x8c\x4d\x8b\x17\x50\xa8\x27\x7e\x3c\xcd\xce\xe1\x3d\x03\x00\xe8\xbc\x3c\xa1\xd5\xab\xb8\x35\x2d\x6e\x06\x2b\x69\x84\x87\x9a\xc1\x3b\xe0\x49\x54\xcd\xb0\xcf\x8d\x28\xed\xc9\x1a\x25\xe1\x30\xe1\x93\xf2\x3c\x07\x61\xd8\x4e\x90\xa2\x31\xb6\x5e\x60\x49\xbb\x9d\xc6\x0e\x67\x9d\x0f\x7a\xc3\x07\x27\x52\x7f\xf1\xbf\x85\xad\x33\xcc\xd8\xcc\xfc\x7e\x2d\xd4\x9d\xd8\x1a\xf5\xda\x19\x3d\xb6\x64\x37\xad\xa1\xe6\x77\xa1\x30\x95\x5c\x56\x95\xc7\x10\xd6\x93\xad\x26\xb8\x25\xeb\x25\xc8\x5e\x4b\x34\xed\x72\xc0\x7f\xf5\x3e\xab\x29\xee\xc7\x4e\xff\x39\x1e\x61\x45\xd6\x32\x76\xcb\xb3\x93\xe9\x17\x2f\xf0\x15\x3d\x69\x2c\x9d\xc7\xe0\xa4\xa9\x7e\xb8\xc7\xb8\xea\xb3\xfe\x23\x00\x00\xff\xff\x7f\x5a\x0f\xed\x8c\x03\x00\x00") - -func _lgraphqlProjectnotificationsGraphqlBytes() ([]byte, error) { - return bindataRead( - __lgraphqlProjectnotificationsGraphql, - "_lgraphql/projectNotifications.graphql", - ) -} - -func _lgraphqlProjectnotificationsGraphql() (*asset, error) { - bytes, err := _lgraphqlProjectnotificationsGraphqlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "_lgraphql/projectNotifications.graphql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) - } - return a.bytes, nil - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// MustAsset is like Asset but panics when Asset would return an error. -// It simplifies safe initialization of global variables. -func MustAsset(name string) []byte { - a, err := Asset(name) - if err != nil { - panic("asset: Asset(" + name + "): " + err.Error()) - } - - return a -} - -// AssetInfo loads and returns the asset info for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) - } - return a.info, nil - } - return nil, fmt.Errorf("AssetInfo %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() (*asset, error){ - "_lgraphql/projectNotifications.graphql": _lgraphqlProjectnotificationsGraphql, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// -// data/ -// foo.txt -// img/ -// a.png -// b.png -// -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for childName := range node.Children { - rv = append(rv, childName) - } - return rv, nil -} - -type bintree struct { - Func func() (*asset, error) - Children map[string]*bintree -} - -var _bintree = &bintree{nil, map[string]*bintree{ - "_lgraphql": &bintree{nil, map[string]*bintree{ - "projectNotifications.graphql": &bintree{_lgraphqlProjectnotificationsGraphql, map[string]*bintree{}}, - }}, -}} - -// RestoreAsset restores an asset under the given directory -func RestoreAsset(dir, name string) error { - data, err := Asset(name) - if err != nil { - return err - } - info, err := AssetInfo(name) - if err != nil { - return err - } - err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) - if err != nil { - return err - } - err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) - if err != nil { - return err - } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil -} - -// RestoreAssets restores an asset under the given directory recursively -func RestoreAssets(dir, name string) error { - children, err := AssetDir(name) - // File - if err != nil { - return RestoreAsset(dir, name) - } - // Dir - for _, child := range children { - err = RestoreAssets(dir, filepath.Join(name, child)) - if err != nil { - return err - } - } - return nil -} - -func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) -} diff --git a/services/logs2notifications/internal/lagoon/jwt/jwt.go b/services/logs2notifications/internal/lagoon/jwt/jwt.go deleted file mode 100644 index 9219e76818..0000000000 --- a/services/logs2notifications/internal/lagoon/jwt/jwt.go +++ /dev/null @@ -1,30 +0,0 @@ -package jwt - -import ( - "time" - - "github.com/dgrijalva/jwt-go" -) - -// LagoonClaims is a set of JWT claims used by Lagoon. -type LagoonClaims struct { - Role string `json:"role"` - jwt.StandardClaims -} - -// OneMinuteAdminToken returns a JWT admin token valid for one minute. -func OneMinuteAdminToken(secret, audience, subject, issuer string) (string, error) { - now := time.Now() - claims := LagoonClaims{ - Role: "admin", - StandardClaims: jwt.StandardClaims{ - Audience: audience, - ExpiresAt: now.Unix() + 60, - IssuedAt: now.Unix(), - Subject: subject, - Issuer: issuer, - }, - } - token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - return token.SignedString([]byte(secret)) -} From 4bb454882d47194ca99ee929446be86d472cb7ac Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 10 Oct 2024 09:32:01 +1100 Subject: [PATCH 2/2] feat: update notifications with more information for build states --- services/logs2notifications/go.mod | 1 - services/logs2notifications/go.sum | 1 - .../internal/handler/email_events.go | 104 +++++++-------- .../internal/handler/main.go | 9 ++ .../internal/handler/main_test.go | 48 +++++-- .../internal/handler/microsoftteams_events.go | 29 ++-- .../internal/handler/rocketchat_events.go | 125 ++++++++---------- .../internal/handler/slack_events.go | 125 ++++++++---------- .../testdata/deployError/emailhtml.txt | 2 +- .../testdata/deployError/emailplain.txt | 2 +- .../testdata/deployError/rocketchat.txt | 2 +- .../handler/testdata/deployError/slack.txt | 2 +- .../handler/testdata/deployError/teams.txt | 2 +- .../handler/testdata/deployError/webhook.txt | 2 +- .../deployErrorImageBuild/emailhtml.txt | 2 + .../deployErrorImageBuild/emailplain.txt | 2 + .../deployErrorImageBuild/rocketchat.txt | 1 + .../testdata/deployErrorImageBuild/slack.txt | 1 + .../testdata/deployErrorImageBuild/teams.txt | 1 + .../deployErrorImageBuild/webhook.txt | 1 + .../testdata/deployFinished/emailhtml.txt | 2 +- .../testdata/deployFinished/emailplain.txt | 2 +- .../deployFinishedWithWarnings/emailhtml.txt | 10 ++ .../deployFinishedWithWarnings/emailplain.txt | 4 + .../deployFinishedWithWarnings/rocketchat.txt | 4 + .../deployFinishedWithWarnings/slack.txt | 5 + .../deployFinishedWithWarnings/teams.txt | 4 + .../deployFinishedWithWarnings/webhook.txt | 1 + .../handler/testdata/input.deployError.json | 1 + .../testdata/input.deployErrorImageBuild.json | 12 ++ .../testdata/input.deployFinished.json | 1 + .../input.deployFinishedWithWarnings.json | 15 +++ .../internal/handler/webhook_events.go | 122 ++++++++--------- 33 files changed, 342 insertions(+), 303 deletions(-) create mode 100644 services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailhtml.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailplain.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/rocketchat.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/slack.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/teams.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/webhook.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailhtml.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailplain.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/rocketchat.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/slack.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/teams.txt create mode 100644 services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/webhook.txt create mode 100644 services/logs2notifications/internal/handler/testdata/input.deployErrorImageBuild.json create mode 100644 services/logs2notifications/internal/handler/testdata/input.deployFinishedWithWarnings.json diff --git a/services/logs2notifications/go.mod b/services/logs2notifications/go.mod index b205e9aa44..1a3a5b48ba 100644 --- a/services/logs2notifications/go.mod +++ b/services/logs2notifications/go.mod @@ -5,7 +5,6 @@ go 1.22 require ( github.com/aws/aws-sdk-go v1.55.5 github.com/cheshir/go-mq/v2 v2.0.1 - github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 github.com/slack-go/slack v0.13.1 github.com/uselagoon/machinery v0.0.29 diff --git a/services/logs2notifications/go.sum b/services/logs2notifications/go.sum index 3814b9458d..7ca567c854 100644 --- a/services/logs2notifications/go.sum +++ b/services/logs2notifications/go.sum @@ -306,7 +306,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0= github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= diff --git a/services/logs2notifications/internal/handler/email_events.go b/services/logs2notifications/internal/handler/email_events.go index 251abb5be3..b656a33915 100644 --- a/services/logs2notifications/internal/handler/email_events.go +++ b/services/logs2notifications/internal/handler/email_events.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "fmt" "log" + "regexp" "strconv" "strings" "text/template" @@ -96,9 +97,9 @@ func (h *Messaging) processEmailTemplates(notification *Notification) (string, s mainHTMLTpl = `{{.OpenshiftProject}} not deleted.` plainTextTpl = `[{{.ProjectName}}] {{.OpenshiftProject}} not deleted. {{.Error}}` case "deployError": - mainHTMLTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} error. + mainHTMLTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} failed at build step ` + "`{{.BuildStep}}`" + `. {{if ne .LogLink ""}} Logs{{end}}` - plainTextTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} error. + plainTextTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} failed at build step {{.BuildStep}}. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}}` subject += fmt.Sprintf("[%s] %s Build %s error.", notification.Meta.ProjectName, @@ -106,7 +107,13 @@ func (h *Messaging) processEmailTemplates(notification *Notification) (string, s notification.Meta.BuildName, ) case "deployFinished": - mainHTMLTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} complete. {{if ne .LogLink ""}}Logs{{end}} + match, _ := regexp.MatchString(".*WithWarnings$", notification.Meta.BuildStep) + msg := "completed" + if match { + emoji = warningEmoji + msg = "completed with warnings, check the build log for more information" + } + mainHTMLTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} ` + msg + `. {{if ne .LogLink ""}}Logs{{end}}

@@ -115,14 +122,15 @@ func (h *Messaging) processEmailTemplates(notification *Notification) (string, s
  • {{.Route}}
  • {{range .Routes}}{{if ne . $.Route}}
  • {{.}}
  • {{end}}{{end}}` - plainTextTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} complete. {{if ne .LogLink ""}}[Logs]({{.LogLink}}){{end}} + plainTextTpl = `[{{.ProjectName}}] {{.BranchName}}{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build {{.BuildName}} ` + msg + `. {{if ne .LogLink ""}}[Logs]({{.LogLink}}){{end}} {{.Route}} {{range .Routes}}{{if ne . $.Route}}{{.}} {{end}}{{end}}` - subject += fmt.Sprintf("[%s] %s Build %s complete.", + subject += fmt.Sprintf("[%s] %s Build %s %s.", notification.Meta.ProjectName, notification.Meta.BranchName, notification.Meta.BuildName, + msg, ) case "problemNotification": eventSplit := strings.Split(notification.Event, ":") @@ -221,70 +229,52 @@ func getEmailEvent(msgEvent string) (string, string, string, error) { } var emailEvent = map[string]EventMap{ - "github:pull_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "gitlab:merge_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "bitbucket:pullrequest:created:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack - "bitbucket:pullrequest:created:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams + "github:pull_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "gitlab:merge_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "bitbucket:pullrequest:created:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack + "bitbucket:pullrequest:created:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams - "github:pull_request:synchronize:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "gitlab:merge_request:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "bitbucket:pullrequest:updated:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack - "bitbucket:pullrequest:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams + "github:pull_request:synchronize:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "gitlab:merge_request:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "bitbucket:pullrequest:updated:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack + "bitbucket:pullrequest:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams - "github:pull_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:fulfilled:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:rejected:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "gitlab:merge_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "github:pull_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:fulfilled:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:rejected:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "gitlab:merge_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "github:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, - "gitlab:remove:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "bitbucket:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "api:deleteEnvironment": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams + "github:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, + "gitlab:remove:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "bitbucket:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "api:deleteEnvironment": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams - "github:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "bitbucket:repo:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "gitlab:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, + "github:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "bitbucket:repo:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "gitlab:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, - "github:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "gitlab:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "bitbucket:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, + "github:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "gitlab:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "bitbucket:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, - "api:deployEnvironmentLatest": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - "api:deployEnvironmentBranch": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, + "api:deployEnvironmentLatest": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + "api:deployEnvironmentBranch": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, - "task:deploy-openshift:finished": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, - "task:remove-openshift-resources:finished": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, - "task:builddeploy-openshift:complete": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, - "task:builddeploy-kubernetes:complete": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, //not in teams + "task:deploy-openshift:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, + "task:remove-openshift-resources:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, + "task:builddeploy-openshift:complete": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, + "task:builddeploy-kubernetes:complete": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, //not in teams - "task:remove-openshift:finished": {Emoji: "✅", Color: "lawngreen", Template: "removeFinished"}, - "task:remove-kubernetes:finished": {Emoji: "✅", Color: "lawngreen", Template: "removeFinished"}, + "task:remove-openshift:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "removeFinished"}, + "task:remove-kubernetes:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "removeFinished"}, "task:remove-openshift:error": {Emoji: "‼️", Color: "red", Template: "deployError"}, "task:remove-kubernetes:error": {Emoji: "‼️", Color: "red", Template: "deployError"}, "task:builddeploy-kubernetes:failed": {Emoji: "‼️", Color: "red", Template: "deployError"}, //not in teams "task:builddeploy-openshift:failed": {Emoji: "‼️", Color: "red", Template: "deployError"}, - "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - "github:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - - // deprecated - // "rest:remove:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold"}, - // "rest:deploy:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:remove:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:promote:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:deploy": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:remove": {Emoji: "ℹ️", Color: "#E8E8E8"}, - - // deprecated - // "task:deploy-openshift:error": {Emoji: "‼️", Color: "red", Template: "deployError"}, - // "task:remove-openshift-resources:error": {Emoji: "‼️", Color: "red", Template: "deployError"}, - - // deprecated - // "task:deploy-openshift:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, - // "task:remove-openshift:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, - // "task:remove-kubernetes:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, - // "task:remove-openshift-resources:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, + "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, + "github:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, + "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, + "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, } diff --git a/services/logs2notifications/internal/handler/main.go b/services/logs2notifications/internal/handler/main.go index 8c81d5f6ce..a9051906fc 100644 --- a/services/logs2notifications/internal/handler/main.go +++ b/services/logs2notifications/internal/handler/main.go @@ -98,6 +98,8 @@ type Notification struct { Timestamp string `json:"timestamp"` ShortSha string `json:"shortSha"` BuildName string `json:"buildName"` + BuildPhase string `json:"buildPhase"` + BuildStep string `json:"buildStep"` CommitURL string `json:"commitUrl"` Environment string `json:"environment"` EnvironmentID string `json:"environmentId"` @@ -134,6 +136,13 @@ type EventMap struct { Template string `json:"template"` } +var ( + warningEmoji string = "⚠️" + infoEmoji string = "ℹ️" + successEmoji string = "✅" + failEmoji string = "🛑" +) + // NewMessaging returns a messaging with config func NewMessaging(config mq.Config, lagoonAPI LagoonAPI, diff --git a/services/logs2notifications/internal/handler/main_test.go b/services/logs2notifications/internal/handler/main_test.go index f10ad3b316..36772772da 100644 --- a/services/logs2notifications/internal/handler/main_test.go +++ b/services/logs2notifications/internal/handler/main_test.go @@ -2,7 +2,7 @@ package handler import ( "encoding/json" - "io/ioutil" + "os" "testing" mq "github.com/cheshir/go-mq/v2" @@ -107,6 +107,16 @@ func TestProcessing(t *testing.T) { teams: "testdata/deployError/teams.txt", webhook: "testdata/deployError/webhook.txt", }, + "deployErrorImageBuild": { + description: "test github repo push deleted events", + input: "testdata/input.deployErrorImageBuild.json", + slack: "testdata/deployErrorImageBuild/slack.txt", + rocketchat: "testdata/deployErrorImageBuild/rocketchat.txt", + emailhtml: "testdata/deployErrorImageBuild/emailhtml.txt", + emailplain: "testdata/deployErrorImageBuild/emailplain.txt", + teams: "testdata/deployErrorImageBuild/teams.txt", + webhook: "testdata/deployErrorImageBuild/webhook.txt", + }, "deployFinished": { description: "test github repo push deleted events", input: "testdata/input.deployFinished.json", @@ -117,6 +127,16 @@ func TestProcessing(t *testing.T) { teams: "testdata/deployFinished/teams.txt", webhook: "testdata/deployFinished/webhook.txt", }, + "deployFinishedWithWarnings": { + description: "test github repo push deleted events", + input: "testdata/input.deployFinishedWithWarnings.json", + slack: "testdata/deployFinishedWithWarnings/slack.txt", + rocketchat: "testdata/deployFinishedWithWarnings/rocketchat.txt", + emailhtml: "testdata/deployFinishedWithWarnings/emailhtml.txt", + emailplain: "testdata/deployFinishedWithWarnings/emailplain.txt", + teams: "testdata/deployFinishedWithWarnings/teams.txt", + webhook: "testdata/deployFinishedWithWarnings/webhook.txt", + }, "mergeRequestClosed": { description: "test github repo push handled events", input: "testdata/input.mergeRequestClosed.json", @@ -157,7 +177,7 @@ func TestProcessing(t *testing.T) { for name, tc := range testCases { t.Run(name, func(tt *testing.T) { // read the input into a the notification struct - inputBytes, err := ioutil.ReadFile(tc.input) // just pass the file name + inputBytes, err := os.ReadFile(tc.input) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } @@ -165,7 +185,7 @@ func TestProcessing(t *testing.T) { json.Unmarshal(inputBytes, notification) // process slack template - resultBytes, err := ioutil.ReadFile(tc.slack) // just pass the file name + resultBytes, err := os.ReadFile(tc.slack) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } @@ -174,11 +194,11 @@ func TestProcessing(t *testing.T) { tt.Fatalf("unexpected error %v", err) } if message != string(resultBytes) { - tt.Fatalf("message doesn't match, wanted `%s` got `%s`", message, string(resultBytes)) + tt.Fatalf("slack message doesn't match, wanted `%s` got `%s`", message, string(resultBytes)) } // process rocketchat template - resultBytes, err = ioutil.ReadFile(tc.rocketchat) // just pass the file name + resultBytes, err = os.ReadFile(tc.rocketchat) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } @@ -187,15 +207,15 @@ func TestProcessing(t *testing.T) { tt.Fatalf("unexpected error %v", err) } if message != string(resultBytes) { - tt.Fatalf("message doesn't match, wanted `%s` got `%s`", message, string(resultBytes)) + tt.Fatalf("rocketchat message doesn't match, wanted `%s` got `%s`", message, string(resultBytes)) } // process email templates - resultBytesHTML, err := ioutil.ReadFile(tc.emailhtml) // just pass the file name + resultBytesHTML, err := os.ReadFile(tc.emailhtml) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } - resultBytesPlainText, err := ioutil.ReadFile(tc.emailplain) // just pass the file name + resultBytesPlainText, err := os.ReadFile(tc.emailplain) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } @@ -204,14 +224,14 @@ func TestProcessing(t *testing.T) { tt.Fatalf("unexpected error %v", err) } if htmlMessage != string(resultBytesHTML) { - tt.Fatalf("html doesn't match, wanted `%s` got `%s`", string(htmlMessage), string(resultBytes)) + tt.Fatalf("html doesn't match, wanted `%s` got `%s`", string(htmlMessage), string(resultBytesHTML)) } if plaintextMessage != string(resultBytesPlainText) { - tt.Fatalf("plaintextmessage doesn't match, wanted `%s` got `%s`", string(plaintextMessage), string(resultBytes)) + tt.Fatalf("plaintextmessage doesn't match, wanted `%s` got `%s`", string(plaintextMessage), string(resultBytesPlainText)) } // process teams template - resultBytes, err = ioutil.ReadFile(tc.teams) // just pass the file name + resultBytes, err = os.ReadFile(tc.teams) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } @@ -220,12 +240,12 @@ func TestProcessing(t *testing.T) { tt.Fatalf("unexpected error %v", err) } if message != string(resultBytes) { - tt.Fatalf("message doesn't match, wanted `%s` got `%s`", message, string(resultBytes)) + tt.Fatalf("teams message doesn't match, wanted `%s` got `%s`", message, string(resultBytes)) } // process webhook template if tc.webhook != "" { - resultBytes, err = ioutil.ReadFile(tc.webhook) // just pass the file name + resultBytes, err = os.ReadFile(tc.webhook) // just pass the file name if err != nil { tt.Fatalf("unexpected error %v", err) } @@ -235,7 +255,7 @@ func TestProcessing(t *testing.T) { } messageBytes, _ := json.Marshal(&message) if string(messageBytes) != string(resultBytes) { - tt.Fatalf("message doesn't match, wanted `%s` got `%s`", string(messageBytes), string(resultBytes)) + tt.Fatalf("webhook message doesn't match, wanted `%s` got `%s`", string(messageBytes), string(resultBytes)) } } }) diff --git a/services/logs2notifications/internal/handler/microsoftteams_events.go b/services/logs2notifications/internal/handler/microsoftteams_events.go index bd97a9e82e..8096e3087f 100644 --- a/services/logs2notifications/internal/handler/microsoftteams_events.go +++ b/services/logs2notifications/internal/handler/microsoftteams_events.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "net/http" + "regexp" "strings" "text/template" ) @@ -71,9 +72,15 @@ func (h *Messaging) processMicrosoftTeamsTemplate(notification *Notification) (s case "notDeleted": teamsTpl = "`{{.BranchName}}`" + ` not deleted. {{.Error}}` case "deployError": - teamsTpl = "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` Failed. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}}` + teamsTpl = "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` failed at build step ` + "`{{.BuildStep}}`" + `. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}}` case "deployFinished": - teamsTpl = "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` Succeeded. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}} + match, _ := regexp.MatchString(".*WithWarnings$", notification.Meta.BuildStep) + msg := "Succeeded" + if match { + emoji = ":warning:" + msg = "Succeeded with warnings, check the build log for more information" + } + teamsTpl = "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}` " + msg + `. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}} * {{.Route}}{{range .Routes}}{{if ne . $.Route}}* {{.}}{{end}} {{end}}` case "problemNotification": @@ -187,22 +194,4 @@ var microsoftTeamsEvent = map[string]EventMap{ "github:push:CannotDeleteProductionEnvironment": {Emoji: ":warning:", Color: "gold", Template: "notDeleted"}, "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: ":warning:", Color: "gold", Template: "notDeleted"}, "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: ":warning:", Color: "gold", Template: "notDeleted"}, - - // deprecated - // "rest:remove:CannotDeleteProductionEnvironment": {Emoji: ":warning:", Color: "gold"}, - // "rest:deploy:receive": {Emoji: ":information_source:", Color: "#E8E8E8"}, - // "rest:remove:receive": {Emoji: ":information_source:", Color: "#E8E8E8"}, - // "rest:promote:receive": {Emoji: ":information_source:", Color: "#E8E8E8"}, - // "rest:pullrequest:deploy": {Emoji: ":information_source:", Color: "#E8E8E8"}, - // "rest:pullrequest:remove": {Emoji: ":information_source:", Color: "#E8E8E8"}, - - // deprecated - // "task:deploy-openshift:error": {Emoji: ":bangbang:", Color: "red", Template: "deployError"}, - // "task:remove-openshift-resources:error": {Emoji: ":bangbang:", Color: "red", Template: "deployError"}, - - // deprecated - // "task:deploy-openshift:retry": {Emoji: ":warning:", Color: "gold", Template: "removeRetry"}, - // "task:remove-openshift:retry": {Emoji: ":warning:", Color: "gold", Template: "removeRetry"}, - // "task:remove-kubernetes:retry": {Emoji: ":warning:", Color: "gold", Template: "removeRetry"}, - // "task:remove-openshift-resources:retry": {Emoji: ":warning:", Color: "gold", Template: "removeRetry"}, } diff --git a/services/logs2notifications/internal/handler/rocketchat_events.go b/services/logs2notifications/internal/handler/rocketchat_events.go index 4e5c6c237a..421b953680 100644 --- a/services/logs2notifications/internal/handler/rocketchat_events.go +++ b/services/logs2notifications/internal/handler/rocketchat_events.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "net/http" + "regexp" "strings" "text/template" ) @@ -75,9 +76,15 @@ func (h *Messaging) processRocketChatTemplate(notification *Notification) (strin case "notDeleted": rcTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + ` not deleted. {{.Error}}` case "deployError": - rcTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` Failed. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}}` + rcTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` failed at build step ` + "`{{.BuildStep}}`" + `. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}}` case "deployFinished": - rcTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` Succeeded. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}} + match, _ := regexp.MatchString(".*WithWarnings$", notification.Meta.BuildStep) + msg := "Succeeded" + if match { + emoji = warningEmoji + msg = "Succeeded with warnings, check the build log for more information" + } + rcTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}` " + msg + `. {{if ne .LogLink ""}} [Logs]({{.LogLink}}){{end}} * {{.Route}}{{range .Routes}}{{if ne . $.Route}}* {{.}}{{end}} {{end}}` case "problemNotification": @@ -145,70 +152,52 @@ func getRocketChatEvent(msgEvent string) (string, string, string, error) { } var rocketChatEventTypeMap = map[string]EventMap{ - "github:pull_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "gitlab:merge_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "bitbucket:pullrequest:created:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack - "bitbucket:pullrequest:created:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams - - "github:pull_request:synchronize:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "gitlab:merge_request:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "bitbucket:pullrequest:updated:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack - "bitbucket:pullrequest:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams - - "github:pull_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:fulfilled:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:rejected:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "gitlab:merge_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - - "github:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, - "gitlab:remove:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "bitbucket:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "api:deleteEnvironment": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams - - "github:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "bitbucket:repo:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "gitlab:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - - "github:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "gitlab:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "bitbucket:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - - "api:deployEnvironmentLatest": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - "api:deployEnvironmentBranch": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - - "task:deploy-openshift:finished": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, - "task:remove-openshift-resources:finished": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, - "task:builddeploy-openshift:complete": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, - "task:builddeploy-kubernetes:complete": {Emoji: "✅", Color: "lawngreen", Template: "deployFinished"}, //not in teams - - "task:remove-openshift:finished": {Emoji: "✅", Color: "lawngreen", Template: "removeFinished"}, - "task:remove-kubernetes:finished": {Emoji: "✅", Color: "lawngreen", Template: "removeFinished"}, - - "task:remove-openshift:error": {Emoji: "🛑", Color: "red", Template: "deployError"}, - "task:remove-kubernetes:error": {Emoji: "🛑", Color: "red", Template: "deployError"}, - "task:builddeploy-kubernetes:failed": {Emoji: "🛑", Color: "red", Template: "deployError"}, //not in teams - "task:builddeploy-openshift:failed": {Emoji: "🛑", Color: "red", Template: "deployError"}, - - "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - "github:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold", Template: "notDeleted"}, - - // deprecated - // "rest:remove:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "gold"}, - // "rest:deploy:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:remove:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:promote:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:deploy": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:remove": {Emoji: "ℹ️", Color: "#E8E8E8"}, - - // deprecated - // "task:deploy-openshift:error": {Emoji: "🛑", Color: "red", Template: "deployError"}, - // "task:remove-openshift-resources:error": {Emoji: "🛑", Color: "red", Template: "deployError"}, - - // deprecated - // "task:deploy-openshift:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, - // "task:remove-openshift:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, - // "task:remove-kubernetes:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, - // "task:remove-openshift-resources:retry": {Emoji: "⚠️", Color: "gold", Template: "removeRetry"}, + "github:pull_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "gitlab:merge_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "bitbucket:pullrequest:created:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack + "bitbucket:pullrequest:created:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams + + "github:pull_request:synchronize:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "gitlab:merge_request:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "bitbucket:pullrequest:updated:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack + "bitbucket:pullrequest:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams + + "github:pull_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:fulfilled:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:rejected:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "gitlab:merge_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + + "github:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, + "gitlab:remove:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "bitbucket:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "api:deleteEnvironment": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams + + "github:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "bitbucket:repo:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "gitlab:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + + "github:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "gitlab:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "bitbucket:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + + "api:deployEnvironmentLatest": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + "api:deployEnvironmentBranch": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + + "task:deploy-openshift:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, + "task:remove-openshift-resources:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, + "task:builddeploy-openshift:complete": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, + "task:builddeploy-kubernetes:complete": {Emoji: successEmoji, Color: "lawngreen", Template: "deployFinished"}, //not in teams + + "task:remove-openshift:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "removeFinished"}, + "task:remove-kubernetes:finished": {Emoji: successEmoji, Color: "lawngreen", Template: "removeFinished"}, + + "task:remove-openshift:error": {Emoji: failEmoji, Color: "red", Template: "deployError"}, + "task:remove-kubernetes:error": {Emoji: failEmoji, Color: "red", Template: "deployError"}, + "task:builddeploy-kubernetes:failed": {Emoji: failEmoji, Color: "red", Template: "deployError"}, //not in teams + "task:builddeploy-openshift:failed": {Emoji: failEmoji, Color: "red", Template: "deployError"}, + + "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, + "github:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, + "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, + "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "gold", Template: "notDeleted"}, } diff --git a/services/logs2notifications/internal/handler/slack_events.go b/services/logs2notifications/internal/handler/slack_events.go index 9b2a60657e..3bf026a5fa 100644 --- a/services/logs2notifications/internal/handler/slack_events.go +++ b/services/logs2notifications/internal/handler/slack_events.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "log" + "regexp" "strings" "text/template" @@ -55,9 +56,15 @@ func (h *Messaging) processSlackTemplate(notification *Notification) (string, st case "notDeleted": slackTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + ` not deleted. {{.Error}}` case "deployError": - slackTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` Failed. {{if ne .LogLink ""}} <{{.LogLink}}|Logs>{{end}}` + slackTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` failed at build step ` + "`{{.BuildStep}}`" + `. {{if ne .LogLink ""}} <{{.LogLink}}|Logs>{{end}}` case "deployFinished": - slackTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}`" + ` Succeeded. {{if ne .LogLink ""}} <{{.LogLink}}|Logs>{{end}} + match, _ := regexp.MatchString(".*WithWarnings$", notification.Meta.BuildStep) + msg := "Succeeded" + if match { + emoji = warningEmoji + msg = "Succeeded with warnings, check the build log for more information" + } + slackTpl = `*[{{.ProjectName}}]* ` + "`{{.BranchName}}`" + `{{ if ne .ShortSha "" }} ({{.ShortSha}}){{end}} Build ` + "`{{.BuildName}}` " + msg + `. {{if ne .LogLink ""}} <{{.LogLink}}|Logs>{{end}} {{.Route}} {{range .Routes}}{{if ne . $.Route}}{{.}}{{end}} {{end}}` @@ -112,70 +119,52 @@ func getSlackEvent(msgEvent string) (string, string, string, error) { } var slackEventTypeMap = map[string]EventMap{ - "github:pull_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "gitlab:merge_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "bitbucket:pullrequest:created:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack - "bitbucket:pullrequest:created:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams - - "github:pull_request:synchronize:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "gitlab:merge_request:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "bitbucket:pullrequest:updated:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack - "bitbucket:pullrequest:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams - - "github:pull_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:fulfilled:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:rejected:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "gitlab:merge_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - - "github:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, - "gitlab:remove:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "bitbucket:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "api:deleteEnvironment": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams - - "github:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "bitbucket:repo:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "gitlab:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - - "github:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "gitlab:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "bitbucket:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - - "api:deployEnvironmentLatest": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - "api:deployEnvironmentBranch": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - - "task:deploy-openshift:finished": {Emoji: "✅", Color: "good", Template: "deployFinished"}, - "task:remove-openshift-resources:finished": {Emoji: "✅", Color: "good", Template: "deployFinished"}, - "task:builddeploy-openshift:complete": {Emoji: "✅", Color: "good", Template: "deployFinished"}, - "task:builddeploy-kubernetes:complete": {Emoji: "✅", Color: "good", Template: "deployFinished"}, //not in teams - - "task:remove-openshift:finished": {Emoji: "✅", Color: "good", Template: "removeFinished"}, - "task:remove-kubernetes:finished": {Emoji: "✅", Color: "good", Template: "removeFinished"}, - - "task:remove-openshift:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - "task:remove-kubernetes:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - "task:builddeploy-kubernetes:failed": {Emoji: "🛑", Color: "danger", Template: "deployError"}, //not in teams - "task:builddeploy-openshift:failed": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - - "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - "github:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - - // deprecated - // "rest:remove:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning"}, - // "rest:deploy:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:remove:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:promote:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:deploy": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:remove": {Emoji: "ℹ️", Color: "#E8E8E8"}, - - // deprecated - // "task:deploy-openshift:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - // "task:remove-openshift-resources:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - - // deprecated - // "task:deploy-openshift:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, - // "task:remove-openshift:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, - // "task:remove-kubernetes:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, - // "task:remove-openshift-resources:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, + "github:pull_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "gitlab:merge_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "bitbucket:pullrequest:created:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack + "bitbucket:pullrequest:created:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams + + "github:pull_request:synchronize:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "gitlab:merge_request:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "bitbucket:pullrequest:updated:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack + "bitbucket:pullrequest:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams + + "github:pull_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:fulfilled:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:rejected:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "gitlab:merge_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + + "github:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, + "gitlab:remove:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "bitbucket:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "api:deleteEnvironment": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams + + "github:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "bitbucket:repo:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "gitlab:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + + "github:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "gitlab:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "bitbucket:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + + "api:deployEnvironmentLatest": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + "api:deployEnvironmentBranch": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + + "task:deploy-openshift:finished": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, + "task:remove-openshift-resources:finished": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, + "task:builddeploy-openshift:complete": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, + "task:builddeploy-kubernetes:complete": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, //not in teams + + "task:remove-openshift:finished": {Emoji: successEmoji, Color: "good", Template: "removeFinished"}, + "task:remove-kubernetes:finished": {Emoji: successEmoji, Color: "good", Template: "removeFinished"}, + + "task:remove-openshift:error": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, + "task:remove-kubernetes:error": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, + "task:builddeploy-kubernetes:failed": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, //not in teams + "task:builddeploy-openshift:failed": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, + + "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, + "github:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, + "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, + "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, } diff --git a/services/logs2notifications/internal/handler/testdata/deployError/emailhtml.txt b/services/logs2notifications/internal/handler/testdata/deployError/emailhtml.txt index caa0842373..53a6736358 100644 --- a/services/logs2notifications/internal/handler/testdata/deployError/emailhtml.txt +++ b/services/logs2notifications/internal/handler/testdata/deployError/emailhtml.txt @@ -1,2 +1,2 @@ -[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 error. +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 failed at build step `applyingDeployments`. Logs \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployError/emailplain.txt b/services/logs2notifications/internal/handler/testdata/deployError/emailplain.txt index 6e842187b3..85106493ad 100644 --- a/services/logs2notifications/internal/handler/testdata/deployError/emailplain.txt +++ b/services/logs2notifications/internal/handler/testdata/deployError/emailplain.txt @@ -1,2 +1,2 @@ -[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 error. +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 failed at build step applyingDeployments. [Logs](https://logs) \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployError/rocketchat.txt b/services/logs2notifications/internal/handler/testdata/deployError/rocketchat.txt index 3188762d78..29c83d3ecc 100644 --- a/services/logs2notifications/internal/handler/testdata/deployError/rocketchat.txt +++ b/services/logs2notifications/internal/handler/testdata/deployError/rocketchat.txt @@ -1 +1 @@ -*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` Failed. [Logs](https://logs) \ No newline at end of file +*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` failed at build step `applyingDeployments`. [Logs](https://logs) \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployError/slack.txt b/services/logs2notifications/internal/handler/testdata/deployError/slack.txt index cb1126de73..c964a36600 100644 --- a/services/logs2notifications/internal/handler/testdata/deployError/slack.txt +++ b/services/logs2notifications/internal/handler/testdata/deployError/slack.txt @@ -1 +1 @@ -*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` Failed. \ No newline at end of file +*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` failed at build step `applyingDeployments`. \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployError/teams.txt b/services/logs2notifications/internal/handler/testdata/deployError/teams.txt index ca2fa8daf9..dd828111e5 100644 --- a/services/logs2notifications/internal/handler/testdata/deployError/teams.txt +++ b/services/logs2notifications/internal/handler/testdata/deployError/teams.txt @@ -1 +1 @@ -`lagoon-type-override` Build `lagoon-build-1234` Failed. [Logs](https://logs) \ No newline at end of file +`lagoon-type-override` Build `lagoon-build-1234` failed at build step `applyingDeployments`. [Logs](https://logs) \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployError/webhook.txt b/services/logs2notifications/internal/handler/testdata/deployError/webhook.txt index 140e01021c..54f8402c12 100644 --- a/services/logs2notifications/internal/handler/testdata/deployError/webhook.txt +++ b/services/logs2notifications/internal/handler/testdata/deployError/webhook.txt @@ -1 +1 @@ -{"type":"DEPLOYMENT","event":"task:builddeploy-kubernetes:failed","project":"ci-github-openshift","environment":"lagoon-type-override","buildName":"lagoon-build-1234","logLink":"https://logs"} \ No newline at end of file +{"type":"DEPLOYMENT","event":"task:builddeploy-kubernetes:failed","project":"ci-github-openshift","environment":"lagoon-type-override","buildName":"lagoon-build-1234","buildStep":"applyingDeployments","logLink":"https://logs"} \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailhtml.txt b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailhtml.txt new file mode 100644 index 0000000000..5b8c9b897e --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailhtml.txt @@ -0,0 +1,2 @@ +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 failed at build step `buildingImages`. + Logs \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailplain.txt b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailplain.txt new file mode 100644 index 0000000000..a7944b1250 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/emailplain.txt @@ -0,0 +1,2 @@ +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 failed at build step buildingImages. + [Logs](https://logs) \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/rocketchat.txt b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/rocketchat.txt new file mode 100644 index 0000000000..792a6b5a7c --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/rocketchat.txt @@ -0,0 +1 @@ +*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` failed at build step `buildingImages`. [Logs](https://logs) \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/slack.txt b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/slack.txt new file mode 100644 index 0000000000..082cb1b8d4 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/slack.txt @@ -0,0 +1 @@ +*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` failed at build step `buildingImages`. \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/teams.txt b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/teams.txt new file mode 100644 index 0000000000..222fa2eb2c --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/teams.txt @@ -0,0 +1 @@ +`lagoon-type-override` Build `lagoon-build-1234` failed at build step `buildingImages`. [Logs](https://logs) \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/webhook.txt b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/webhook.txt new file mode 100644 index 0000000000..e28bcbd768 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployErrorImageBuild/webhook.txt @@ -0,0 +1 @@ +{"type":"DEPLOYMENT","event":"task:builddeploy-kubernetes:failed","project":"ci-github-openshift","environment":"lagoon-type-override","buildName":"lagoon-build-1234","buildStep":"buildingImages","logLink":"https://logs"} \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployFinished/emailhtml.txt b/services/logs2notifications/internal/handler/testdata/deployFinished/emailhtml.txt index 26155d23c4..6e4b8a4ec1 100644 --- a/services/logs2notifications/internal/handler/testdata/deployFinished/emailhtml.txt +++ b/services/logs2notifications/internal/handler/testdata/deployFinished/emailhtml.txt @@ -1,4 +1,4 @@ -[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 complete. Logs +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 completed. Logs

    diff --git a/services/logs2notifications/internal/handler/testdata/deployFinished/emailplain.txt b/services/logs2notifications/internal/handler/testdata/deployFinished/emailplain.txt index 3364f45f8b..bd6ef9308a 100644 --- a/services/logs2notifications/internal/handler/testdata/deployFinished/emailplain.txt +++ b/services/logs2notifications/internal/handler/testdata/deployFinished/emailplain.txt @@ -1,4 +1,4 @@ -[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 complete. [Logs](https://logs) +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 completed. [Logs](https://logs) https://route1 https://route2 https://route3 diff --git a/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailhtml.txt b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailhtml.txt new file mode 100644 index 0000000000..4612715f20 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailhtml.txt @@ -0,0 +1,10 @@ +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 completed with warnings, check the build log for more information. Logs +

    +
    +
    +

    +

    \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailplain.txt b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailplain.txt new file mode 100644 index 0000000000..09aa29b79b --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/emailplain.txt @@ -0,0 +1,4 @@ +[ci-github-openshift] lagoon-type-override Build lagoon-build-1234 completed with warnings, check the build log for more information. [Logs](https://logs) +https://route1 +https://route2 +https://route3 diff --git a/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/rocketchat.txt b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/rocketchat.txt new file mode 100644 index 0000000000..88e532e35d --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/rocketchat.txt @@ -0,0 +1,4 @@ +*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` Succeeded with warnings, check the build log for more information. [Logs](https://logs) +* https://route1 +* https://route2 +* https://route3 diff --git a/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/slack.txt b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/slack.txt new file mode 100644 index 0000000000..04ca43f16a --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/slack.txt @@ -0,0 +1,5 @@ +*[ci-github-openshift]* `lagoon-type-override` Build `lagoon-build-1234` Succeeded with warnings, check the build log for more information. +https://route1 + +https://route2 +https://route3 diff --git a/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/teams.txt b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/teams.txt new file mode 100644 index 0000000000..2f2d445957 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/teams.txt @@ -0,0 +1,4 @@ +`lagoon-type-override` Build `lagoon-build-1234` Succeeded with warnings, check the build log for more information. [Logs](https://logs) +* https://route1 +* https://route2 +* https://route3 diff --git a/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/webhook.txt b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/webhook.txt new file mode 100644 index 0000000000..2d9750e7e6 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/deployFinishedWithWarnings/webhook.txt @@ -0,0 +1 @@ +{"type":"DEPLOYMENT","event":"task:deploy-openshift:finished","project":"ci-github-openshift","environment":"lagoon-type-override","buildName":"lagoon-build-1234","warnings":true,"route":"https://route1","routes":["https://route1","https://route2","https://route3"],"logLink":"https://logs"} \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/testdata/input.deployError.json b/services/logs2notifications/internal/handler/testdata/input.deployError.json index dfca8706b6..674448ac8e 100644 --- a/services/logs2notifications/internal/handler/testdata/input.deployError.json +++ b/services/logs2notifications/internal/handler/testdata/input.deployError.json @@ -4,6 +4,7 @@ "meta":{ "projectName":"ci-github-openshift", "branchName":"lagoon-type-override", + "buildStep":"applyingDeployments", "project":"ci-github-openshift", "buildName":"lagoon-build-1234", "logLink":"https://logs" diff --git a/services/logs2notifications/internal/handler/testdata/input.deployErrorImageBuild.json b/services/logs2notifications/internal/handler/testdata/input.deployErrorImageBuild.json new file mode 100644 index 0000000000..c4b69904a1 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/input.deployErrorImageBuild.json @@ -0,0 +1,12 @@ +{ + "project":"ci-github-openshift", + "event":"task:builddeploy-kubernetes:failed", + "meta":{ + "projectName":"ci-github-openshift", + "branchName":"lagoon-type-override", + "buildStep":"buildingImages", + "project":"ci-github-openshift", + "buildName":"lagoon-build-1234", + "logLink":"https://logs" + } +} diff --git a/services/logs2notifications/internal/handler/testdata/input.deployFinished.json b/services/logs2notifications/internal/handler/testdata/input.deployFinished.json index be4eb952fd..a2207c9e4f 100644 --- a/services/logs2notifications/internal/handler/testdata/input.deployFinished.json +++ b/services/logs2notifications/internal/handler/testdata/input.deployFinished.json @@ -7,6 +7,7 @@ "projectName":"ci-github-openshift", "branchName":"lagoon-type-override", "buildName":"lagoon-build-1234", + "buildStep":"complete", "route":"https://route1", "routes":["https://route1","https://route2","https://route3"], "logLink":"https://logs" diff --git a/services/logs2notifications/internal/handler/testdata/input.deployFinishedWithWarnings.json b/services/logs2notifications/internal/handler/testdata/input.deployFinishedWithWarnings.json new file mode 100644 index 0000000000..5fa7918dd2 --- /dev/null +++ b/services/logs2notifications/internal/handler/testdata/input.deployFinishedWithWarnings.json @@ -0,0 +1,15 @@ +{ + "severity":"info", + "project":"ci-github-openshift", + "uuid":"", + "event":"task:deploy-openshift:finished", + "meta":{ + "projectName":"ci-github-openshift", + "branchName":"lagoon-type-override", + "buildName":"lagoon-build-1234", + "buildStep":"completedWithWarnings", + "route":"https://route1", + "routes":["https://route1","https://route2","https://route3"], + "logLink":"https://logs" + } +} \ No newline at end of file diff --git a/services/logs2notifications/internal/handler/webhook_events.go b/services/logs2notifications/internal/handler/webhook_events.go index a272c416e8..1136434951 100644 --- a/services/logs2notifications/internal/handler/webhook_events.go +++ b/services/logs2notifications/internal/handler/webhook_events.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "net/http" + "regexp" "strings" "github.com/uselagoon/machinery/api/schema" @@ -18,6 +19,8 @@ type WebhookData struct { Project string `json:"project"` Environment string `json:"environment"` BuildName string `json:"buildName,omitempty"` + Warnings bool `json:"warnings,omitempty"` + BuildStep string `json:"buildStep,omitempty"` Route string `json:"route,omitempty"` Routes []string `json:"routes,omitempty"` LogLink string `json:"logLink,omitempty"` @@ -76,8 +79,13 @@ func (h *Messaging) processWebhookTemplate(notification *Notification) (*Webhook switch tpl { case "deployFinished": + match, _ := regexp.MatchString(".*WithWarnings$", notification.Meta.BuildStep) + if match { + data.Warnings = true + } data.Type = "DEPLOYMENT" case "deployError": + data.BuildStep = notification.Meta.BuildStep data.Type = "DEPLOYMENT" default: return nil, fmt.Errorf("no matching event") @@ -93,70 +101,52 @@ func getWebhookEvent(msgEvent string) (string, error) { } var webhookEventTypeMap = map[string]EventMap{ - "github:pull_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "gitlab:merge_request:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, - "bitbucket:pullrequest:created:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack - "bitbucket:pullrequest:created:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams - - "github:pull_request:synchronize:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "gitlab:merge_request:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, - "bitbucket:pullrequest:updated:opened:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack - "bitbucket:pullrequest:updated:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams - - "github:pull_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:fulfilled:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "bitbucket:pullrequest:rejected:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - "gitlab:merge_request:closed:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "mergeRequestClosed"}, - - "github:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, - "gitlab:remove:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "bitbucket:delete:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack - "api:deleteEnvironment": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams - - "github:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "bitbucket:repo:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - "gitlab:push:handled": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushHandled"}, - - "github:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "gitlab:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - "bitbucket:push:skipped": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "repoPushSkipped"}, - - "api:deployEnvironmentLatest": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - "api:deployEnvironmentBranch": {Emoji: "ℹ️", Color: "#E8E8E8", Template: "deployEnvironment"}, - - "task:deploy-openshift:finished": {Emoji: "✅", Color: "good", Template: "deployFinished"}, - "task:remove-openshift-resources:finished": {Emoji: "✅", Color: "good", Template: "deployFinished"}, - "task:builddeploy-openshift:complete": {Emoji: "✅", Color: "good", Template: "deployFinished"}, - "task:builddeploy-kubernetes:complete": {Emoji: "✅", Color: "good", Template: "deployFinished"}, //not in teams - - "task:remove-openshift:finished": {Emoji: "✅", Color: "good", Template: "removeFinished"}, - "task:remove-kubernetes:finished": {Emoji: "✅", Color: "good", Template: "removeFinished"}, - - "task:remove-openshift:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - "task:remove-kubernetes:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - "task:builddeploy-kubernetes:failed": {Emoji: "🛑", Color: "danger", Template: "deployError"}, //not in teams - "task:builddeploy-openshift:failed": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - - "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - "github:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning", Template: "notDeleted"}, - - // deprecated - // "rest:remove:CannotDeleteProductionEnvironment": {Emoji: "⚠️", Color: "warning"}, - // "rest:deploy:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:remove:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:promote:receive": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:deploy": {Emoji: "ℹ️", Color: "#E8E8E8"}, - // "rest:pullrequest:remove": {Emoji: "ℹ️", Color: "#E8E8E8"}, - - // deprecated - // "task:deploy-openshift:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - // "task:remove-openshift-resources:error": {Emoji: "🛑", Color: "danger", Template: "deployError"}, - - // deprecated - // "task:deploy-openshift:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, - // "task:remove-openshift:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, - // "task:remove-kubernetes:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, - // "task:remove-openshift-resources:retry": {Emoji: "⚠️", Color: "warning", Template: "removeRetry"}, + "github:pull_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "gitlab:merge_request:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, + "bitbucket:pullrequest:created:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in slack + "bitbucket:pullrequest:created:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestOpened"}, //not in teams + + "github:pull_request:synchronize:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "gitlab:merge_request:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, + "bitbucket:pullrequest:updated:opened:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in slack + "bitbucket:pullrequest:updated:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestUpdated"}, //not in teams + + "github:pull_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:fulfilled:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "bitbucket:pullrequest:rejected:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + "gitlab:merge_request:closed:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "mergeRequestClosed"}, + + "github:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, + "gitlab:remove:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "bitbucket:delete:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in slack + "api:deleteEnvironment": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deleteEnvironment"}, //not in teams + + "github:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "bitbucket:repo:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + "gitlab:push:handled": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushHandled"}, + + "github:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "gitlab:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + "bitbucket:push:skipped": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "repoPushSkipped"}, + + "api:deployEnvironmentLatest": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + "api:deployEnvironmentBranch": {Emoji: infoEmoji, Color: "#E8E8E8", Template: "deployEnvironment"}, + + "task:deploy-openshift:finished": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, + "task:remove-openshift-resources:finished": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, + "task:builddeploy-openshift:complete": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, + "task:builddeploy-kubernetes:complete": {Emoji: successEmoji, Color: "good", Template: "deployFinished"}, //not in teams + + "task:remove-openshift:finished": {Emoji: successEmoji, Color: "good", Template: "removeFinished"}, + "task:remove-kubernetes:finished": {Emoji: successEmoji, Color: "good", Template: "removeFinished"}, + + "task:remove-openshift:error": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, + "task:remove-kubernetes:error": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, + "task:builddeploy-kubernetes:failed": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, //not in teams + "task:builddeploy-openshift:failed": {Emoji: failEmoji, Color: "danger", Template: "deployError"}, + + "github:pull_request:closed:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, + "github:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, + "bitbucket:repo:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, + "gitlab:push:CannotDeleteProductionEnvironment": {Emoji: warningEmoji, Color: "warning", Template: "notDeleted"}, }