Skip to content

feat: generate golden files for notification templates #14537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Sep 4, 2024
Merged
Prev Previous commit
Next Next commit
adjust payload
  • Loading branch information
mtojek committed Sep 4, 2024
commit 994f48402818942d289a929bf14b39a2cc81f88e
10 changes: 5 additions & 5 deletions coderd/database/migrations/000249_email_reports.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ INSERT INTO notification_templates (id, name, title_template, body_template, "gr
VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"',
E'Hi {{.UserName}},

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.
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.

**Report:**

{{range $index, $version := .Labels.template_versions}}
{{add $index 1}}. "{{$version.TemplateDisplayName}}" failed {{$version.FailedCount}} time{{if gt $version.FailedCount 1}}s{{end}}:
{{range $i, $build := $version.FailedBuilds}}
* [{{$build.WorkspaceOwnerUsername}} / {{$build.WorkspaceName}} / #{{$build.BuildNumber}}]({{base_url}}/@{{$build.WorkspaceOwnerUsername}}/{{$build.WorkspaceName}}/builds/{{$build.BuildNumber}})
{{range $index, $version := .Data.template_versions}}
{{add $index 1}}. "{{$version.template_version_name}}" failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}:
{{range $i, $build := $version.failed_builds}}
* [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}})
{{end}}
{{end}}

Expand Down
50 changes: 50 additions & 0 deletions coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,56 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
},
},
},
{
name: "TemplateWorkspaceBuildSummary",
id: notifications.TemplateWorkspaceBuildSummary,
payload: types.MessagePayload{
UserName: "bobby",
Labels: map[string]string{
"template_name": "bobby-first-template",
"template_display_name": "Bobby First Template",
},
Data: map[string]any{
"failed_builds": 4,
"total_builds": 55,
"report_frequency": "week",
"template_versions": []map[string]any{
{
"template_version_name": "bobby-template-version-1",
"failed_count": 3,
"builds": []map[string]any{
{
"workspace_owner_username": "mtojek",
"workspace_name": "workspace-1",
"build_number": 1234,
},
{
"workspace_owner_username": "johndoe",
"workspace_name": "my-workspace-3",
"build_number": 5678,
},
{
"workspace_owner_username": "jack",
"workspace_name": "workwork",
"build_number": 774,
},
},
},
{
"template_version_name": "bobby-template-version-2",
"failed_count": 1,
"builds": []map[string]any{
{
"workspace_owner_username": "ben",
"workspace_name": "cool-workspace",
"build_number": 8888,
},
},
},
},
},
},
},
}

allTemplates, err := enumerateAllTemplates(t)
Expand Down
1 change: 1 addition & 0 deletions coderd/notifications/types/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type MessagePayload struct {

Actions []TemplateAction `json:"actions"`
Labels map[string]string `json:"labels"`
Data map[string]any `json:"data,omitempty"`
}
Loading