You've already forked agentic-coding-workflow
功能补齐、查看git提交历史
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
@@ -59,6 +60,7 @@ func (h *Handler) Mount(r chi.Router) {
|
||||
r.Get("/main/status", h.statusOnMain)
|
||||
r.Post("/main/commit", h.commitOnMain)
|
||||
r.Post("/main/push", h.pushOnMain)
|
||||
r.Get("/main/log", h.logOnMain)
|
||||
|
||||
r.Get("/worktrees", h.listWorktrees)
|
||||
r.Post("/worktrees", h.createWorktree)
|
||||
@@ -71,6 +73,7 @@ func (h *Handler) Mount(r chi.Router) {
|
||||
r.Get("/status", h.statusOnWorktree)
|
||||
r.Post("/commit", h.commitOnWorktree)
|
||||
r.Post("/push", h.pushOnWorktree)
|
||||
r.Get("/log", h.logOnWorktree)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -536,3 +539,59 @@ func (h *Handler) pushGeneric(w http.ResponseWriter, r *http.Request, onMain boo
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *Handler) logOnMain(w http.ResponseWriter, r *http.Request) {
|
||||
h.logGeneric(w, r, true)
|
||||
}
|
||||
|
||||
func (h *Handler) logOnWorktree(w http.ResponseWriter, r *http.Request) {
|
||||
h.logGeneric(w, r, false)
|
||||
}
|
||||
|
||||
func (h *Handler) logGeneric(w http.ResponseWriter, r *http.Request, onMain bool) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
param := "wsID"
|
||||
if !onMain {
|
||||
param = "wtID"
|
||||
}
|
||||
id, err := parseUUID(chi.URLParam(r, param))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
n := parseLogN(r)
|
||||
var commits []git.Commit
|
||||
if onMain {
|
||||
commits, err = h.gop.LogOnMain(r.Context(), c, id, n)
|
||||
} else {
|
||||
commits, err = h.gop.LogOnWorktree(r.Context(), c, id, n)
|
||||
}
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
resp := make([]commitLogResp, 0, len(commits))
|
||||
for _, cc := range commits {
|
||||
resp = append(resp, toCommitLogResp(cc))
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func parseLogN(r *http.Request) int {
|
||||
nStr := r.URL.Query().Get("n")
|
||||
if nStr == "" {
|
||||
return 50
|
||||
}
|
||||
n, err := strconv.Atoi(nStr)
|
||||
if err != nil || n <= 0 {
|
||||
return 50
|
||||
}
|
||||
if n > 200 {
|
||||
return 200
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user