Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c0e39f

Browse files
Kira-Pilotpull[bot]
authored andcommitted
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
1 parentc6f2f64 commit9c0e39f

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

‎coderd/audit.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ func (api *API) convertAuditLogs(ctx context.Context, dblogs []database.GetAudit
180180
}
181181

182182
typeAdditionalFieldsstruct {
183-
WorkspaceNamestring
184-
BuildNumberstring
183+
WorkspaceNamestring`json:"workspace_name"`
184+
BuildNumberstring`json:"build_number"`
185+
BuildReason database.BuildReason`json:"build_reason"`
185186
}
186187

187188
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
219220
resourceInfo:=map[string]string{
220221
"workspaceName":"unknown",
221222
"buildNumber":"unknown",
223+
"buildReason":"unknown",
222224
}
223225
dblog.AdditionalFields,err=json.Marshal(resourceInfo)
224226
api.Logger.Error(ctx,"marshal additional fields",slog.Error(err))
@@ -262,8 +264,8 @@ func auditLogDescription(alog database.GetAuditLogsOffsetRow, additionalFields A
262264
)
263265

264266
// Strings for starting/stopping workspace builds follow the below format:
265-
// "{user} started build #{build_number} for workspace {target}"
266-
// where target is a workspace instead of a workspace build
267+
// "{user | 'Coder automatically'} started build #{build_number} for workspace {target}"
268+
// where target is a workspace(name)instead of a workspace build
267269
// passed in on the FE via AuditLog.AdditionalFields rather than derived in request.go:35
268270
ifalog.ResourceType==database.ResourceTypeWorkspaceBuild&&alog.Action!=database.AuditActionDelete {
269271
iflen(additionalFields.BuildNumber)==0 {

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ func (server *Server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*p
550550
buildResourceInfo:=map[string]string{
551551
"workspaceName":workspace.Name,
552552
"buildNumber":strconv.FormatInt(int64(build.BuildNumber),10),
553+
"buildReason":fmt.Sprintf("%v",build.Reason),
553554
}
554555

555556
wriBytes,err:=json.Marshal(buildResourceInfo)
@@ -799,6 +800,7 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
799800
buildResourceInfo:=map[string]string{
800801
"workspaceName":workspace.Name,
801802
"buildNumber":strconv.FormatInt(int64(workspaceBuild.BuildNumber),10),
803+
"buildReason":fmt.Sprintf("%v",workspaceBuild.Reason),
802804
}
803805

804806
wriBytes,err:=json.Marshal(buildResourceInfo)

‎site/src/components/AuditLogRow/AuditLogDescription.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
1212
const{ t}=i18next
1313

1414
lettarget=auditLog.resource_target.trim()
15+
letuser=auditLog.user?.username.trim()
1516

16-
// audit logs with a resource_type of workspace build use workspace name as a target
1717
if(auditLog.resource_type==="workspace_build"){
18+
// audit logs with a resource_type of workspace build use workspace name as a target
1819
target=auditLog.additional_fields.workspaceName.trim()
20+
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
21+
user=
22+
auditLog.additional_fields.buildReason&&
23+
auditLog.additional_fields.buildReason!=="initiator"
24+
?t("auditLog:table.logRow.buildReason")
25+
:auditLog.user?.username.trim()
1926
}
2027

2128
// SSH key entries have no links
@@ -30,7 +37,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
3037
}
3138

3239
consttruncatedDescription=auditLog.description
33-
.replace("{user}",`${auditLog.user?.username.trim()}`)
40+
.replace("{user}",`${user}`)
3441
.replace("{target}","")
3542

3643
return(

‎site/src/i18n/en/auditLog.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"os":"OS:",
1414
"browser":"Browser:",
1515
"notAvailable":"Not available",
16-
"onBehalfOf":" on behalf of {{owner}}"
16+
"onBehalfOf":" on behalf of {{owner}}",
17+
"buildReason":"Coder automatically"
1718
}
1819
},
1920
"paywall": {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp