Skip to content

Commit 994f484

Browse files
committed
adjust payload
1 parent d9fef24 commit 994f484

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

coderd/database/migrations/000249_email_reports.up.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ INSERT INTO notification_templates (id, name, title_template, body_template, "gr
22
VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"',
33
E'Hi {{.UserName}},
44
5-
Template {{.Labels.template_display_name}} has failed to build {{.Labels.failed_builds})/{{.Labels.total_builds}} times over the last {{.Labels.report_frequency}} and may be unstable.
5+
Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_builds})/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable.
66
77
**Report:**
88
9-
{{range $index, $version := .Labels.template_versions}}
10-
{{add $index 1}}. "{{$version.TemplateDisplayName}}" failed {{$version.FailedCount}} time{{if gt $version.FailedCount 1}}s{{end}}:
11-
{{range $i, $build := $version.FailedBuilds}}
12-
* [{{$build.WorkspaceOwnerUsername}} / {{$build.WorkspaceName}} / #{{$build.BuildNumber}}]({{base_url}}/@{{$build.WorkspaceOwnerUsername}}/{{$build.WorkspaceName}}/builds/{{$build.BuildNumber}})
9+
{{range $index, $version := .Data.template_versions}}
10+
{{add $index 1}}. "{{$version.template_version_name}}" failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}:
11+
{{range $i, $build := $version.failed_builds}}
12+
* [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}})
1313
{{end}}
1414
{{end}}
1515

coderd/notifications/notifications_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,56 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
837837
},
838838
},
839839
},
840+
{
841+
name: "TemplateWorkspaceBuildSummary",
842+
id: notifications.TemplateWorkspaceBuildSummary,
843+
payload: types.MessagePayload{
844+
UserName: "bobby",
845+
Labels: map[string]string{
846+
"template_name": "bobby-first-template",
847+
"template_display_name": "Bobby First Template",
848+
},
849+
Data: map[string]any{
850+
"failed_builds": 4,
851+
"total_builds": 55,
852+
"report_frequency": "week",
853+
"template_versions": []map[string]any{
854+
{
855+
"template_version_name": "bobby-template-version-1",
856+
"failed_count": 3,
857+
"builds": []map[string]any{
858+
{
859+
"workspace_owner_username": "mtojek",
860+
"workspace_name": "workspace-1",
861+
"build_number": 1234,
862+
},
863+
{
864+
"workspace_owner_username": "johndoe",
865+
"workspace_name": "my-workspace-3",
866+
"build_number": 5678,
867+
},
868+
{
869+
"workspace_owner_username": "jack",
870+
"workspace_name": "workwork",
871+
"build_number": 774,
872+
},
873+
},
874+
},
875+
{
876+
"template_version_name": "bobby-template-version-2",
877+
"failed_count": 1,
878+
"builds": []map[string]any{
879+
{
880+
"workspace_owner_username": "ben",
881+
"workspace_name": "cool-workspace",
882+
"build_number": 8888,
883+
},
884+
},
885+
},
886+
},
887+
},
888+
},
889+
},
840890
}
841891

842892
allTemplates, err := enumerateAllTemplates(t)

coderd/notifications/types/payload.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ type MessagePayload struct {
1616

1717
Actions []TemplateAction `json:"actions"`
1818
Labels map[string]string `json:"labels"`
19+
Data map[string]any `json:"data,omitempty"`
1920
}

0 commit comments

Comments
 (0)