diff options
Diffstat (limited to 'internal/api/deployment.go')
| -rw-r--r-- | internal/api/deployment.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/api/deployment.go b/internal/api/deployment.go new file mode 100644 index 0000000..d927545 --- /dev/null +++ b/internal/api/deployment.go @@ -0,0 +1,36 @@ +package api + +import ( + "database/sql" + "net/http" + + "github.com/thepeterstone/claudomator/internal/deployment" +) + +// handleGetDeploymentStatus returns whether the currently-deployed server +// includes the commits that were produced by this task's latest execution. +// GET /api/tasks/{id}/deployment-status +func (s *Server) handleGetDeploymentStatus(w http.ResponseWriter, r *http.Request) { + id := r.PathValue("id") + + tk, err := s.store.GetTask(id) + if err != nil { + writeJSON(w, http.StatusNotFound, map[string]string{"error": "task not found"}) + return + } + + exec, err := s.store.GetLatestExecution(tk.ID) + if err != nil { + if err == sql.ErrNoRows { + // No execution yet — return status with no fix commits. + status := deployment.Check(nil, tk.Agent.ProjectDir) + writeJSON(w, http.StatusOK, status) + return + } + writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()}) + return + } + + status := deployment.Check(exec.Commits, tk.Agent.ProjectDir) + writeJSON(w, http.StatusOK, status) +} |
