Skip to content

Commit 9d71a83

Browse files
committed
just the template
1 parent cd7ce8e commit 9d71a83

8 files changed

+97
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELETE FROM notification_templates WHERE id = '34a20db2-e9cc-4a93-b0e4-8569699d7a00';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
INSERT INTO notification_templates (id, name, title_template, body_template, "group", actions)
2+
VALUES ('34a20db2-e9cc-4a93-b0e4-8569699d7a00', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"',
3+
E'Hi {{.UserName}},
4+
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.
6+
7+
**Report:**
8+
{{range $version := .Data.template_versions}}
9+
**{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}:
10+
{{range $build := $version.failed_builds}}
11+
* [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}})
12+
{{- end}}
13+
{{end}}
14+
We recommend reviewing these issues to ensure future builds are successful.',
15+
'Template Events', '[
16+
{
17+
"label": "View workspaces",
18+
"url": "{{ base_url }}/workspaces?filter=template%3A{{.Labels.template_name}}"
19+
}
20+
]'::jsonb);

coderd/notifications/enqueuer.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUI
6969
dispatchMethod = metadata.CustomMethod.NotificationMethod
7070
}
7171

72-
payload, err := s.buildPayload(metadata, labels)
72+
data := map[string]any{} // FIXME
73+
payload, err := s.buildPayload(metadata, labels, data)
7374
if err != nil {
7475
s.log.Warn(ctx, "failed to build payload", slog.F("template_id", templateID), slog.F("user_id", userID), slog.Error(err))
7576
return nil, xerrors.Errorf("enqueue notification (payload build): %w", err)
@@ -119,7 +120,7 @@ func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUI
119120
// buildPayload creates the payload that the notification will for variable substitution and/or routing.
120121
// The payload contains information about the recipient, the event that triggered the notification, and any subsequent
121122
// actions which can be taken by the recipient.
122-
func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string) (*types.MessagePayload, error) {
123+
func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string, data map[string]any) (*types.MessagePayload, error) {
123124
payload := types.MessagePayload{
124125
Version: "1.0",
125126

@@ -131,6 +132,8 @@ func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRo
131132
UserUsername: metadata.UserUsername,
132133

133134
Labels: labels,
135+
Data: data,
136+
134137
// No actions yet
135138
}
136139

coderd/notifications/events.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ var (
2929
// Template-related events.
3030
var (
3131
TemplateTemplateDeleted = uuid.MustParse("29a09665-2a4c-403f-9648-54301670e7be")
32+
33+
TemplateWorkspaceBuildSummary = uuid.MustParse("34a20db2-e9cc-4a93-b0e4-8569699d7a00")
3234
)

coderd/notifications/notifications_test.go

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

849899
allTemplates, err := enumerateAllTemplates(t)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Hi Bobby,
2+
3+
Template **Bobby First Template** has failed to build 4/55 times over the last week and may be unstable.
4+
5+
**Report:**
6+
7+
**bobby-template-version-1** failed 3 times:
8+
9+
* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234)
10+
* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678)
11+
* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774)
12+
13+
**bobby-template-version-2** failed 1 time:
14+
15+
* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888)
16+
17+
We recommend reviewing these issues to ensure future builds are successful.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Workspace builds failed for template "Bobby First Template"

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)