Unify active task loading across API handlers
This commit is contained in:
@@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
@@ -13,19 +12,8 @@ import (
|
||||
var objectID = regexp.MustCompile(`^[0-9a-f]{40}([0-9a-f]{24})?$`)
|
||||
|
||||
func (s *Server) GetTaskChanges(w http.ResponseWriter, r *http.Request, taskID string, params api.GetTaskChangesParams) {
|
||||
t, err := s.store.GetTask(r.Context(), taskID)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
if t.Status != api.TaskStatusActive {
|
||||
writeError(w, http.StatusConflict, fmt.Errorf("task %s is %s and has no worktree", t.Id, t.Status))
|
||||
return
|
||||
}
|
||||
|
||||
p, err := s.store.GetProject(r.Context(), t.ProjectId)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
t, p, ok := s.activeTaskProject(w, r, taskID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -96,13 +84,8 @@ func (s *Server) stepBase(r *http.Request, t api.Task, snap api.Snapshot) (strin
|
||||
}
|
||||
|
||||
func (s *Server) GetTaskDiff(w http.ResponseWriter, r *http.Request, taskID string, params api.GetTaskDiffParams) {
|
||||
t, err := s.store.GetTask(r.Context(), taskID)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
if t.Status != api.TaskStatusActive {
|
||||
writeError(w, http.StatusConflict, fmt.Errorf("task %s is %s and has no worktree", t.Id, t.Status))
|
||||
t, ok := s.activeTask(w, r, taskID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if !objectID.MatchString(params.Base) || !objectID.MatchString(params.Tree) {
|
||||
|
||||
Reference in New Issue
Block a user