Skip to content

fix(coderd/notifications): simplify TemplateWorkspaceManualBuildFailed #15067

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 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
UPDATE notification_templates
SET
body_template = E'Hi {{.UserName}},\n\n' ||
E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' ||
-- Mention template display name:
E'The template''s display name was **{{.Labels.template_display_name}}**. ' ||
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
WHERE
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
UPDATE notification_templates
SET
body_template = E'Hi {{.UserName}},\n\n' ||
-- Revert to a single label for the template name.:
E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' ||
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
WHERE
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';
1 change: 0 additions & 1 deletion coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,6 @@ func TestNotificationTemplates_Golden(t *testing.T) {
Labels: map[string]string{
"name": "bobby-workspace",
"template_name": "bobby-template",
"template_display_name": "William's Template",
"template_version_name": "bobby-template-version",
"initiator": "joe",
"workspace_owner_username": "mrbobby",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Hi Bobby,
A manual build of the workspace bobby-workspace using the template bobby-te=
mplate failed (version: bobby-template-version).

The template's display name was William's Template. The workspace build was=
initiated by joe.
The workspace build was initiated by joe.


View build: http://test.com/@mrbobby/bobby-workspace/builds/3
Expand Down Expand Up @@ -55,8 +54,7 @@ argin: 8px 0 32px; line-height: 1.5;">
he template <strong>bobby-template</strong> failed (version: <strong>bobby-=
template-version</strong>).</p>

<p>The template&rsquo;s display name was <strong>William&rsquo;s Template</=
strong>. The workspace build was initiated by <strong>joe</strong>.</p>
<p>The workspace build was initiated by <strong>joe</strong>.</p>
</div>
<div style=3D"text-align: center; margin-top: 32px;">
=20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"labels": {
"initiator": "joe",
"name": "bobby-workspace",
"template_display_name": "William's Template",
"template_name": "bobby-template",
"template_version_name": "bobby-template-version",
"workspace_build_number": "3",
Expand All @@ -28,6 +27,6 @@
},
"title": "Workspace \"bobby-workspace\" manual build failed",
"title_markdown": "Workspace \"bobby-workspace\" manual build failed",
"body": "Hi Bobby,\n\nA manual build of the workspace bobby-workspace using the template bobby-template failed (version: bobby-template-version).\n\nThe template's display name was William's Template. The workspace build was initiated by joe.",
"body_markdown": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**."
"body": "Hi Bobby,\n\nA manual build of the workspace bobby-workspace using the template bobby-template failed (version: bobby-template-version).\n\nThe workspace build was initiated by joe.",
"body_markdown": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe workspace build was initiated by **joe**."
}
21 changes: 12 additions & 9 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,16 +1124,19 @@ func (s *server) notifyWorkspaceManualBuildFailed(ctx context.Context, workspace
}

for _, templateAdmin := range templateAdmins {
labels := map[string]string{
"name": workspace.Name,
"template_name": template.DisplayName,
"template_version_name": templateVersion.Name,
"initiator": build.InitiatorByUsername,
"workspace_owner_username": workspaceOwner.Username,
"workspace_build_number": strconv.Itoa(int(build.BuildNumber)),
}
if template.DisplayName == "" {
labels["template_name"] = template.Name
}
if _, err := s.NotificationsEnqueuer.Enqueue(ctx, templateAdmin.ID, notifications.TemplateWorkspaceManualBuildFailed,
map[string]string{
"name": workspace.Name,
"template_name": template.Name,
"template_display_name": template.DisplayName,
"template_version_name": templateVersion.Name,
"initiator": build.InitiatorByUsername,
"workspace_owner_username": workspaceOwner.Username,
"workspace_build_number": strconv.Itoa(int(build.BuildNumber)),
}, "provisionerdserver",
labels, "provisionerdserver",
// Associate this notification with all the related entities.
workspace.ID, workspace.OwnerID, workspace.TemplateID, workspace.OrganizationID,
); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions coderd/provisionerdserver/provisionerdserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1859,8 +1859,7 @@ func TestNotifications(t *testing.T) {
assert.Contains(t, notifEnq.Sent[0].Targets, workspace.OrganizationID)
assert.Contains(t, notifEnq.Sent[0].Targets, user.ID)
assert.Equal(t, workspace.Name, notifEnq.Sent[0].Labels["name"])
assert.Equal(t, template.Name, notifEnq.Sent[0].Labels["template_name"])
assert.Equal(t, template.DisplayName, notifEnq.Sent[0].Labels["template_display_name"])
assert.Equal(t, template.DisplayName, notifEnq.Sent[0].Labels["template_name"])
assert.Equal(t, version.Name, notifEnq.Sent[0].Labels["template_version_name"])
assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["initiator"])
assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["workspace_owner_username"])
Expand Down
Loading