mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
feat: indicate when workspace builds are stopped/started by Coder (#5813)
* feat: indicate when workspace_builds are stopped/started by Coder * added translattion * added json tags and adjust type
This commit is contained in:
@ -180,8 +180,9 @@ func (api *API) convertAuditLogs(ctx context.Context, dblogs []database.GetAudit
|
||||
}
|
||||
|
||||
type AdditionalFields struct {
|
||||
WorkspaceName string
|
||||
BuildNumber string
|
||||
WorkspaceName string `json:"workspace_name"`
|
||||
BuildNumber string `json:"build_number"`
|
||||
BuildReason database.BuildReason `json:"build_reason"`
|
||||
}
|
||||
|
||||
func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
|
||||
@ -219,6 +220,7 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
|
||||
resourceInfo := map[string]string{
|
||||
"workspaceName": "unknown",
|
||||
"buildNumber": "unknown",
|
||||
"buildReason": "unknown",
|
||||
}
|
||||
dblog.AdditionalFields, err = json.Marshal(resourceInfo)
|
||||
api.Logger.Error(ctx, "marshal additional fields", slog.Error(err))
|
||||
@ -262,8 +264,8 @@ func auditLogDescription(alog database.GetAuditLogsOffsetRow, additionalFields A
|
||||
)
|
||||
|
||||
// Strings for starting/stopping workspace builds follow the below format:
|
||||
// "{user} started build #{build_number} for workspace {target}"
|
||||
// where target is a workspace instead of a workspace build
|
||||
// "{user | 'Coder automatically'} started build #{build_number} for workspace {target}"
|
||||
// where target is a workspace (name) instead of a workspace build
|
||||
// passed in on the FE via AuditLog.AdditionalFields rather than derived in request.go:35
|
||||
if alog.ResourceType == database.ResourceTypeWorkspaceBuild && alog.Action != database.AuditActionDelete {
|
||||
if len(additionalFields.BuildNumber) == 0 {
|
||||
|
@ -550,6 +550,7 @@ func (server *Server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*p
|
||||
buildResourceInfo := map[string]string{
|
||||
"workspaceName": workspace.Name,
|
||||
"buildNumber": strconv.FormatInt(int64(build.BuildNumber), 10),
|
||||
"buildReason": fmt.Sprintf("%v", build.Reason),
|
||||
}
|
||||
|
||||
wriBytes, err := json.Marshal(buildResourceInfo)
|
||||
@ -799,6 +800,7 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
|
||||
buildResourceInfo := map[string]string{
|
||||
"workspaceName": workspace.Name,
|
||||
"buildNumber": strconv.FormatInt(int64(workspaceBuild.BuildNumber), 10),
|
||||
"buildReason": fmt.Sprintf("%v", workspaceBuild.Reason),
|
||||
}
|
||||
|
||||
wriBytes, err := json.Marshal(buildResourceInfo)
|
||||
|
Reference in New Issue
Block a user