-
Notifications
You must be signed in to change notification settings - Fork 943
feat: notify template owner on manual build failures #14262
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
Changes from 1 commit
f673b57
2ad3450
cdf247b
9c36cb8
f81611d
d5ecc0f
35abdae
204b17e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1021,7 +1021,7 @@ func (s *server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*proto. | |||||||
} | ||||||||
|
||||||||
// Only notify auto build failures | ||||||||
autoBuild := build.Reason.Valid() && build.Reason != database.BuildReasonInitiator | ||||||||
autoBuild := build.Reason != database.BuildReasonInitiator | ||||||||
if autoBuild { | ||||||||
s.notifyWorkspaceBuildFailed(ctx, workspace, build, workspace.OwnerID) | ||||||||
} | ||||||||
|
@@ -1032,7 +1032,7 @@ func (s *server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*proto. | |||||||
s.Logger.Warn(ctx, "failed to find template admins for template build failed notification", slog.Error(err)) | ||||||||
} else { | ||||||||
for _, admin := range admins { | ||||||||
if admin.ID != build.InitiatorID { | ||||||||
if admin.ID != build.InitiatorID && !autoBuild { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
s.notifyTemplateBuildFailed(ctx, workspace, build, admin.ID) | ||||||||
} | ||||||||
} | ||||||||
|
@@ -1143,19 +1143,13 @@ func (s *server) notifyTemplateBuildFailed(ctx context.Context, workspace databa | |||||||
return | ||||||||
} | ||||||||
|
||||||||
// We only need to know the reason when it is not initiated by the user. | ||||||||
var reason string | ||||||||
if build.Reason != database.BuildReasonInitiator { | ||||||||
reason = string(build.Reason) | ||||||||
} | ||||||||
|
||||||||
if _, err := s.NotificationsEnqueuer.Enqueue(ctx, receiverID, notifications.TemplateTemplateBuildFailed, | ||||||||
map[string]string{ | ||||||||
"name": template.Name, | ||||||||
"version": version.Name, | ||||||||
"workspaceName": workspace.Name, | ||||||||
"transition": string(build.Transition), | ||||||||
"reason": reason, | ||||||||
"reason": string(build.Reason), | ||||||||
"initiator": build.InitiatorByUsername, | ||||||||
"workspaceOwnerName": owner.Username, | ||||||||
"buildNumber": strconv.FormatInt(int64(build.BuildNumber), 10), | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1829,15 +1829,15 @@ func TestNotifications(t *testing.T) { | |
tc := []struct { | ||
name string | ||
tplOwner database.User | ||
buildInitiator *database.User | ||
buildInitiator database.User | ||
reason database.BuildReason | ||
transition database.WorkspaceTransition | ||
receivers []uuid.UUID | ||
}{ | ||
{ | ||
name: "ManualBuild", | ||
tplOwner: ownerA, | ||
buildInitiator: &ownerB, | ||
buildInitiator: ownerB, | ||
reason: database.BuildReasonInitiator, | ||
transition: database.WorkspaceTransitionStart, | ||
// Ensure that during manual builds, the initiator does not receive a | ||
|
@@ -1848,7 +1848,7 @@ func TestNotifications(t *testing.T) { | |
{ | ||
name: "AutoBuild", | ||
tplOwner: ownerA, | ||
buildInitiator: nil, | ||
buildInitiator: ownerA, | ||
reason: database.BuildReasonAutostart, | ||
transition: database.WorkspaceTransitionStart, | ||
// Ensure that during automated builds, all template admins and owners | ||
|
@@ -1860,7 +1860,7 @@ func TestNotifications(t *testing.T) { | |
for _, c := range tc { | ||
t.Run(c.name, func(t *testing.T) { | ||
// Given: a template and a workspace build | ||
isManualBuild := c.buildInitiator != nil && c.reason == database.BuildReasonInitiator | ||
isManualBuild := c.reason == database.BuildReasonInitiator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you have this logic in multiple places, it might be worth creating a helper method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try and group your code into logical blocks, and use whitespace for visual assistance. Think of your code as having the same visual hierarchy that you'd design in your frontends. For example, You've got a whole lot of code below which is doing several things; add a bit of spaces and/or comments to give the reader's "eye" some space to "breathe", and group related concepts/lines together to infer relationships. |
||
template := dbgen.Template(t, db, database.Template{ | ||
Name: "template", | ||
Provisioner: database.ProvisionerTypeEcho, | ||
|
@@ -1883,16 +1883,17 @@ func TestNotifications(t *testing.T) { | |
OwnerID: workspaceOwner.ID, | ||
OrganizationID: pd.OrganizationID, | ||
}) | ||
build := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ | ||
b := database.WorkspaceBuild{ | ||
WorkspaceID: workspace.ID, | ||
TemplateVersionID: version.ID, | ||
Transition: c.transition, | ||
Reason: c.reason, | ||
}) | ||
} | ||
// Set the build initiator if the test case specifies one for manual builds. | ||
if isManualBuild { | ||
build.InitiatorID = c.buildInitiator.ID | ||
b.InitiatorID = c.buildInitiator.ID | ||
} | ||
build := dbgen.WorkspaceBuild(t, db, b) | ||
file := dbgen.File(t, db, database.File{CreatedBy: c.buildInitiator.ID}) | ||
job := dbgen.ProvisionerJob(t, db, ps, database.ProvisionerJob{ | ||
FileID: file.ID, | ||
|
@@ -1943,7 +1944,7 @@ func TestNotifications(t *testing.T) { | |
require.Equal(t, n.Labels["workspaceName"], workspace.Name) | ||
require.Equal(t, n.Labels["transition"], string(build.Transition)) | ||
require.Equal(t, n.Labels["reason"], string(build.Reason)) | ||
require.Equal(t, n.Labels["workspaceOwnerName"], workspaceOwner.Name) | ||
require.Equal(t, n.Labels["workspaceOwnerName"], workspaceOwner.Username) | ||
require.Equal(t, n.Labels["buildNumber"], strconv.FormatInt(int64(build.BuildNumber), 10)) | ||
if isManualBuild { | ||
require.Equal(t, n.Labels["initiator"], c.buildInitiator.Username) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather that this comment explain what classifies as an auto build (i.e. not initiated by a user)