Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add is_prebuild flag to workspace API response
  • Loading branch information
ssncferreira committed Jul 10, 2025
commit 207c80ff213447a4f7e23699573a71f6daaec9cd
3 changes: 2 additions & 1 deletion cli/testdata/coder_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"automatic_updates": "never",
"allow_renames": false,
"favorite": false,
"next_start_at": "====[timestamp]====="
"next_start_at": "====[timestamp]=====",
"is_prebuild": false
}
]
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,12 @@ func convertWorkspace(
if latestAppStatus.ID == uuid.Nil {
appStatus = nil
}

isPrebuild := false
Copy link
Contributor

@SasSwart SasSwart Jul 14, 2025

Choose a reason for hiding this comment

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

A few nonblocking thoughts:

  • Consider isPrebuilt instead of isPrebuilt. I know is a small and subtle naming change but a Prebuild is not the same thing as a prebuilt workspace.
  • Also perhaps consider a comment or something to explain that this is for unclaimed prebuilt workspaces only. A claimed workspace can still be called prebuilt and the change in this PR does not affect those.
  • should we have a prebuilds.IsUnclaimedPrebuiltWorkspace(...) function to encapsulate and abstract this logic?

Copy link
Contributor Author

@ssncferreira ssncferreira Jul 14, 2025

Choose a reason for hiding this comment

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

Consider isPrebuilt instead of isPrebuilt. I know is a small and subtle naming change but a Prebuild is not the same thing as a prebuilt workspace.

The way I have been using these terms, is Prebuild = Prebuilt Workspace, but maybe I have been using it wrong. What is the difference between Prebuild and Prebuilt Workspace?

Also perhaps consider a comment or something to explain that this is for unclaimed prebuilt workspaces only. A claimed workspace can still be called prebuilt and the change in this PR does not affect those.

Added a comment in 0bde254, let me know if it works.

should we have a prebuilds.IsUnclaimedPrebuiltWorkspace(...) function to encapsulate and abstract this logic?

Yes, we can do that and reuse it in other parts of the code that already have this logic. I can address it in a separate PR. Edit: actually, there is a better solution that I completely forgot 🤦‍♀️ which is to use workspace.IsPrebuild(). This encapsulates that logic on workspace and improves readability: 0120c5b
I will create a follow up PR to add some tests to test this parameter.

if workspace.OwnerID == database.PrebuildsSystemUserID {
isPrebuild = true
}

return codersdk.Workspace{
ID: workspace.ID,
CreatedAt: workspace.CreatedAt,
Expand Down Expand Up @@ -2265,6 +2271,7 @@ func convertWorkspace(
AllowRenames: allowRenames,
Favorite: requesterFavorite,
NextStartAt: nextStartAt,
IsPrebuild: isPrebuild,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions codersdk/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Workspace struct {
AllowRenames bool `json:"allow_renames"`
Favorite bool `json:"favorite"`
NextStartAt *time.Time `json:"next_start_at" format:"date-time"`
IsPrebuild bool `json:"is_prebuild"`
}

func (w Workspace) FullName() string {
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions docs/reference/api/workspaces.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions site/src/modules/workspaces/prebuilds.ts

This file was deleted.

Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest adding a story here to showcase the new behaviour.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 73f5476

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Link } from "components/Link/Link";
import { Loader } from "components/Loader/Loader";
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
import dayjs from "dayjs";
import { isPrebuiltWorkspace } from "modules/workspaces/prebuilds";
import {
scheduleChanged,
scheduleToAutostart,
Expand Down Expand Up @@ -98,13 +97,10 @@ const WorkspaceSchedulePage: FC = () => {
)}

{template &&
// Prebuilt workspaces have their own scheduling system,
// so we avoid showing the workspace-level schedule settings form.
// Instead, show an informational message with a link to the relevant docs.
(isPrebuiltWorkspace(workspace) ? (
(workspace.is_prebuild ? (
<Alert severity="info">
Prebuilt workspaces do not support workspace-level scheduling. For
prebuilt workspace specific scheduling refer to the{" "}
Prebuilt workspaces ignore workspace-level scheduling until they are claimed.
For prebuilt workspace specific scheduling refer to the{" "}
<Link
title="Prebuilt Workspaces Scheduling"
href={docs(
Expand Down
1 change: 1 addition & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ export const MockWorkspace: TypesGen.Workspace = {
deleting_at: null,
dormant_at: null,
next_start_at: null,
is_prebuild: false,
};

export const MockFavoriteWorkspace: TypesGen.Workspace = {
Expand Down
Loading