Skip to content

Commit 51d3abb

Browse files
feat(site): use new task data model and endpoints (coder#20431)
Updates the UI to use the new API endpoints for tasks and use its new data model. Disclaimer: Since the base data model for tasks changed, we had to do a quite large refactor and I'm sorry for that 🙏, but you'll notice most of the changes are to adjust the types. Closes coder/internal#976 --------- Co-authored-by: Bruno Quaresma <bruno_nonato_quaresma@hotmail.com>
1 parent c6e551f commit 51d3abb

32 files changed

+606
-658
lines changed

cli/exp_task_status_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ func Test_TaskStatus(t *testing.T) {
240240
"template_display_name": "",
241241
"template_icon": "",
242242
"workspace_id": null,
243+
"workspace_name": "",
243244
"workspace_status": "running",
244245
"workspace_agent_id": null,
245246
"workspace_agent_lifecycle": "ready",

coderd/aitasks.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,15 @@ func taskFromDBTaskAndWorkspace(dbTask database.Task, ws codersdk.Workspace) cod
339339
OrganizationID: dbTask.OrganizationID,
340340
OwnerID: dbTask.OwnerID,
341341
OwnerName: ws.OwnerName,
342+
OwnerAvatarURL: ws.OwnerAvatarURL,
342343
Name: dbTask.Name,
343344
TemplateID: ws.TemplateID,
344345
TemplateVersionID: dbTask.TemplateVersionID,
345346
TemplateName: ws.TemplateName,
346347
TemplateDisplayName: ws.TemplateDisplayName,
347348
TemplateIcon: ws.TemplateIcon,
348349
WorkspaceID: dbTask.WorkspaceID,
350+
WorkspaceName: ws.Name,
349351
WorkspaceBuildNumber: dbTask.WorkspaceBuildNumber.Int32,
350352
WorkspaceStatus: ws.LatestBuild.Status,
351353
WorkspaceAgentID: dbTask.WorkspaceAgentID,
@@ -360,21 +362,13 @@ func taskFromDBTaskAndWorkspace(dbTask database.Task, ws codersdk.Workspace) cod
360362
}
361363
}
362364

363-
// tasksListResponse wraps a list of experimental tasks.
364-
//
365-
// Experimental: Response shape is experimental and may change.
366-
type tasksListResponse struct {
367-
Tasks []codersdk.Task `json:"tasks"`
368-
Count int `json:"count"`
369-
}
370-
371365
// @Summary List AI tasks
372366
// @Description: EXPERIMENTAL: this endpoint is experimental and not guaranteed to be stable.
373367
// @ID list-tasks
374368
// @Security CoderSessionToken
375369
// @Tags Experimental
376370
// @Param q query string false "Search query for filtering tasks. Supports: owner:<username/uuid/me>, organization:<org-name/uuid>, status:<status>"
377-
// @Success 200 {object} coderd.tasksListResponse
371+
// @Success 200 {object} codersdk.TasksListResponse
378372
// @Router /api/experimental/tasks [get]
379373
//
380374
// EXPERIMENTAL: This endpoint is experimental and not guaranteed to be stable.
@@ -413,7 +407,7 @@ func (api *API) tasksList(rw http.ResponseWriter, r *http.Request) {
413407
return
414408
}
415409

416-
httpapi.Write(ctx, rw, http.StatusOK, tasksListResponse{
410+
httpapi.Write(ctx, rw, http.StatusOK, codersdk.TasksListResponse{
417411
Tasks: tasks,
418412
Count: len(tasks),
419413
})

coderd/aitasks_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func TestTasks(t *testing.T) {
268268
require.True(t, ok, "task should be found in the list")
269269
assert.Equal(t, wantPrompt, got.InitialPrompt, "task prompt should match the AI Prompt parameter")
270270
assert.Equal(t, task.WorkspaceID.UUID, got.WorkspaceID.UUID, "workspace id should match")
271+
assert.Equal(t, task.WorkspaceName, got.WorkspaceName, "workspace name should match")
271272
// Status should be populated via the tasks_with_status view.
272273
assert.NotEmpty(t, got.Status, "task status should not be empty")
273274
assert.NotEmpty(t, got.WorkspaceStatus, "workspace status should not be empty")
@@ -323,6 +324,7 @@ func TestTasks(t *testing.T) {
323324
assert.Equal(t, task.Name, updated.Name, "task name should match")
324325
assert.Equal(t, wantPrompt, updated.InitialPrompt, "task prompt should match the AI Prompt parameter")
325326
assert.Equal(t, task.WorkspaceID.UUID, updated.WorkspaceID.UUID, "workspace id should match")
327+
assert.Equal(t, task.WorkspaceName, updated.WorkspaceName, "workspace name should match")
326328
assert.Equal(t, ws.LatestBuild.BuildNumber, updated.WorkspaceBuildNumber, "workspace build number should match")
327329
assert.Equal(t, agentID, updated.WorkspaceAgentID.UUID, "workspace agent id should match")
328330
assert.Equal(t, taskAppID, updated.WorkspaceAppID.UUID, "workspace app id should match")

coderd/apidoc/docs.go

Lines changed: 21 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 21 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/aitasks.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ type Task struct {
156156
OrganizationID uuid.UUID `json:"organization_id" format:"uuid" table:"organization id"`
157157
OwnerID uuid.UUID `json:"owner_id" format:"uuid" table:"owner id"`
158158
OwnerName string `json:"owner_name" table:"owner name"`
159+
OwnerAvatarURL string `json:"owner_avatar_url,omitempty" table:"owner avatar url"`
159160
Name string `json:"name" table:"name,default_sort"`
160161
TemplateID uuid.UUID `json:"template_id" format:"uuid" table:"template id"`
161162
TemplateVersionID uuid.UUID `json:"template_version_id" format:"uuid" table:"template version id"`
162163
TemplateName string `json:"template_name" table:"template name"`
163164
TemplateDisplayName string `json:"template_display_name" table:"template display name"`
164165
TemplateIcon string `json:"template_icon" table:"template icon"`
165166
WorkspaceID uuid.NullUUID `json:"workspace_id" format:"uuid" table:"workspace id"`
167+
WorkspaceName string `json:"workspace_name" table:"workspace name"`
166168
WorkspaceStatus WorkspaceStatus `json:"workspace_status,omitempty" enums:"pending,starting,running,stopping,stopped,failed,canceling,canceled,deleting,deleted" table:"workspace status"`
167169
WorkspaceBuildNumber int32 `json:"workspace_build_number,omitempty" table:"workspace build number"`
168170
WorkspaceAgentID uuid.NullUUID `json:"workspace_agent_id" format:"uuid" table:"workspace agent id"`
@@ -200,6 +202,14 @@ type TasksFilter struct {
200202
FilterQuery string `json:"filter_query,omitempty"`
201203
}
202204

205+
// TaskListResponse is the response shape for tasks list.
206+
//
207+
// Experimental response shape for tasks list (server returns []Task).
208+
type TasksListResponse struct {
209+
Tasks []Task `json:"tasks"`
210+
Count int `json:"count"`
211+
}
212+
203213
func (f TasksFilter) asRequestOption() RequestOption {
204214
return func(r *http.Request) {
205215
var params []string
@@ -242,12 +252,7 @@ func (c *ExperimentalClient) Tasks(ctx context.Context, filter *TasksFilter) ([]
242252
return nil, ReadBodyAsError(res)
243253
}
244254

245-
// Experimental response shape for tasks list (server returns []Task).
246-
type tasksListResponse struct {
247-
Tasks []Task `json:"tasks"`
248-
Count int `json:"count"`
249-
}
250-
var tres tasksListResponse
255+
var tres TasksListResponse
251256
if err := json.NewDecoder(res.Body).Decode(&tres); err != nil {
252257
return nil, err
253258
}

docs/reference/api/experimental.md

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)