summaryrefslogtreecommitdiff
path: root/internal/api/task_view.go
diff options
context:
space:
mode:
authorClaudomator Agent <agent@claudomator>2026-03-16 20:01:59 +0000
committerClaudomator Agent <agent@claudomator>2026-03-16 20:01:59 +0000
commit1b2deb13daa788dc43d98caeaa9507254b1ca283 (patch)
treeb78fdeb30d0e96b4141ec9e66937b40018e4f99f /internal/api/task_view.go
parent054ec8b653b175917ef8bea45d55025e6775f187 (diff)
feat: display deployment status badge on READY task cards
Add deployment_status field to task list/get API responses for READY tasks. The field includes deployed_commit, fix_commits, and includes_fix so the UI can show whether the deployed server includes each fix. - internal/api/task_view.go: taskView struct + enrichTask() helper - handleListTasks/handleGetTask: return enriched taskView responses - web/app.js: export renderDeploymentBadge(); add badge to READY cards - web/test/deployment-badge.test.mjs: 8 tests for renderDeploymentBadge - web/style.css: .deployment-badge--deployed / --pending styles - server_test.go: 3 new tests (red→green) for enriched task responses Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/api/task_view.go')
-rw-r--r--internal/api/task_view.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/api/task_view.go b/internal/api/task_view.go
new file mode 100644
index 0000000..5791058
--- /dev/null
+++ b/internal/api/task_view.go
@@ -0,0 +1,41 @@
+package api
+
+import (
+ "database/sql"
+
+ "github.com/thepeterstone/claudomator/internal/deployment"
+ "github.com/thepeterstone/claudomator/internal/task"
+)
+
+// taskView wraps a task with computed fields that are derived from execution
+// history and deployment state. It is used as the JSON response type for task
+// list and get endpoints so that callers receive enriched data in one request.
+type taskView struct {
+ *task.Task
+ Changestats *task.Changestats `json:"changestats,omitempty"`
+ DeploymentStatus *deployment.Status `json:"deployment_status,omitempty"`
+}
+
+// enrichTask fetches the latest execution for the given task and attaches
+// changestats and deployment_status fields for READY tasks.
+// Non-READY tasks are returned without these extra fields.
+func (s *Server) enrichTask(tk *task.Task) *taskView {
+ view := &taskView{Task: tk}
+
+ if tk.State != task.StateReady {
+ return view
+ }
+
+ exec, err := s.store.GetLatestExecution(tk.ID)
+ if err != nil {
+ if err == sql.ErrNoRows {
+ // No execution yet — still include deployment status (empty commits).
+ view.DeploymentStatus = deployment.Check(nil, tk.Agent.ProjectDir)
+ }
+ return view
+ }
+
+ view.Changestats = exec.Changestats
+ view.DeploymentStatus = deployment.Check(exec.Commits, tk.Agent.ProjectDir)
+ return view
+}