Skip to content

fix: ensure reason present for workspace autoupdated notification #17935

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 2 commits into from
May 20, 2025

Conversation

DanielleMaywood
Copy link
Contributor

Fixes #17930

Update the WorkspaceAutoUpdated notification to only display the reason if it is present.

…autoupdated

Fixes #17930

Update the `WorkspaceAutoUpdated` notification to only display the
reason if it is present.
@DanielleMaywood DanielleMaywood changed the title fix(coderd/notifications): only show reason if present for workspace autoupdated fix(coderd/notifications): omit reason if empty for workspace autoupdated May 20, 2025
@DanielleMaywood DanielleMaywood marked this pull request as ready for review May 20, 2025 11:28
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the WorkspaceAutoUpdated notification to suppress the “Reason for update” block when no reason is provided.

  • Adds golden fixtures for both webhook and SMTP outputs when .Labels.template_version_message is empty
  • Introduces a conditional in the SQL migration to append the reason only if present
  • Adds a new test case to verify rendering when no message is provided

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden New JSON fixture showing no reason block
coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden New HTML fixture showing no reason block
coderd/notifications/notifications_test.go Added TemplateWorkspaceAutoUpdated_NoMessage test case
coderd/database/migrations/000328_fix_workspace_update_reason.up.sql Updated body_template to conditionally include the reason block
coderd/database/migrations/000328_fix_workspace_update_reason.down.sql Restores original template with unconditional reason block
Comments suppressed due to low confidence (1)

coderd/notifications/notifications_test.go:849

  • Consider adding a complementary test case where template_version_message is non-empty to verify that the reason block renders correctly under the conditional.
name: "TemplateWorkspaceAutoUpdated_NoMessage",

@@ -0,0 +1,4 @@
UPDATE notification_templates
SET body_template = E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).' ||
E'{{if .Labels.template_version_message}}\n\nReason for update: **{{.Labels.template_version_message}}**.{{end}}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be easier to inject a default non-empty value for the reason instead of excluding it?
As a receiver of this notification, if I see this reason sometimes but not other times then it'll be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like "No reason given"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work, although I think it'd be good to find out why we don't specify a reason.

Copy link
Member

@ethanndickson ethanndickson May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just None / None provided?

Copy link
Contributor Author

@DanielleMaywood DanielleMaywood May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work, although I think it'd be good to find out why we don't specify a reason.

When making a new template version, if there is no message specified in the optional field, then this field will end up empty on a workspace auto update.

I'll go with @ethanndickson's suggestion of None provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, "template version updated" would make more sense than "none provided", no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd assume "template version updated" is implied by the prior part of the notification, so I feel like we don't need to repeat that.

Your workspace {{.Labels.name}} has been updated automatically to the latest template version ({{.Labels.template_version_name}}).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK 👍

@DanielleMaywood
Copy link
Contributor Author

I've updated the PR to conditionally check the argument provided to the template instead of making a change to the template itself.

@DanielleMaywood DanielleMaywood changed the title fix(coderd/notifications): omit reason if empty for workspace autoupdated fix: ensure reason present for workspace autoupdated notification May 20, 2025
@DanielleMaywood DanielleMaywood changed the title fix: ensure reason present for workspace autoupdated notification fix: ensure reason present for workspace autoupdated notification May 20, 2025
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DanielleMaywood DanielleMaywood merged commit 1267c9c into main May 20, 2025
33 checks passed
@DanielleMaywood DanielleMaywood deleted the dm-update-reason-notif branch May 20, 2025 15:01
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Workspace update notifications with an empty template version message aren't handled
3 participants