Skip to content

Commit

Permalink
fix(cloudevents-server): refactor results parts for tekton run notifi…
Browse files Browse the repository at this point in the history
…cation message (#73)

Signed-off-by: wuhuizuo <wuhuizuo@126.com>

Signed-off-by: wuhuizuo <wuhuizuo@126.com>
  • Loading branch information
wuhuizuo authored Feb 18, 2024
1 parent 594e266 commit 0f5542f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cloudevents-server/pkg/events/custom/tekton/lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ func extractLarkInfosFromEvent(event cloudevents.Event, baseURL string) (*cardMe
if results := data.PipelineRun.Status.PipelineResults; len(results) > 0 {
var parts []string
for _, r := range results {
parts = append(parts, fmt.Sprintf("**%s**:", r.Name), r.Value, "---")
parts = append(parts, fmt.Sprintf("%s:", r.Name), r.Value)
ret.Results = append(ret.Results, [2]string{r.Name, r.Value})
}
ret.Results = strings.Join(parts, "\n")
}
case data.TaskRun != nil:
startTime = data.TaskRun.Status.StartTime
Expand All @@ -170,8 +170,8 @@ func extractLarkInfosFromEvent(event cloudevents.Event, baseURL string) (*cardMe
for _, r := range results {
v, _ := r.Value.MarshalJSON()
parts = append(parts, fmt.Sprintf("**%s**:", r.Name), string(v), "---")
ret.Results = append(ret.Results, [2]string{r.Name, string(v)})
}
ret.Results = strings.Join(parts, "\n")
}
case data.Run != nil:
startTime = data.Run.Status.StartTime
Expand All @@ -181,8 +181,9 @@ func extractLarkInfosFromEvent(event cloudevents.Event, baseURL string) (*cardMe
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})

}
ret.Results = strings.Join(parts, "\n")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ elements:
- tag: markdown
content: |-
**Results:**

{{ indent 6 . }}
{{- range . }}
- **{{ index . 0 }}:**
```YAML
{{ indent 6 (index . 1) }}
```
{{- end }}
{{- end }}
{{- with .RerunURL }}
- tag: hr
- tag: markdown
content: |-
🔧 **Rerun:**

{{ . }}"
```BASH
{{ . }}
```
{{- end }}
- tag: action
actions:
Expand Down
2 changes: 1 addition & 1 deletion cloudevents-server/pkg/events/custom/tekton/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type cardMessageInfos struct {
StartTime string
EndTime string
TimeCost string
Results string
Results [][2]string // Key-Value pairs.
}

var larkCardHeaderTemplates = map[tektoncloudevent.TektonEventType]string{
Expand Down

0 comments on commit 0f5542f

Please sign in to comment.