Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 881dc5e

Browse files
committed
fix: initiator
1 parent 1001bc1 commit 881dc5e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ func (s *server) CompleteJob(ctx context.Context, completed *proto.CompletedJob)
15491549

15501550
func (s *server) notifyWorkspaceDeleted(ctx context.Context, workspace database.Workspace, build database.WorkspaceBuild) {
15511551
var reason string
1552+
initiator := build.InitiatorByUsername
15521553
if build.Reason.Valid() {
15531554
switch build.Reason {
15541555
case database.BuildReasonInitiator:
@@ -1560,6 +1561,7 @@ func (s *server) notifyWorkspaceDeleted(ctx context.Context, workspace database.
15601561
reason = "initiated by user"
15611562
case database.BuildReasonAutodelete:
15621563
reason = "autodeleted due to dormancy"
1564+
initiator = ""
15631565
default:
15641566
reason = string(build.Reason)
15651567
}
@@ -1569,12 +1571,17 @@ func (s *server) notifyWorkspaceDeleted(ctx context.Context, workspace database.
15691571
slog.F("reason", reason), slog.F("workspace_id", workspace.ID), slog.F("build_id", build.ID))
15701572
}
15711573

1574+
labels := map[string]string{
1575+
"name": workspace.Name,
1576+
"reason": reason,
1577+
}
1578+
1579+
if initiator != "" {
1580+
labels["initiator"] = initiator
1581+
}
1582+
15721583
if _, err := s.NotificationEnqueuer.Enqueue(ctx, workspace.OwnerID, notifications.TemplateWorkspaceDeleted,
1573-
map[string]string{
1574-
"name": workspace.Name,
1575-
"initiator": build.InitiatorByUsername,
1576-
"reason": reason,
1577-
}, "provisionerdserver",
1584+
labels, "provisionerdserver",
15781585
// Associate this notification with all the related entities.
15791586
workspace.ID, workspace.OwnerID, workspace.TemplateID, workspace.OrganizationID,
15801587
); err != nil {

0 commit comments

Comments
 (0)