Skip to content

Commit

Permalink
feat(cloudevents-server): add failed message to lark notification (#198)
Browse files Browse the repository at this point in the history
Signed-off-by: wuhuizuo <[email protected]>

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo authored Nov 6, 2024
1 parent 79b3dbd commit 495e6f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cloudevents-server/pkg/events/tekton/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,8 @@ func fillInfosWithCustomRun(data *v1alpha1.Run, ret *cardMessageInfos) {
ret.Params = append(ret.Params, [2]string{p.Name, string(v)})
}
if results := data.Status.Results; len(results) > 0 {
var parts []string
for _, r := range results {
parts = append(parts, fmt.Sprintf("**%s**:", r.Name), r.Value, "---")
ret.Results = append(ret.Results, [2]string{r.Name, r.Value})

}
}
}
Expand All @@ -147,7 +144,9 @@ func fillInfosWithTaskRun(data *v1beta1.TaskRun, ret *cardMessageInfos) {
v, _ := p.Value.MarshalJSON()
ret.Params = append(ret.Params, [2]string{p.Name, string(v)})
}
if data.Status.GetCondition(apis.ConditionSucceeded).IsFalse() {
succeededCondition := data.Status.GetCondition(apis.ConditionSucceeded)
if succeededCondition.IsFalse() {
ret.FailedMessage = succeededCondition.Message
ret.RerunURL = fmt.Sprintf("tkn -n %s task start %s --use-taskrun %s",
data.Namespace, data.Spec.TaskRef.Name, data.Name)
}
Expand All @@ -166,7 +165,9 @@ func fillInfosWithPipelineRun(data *v1beta1.PipelineRun, ret *cardMessageInfos)
v, _ := p.Value.MarshalJSON()
ret.Params = append(ret.Params, [2]string{p.Name, string(v)})
}
if data.Status.GetCondition(apis.ConditionSucceeded).IsFalse() {
succeededCondition := data.Status.GetCondition(apis.ConditionSucceeded)
if succeededCondition.IsFalse() {
ret.FailedMessage = succeededCondition.Message
ret.RerunURL = fmt.Sprintf("tkn -n %s pipeline start %s --use-pipelinerun %s",
data.Namespace, data.Spec.PipelineRef.Name, data.Name)
}
Expand All @@ -175,7 +176,6 @@ func fillInfosWithPipelineRun(data *v1beta1.PipelineRun, ret *cardMessageInfos)
ret.Results = append(ret.Results, [2]string{r.Name, r.Value.StringVal})
}
}

}

func getFailedTasks(data *v1beta1.PipelineRun, logGetter func(podName, containerName string) string) map[string][]stepInfo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
config:
wide_screen_mode: true
elements:
{{- with .FailedMessage }}
- tag: markdown
content: |-
**Failed summary:** {{ . }}
- tag: hr
{{- end }}
- tag: div
fields:
{{- with .StartTime }}
Expand Down
1 change: 1 addition & 0 deletions cloudevents-server/pkg/events/tekton/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type cardMessageInfos struct {
StartTime string
EndTime string
TimeCost string
FailedMessage string
Params [][2]string // key-value pairs.
Results [][2]string // Key-Value pairs.
StepStatuses []stepInfo // name-status pairs.
Expand Down

0 comments on commit 495e6f0

Please sign in to comment.