-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publisher): pretty the notify lark message (#200)
Signed-off-by: wuhuizuo <[email protected]> Signed-off-by: wuhuizuo <[email protected]>
- Loading branch information
Showing
7 changed files
with
309 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package impl | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"text/template" | ||
|
||
"github.com/Masterminds/sprig/v3" | ||
"gopkg.in/yaml.v3" | ||
|
||
_ "embed" | ||
) | ||
|
||
//go:embed lark_templates/tiup-publish-failure-notify.yaml.tmpl | ||
var larkTemplateBytes string | ||
|
||
func newLarkCardWithGoTemplate(infos any) (string, error) { | ||
tmpl, err := template.New("lark").Funcs(sprig.FuncMap()).Parse(larkTemplateBytes) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
tmplResult := new(bytes.Buffer) | ||
if err := tmpl.Execute(tmplResult, infos); err != nil { | ||
return "", err | ||
} | ||
|
||
values := make(map[string]interface{}) | ||
if err := yaml.Unmarshal(tmplResult.Bytes(), &values); err != nil { | ||
return "", err | ||
} | ||
|
||
jsonBytes, err := json.Marshal(values) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(jsonBytes), nil | ||
} | ||
|
||
type failureNotifyInfo struct { | ||
Title string | ||
RerunCommands string | ||
FailedMessage string | ||
Params [][2]string // key-value pairs. | ||
} |
39 changes: 39 additions & 0 deletions
39
publisher/pkg/impl/lark_templates/tiup-publish-failure-notify.yaml.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
msg_type: interactive | ||
card: | ||
config: | ||
wide_screen_mode: true | ||
elements: | ||
{{- with .FailedMessage }} | ||
- tag: markdown | ||
content: |- | ||
**Failed summary:** | ||
```text | ||
{{ indent 8 . }} | ||
``` | ||
- tag: hr | ||
{{- end }} | ||
{{- with .Params }} | ||
- tag: markdown | ||
content: |- | ||
**Params:** | ||
{{- range . }} | ||
- **{{ index . 0 }}:** {{ index . 1 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- with .RerunCommands }} | ||
- tag: hr | ||
- tag: markdown | ||
content: |- | ||
🔧 **Rerun:** | ||
|
||
```BASH | ||
{{ . }} | ||
``` | ||
{{- end }} | ||
|
||
header: | ||
template: red # blue | wathet | turquoise | green | yellow | orange | red | carmine | violet | purple | indigo | grey | ||
title: | ||
content: {{ .Title }} | ||
tag: plain_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.