docs: update server implementation gaps

This commit is contained in:
kami
2026-07-26 19:47:08 +04:00
parent 073d5c69b0
commit aa6719ca16
3 changed files with 120 additions and 11 deletions
+42 -1
View File
@@ -1,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"fmt"
"log"
@@ -8,6 +9,7 @@ import (
"orchestra/internal/authz"
"orchestra/internal/domain"
"orchestra/internal/operations"
"orchestra/internal/provider"
"orchestra/internal/registry"
"orchestra/internal/router"
"orchestra/internal/store"
@@ -173,7 +175,31 @@ func main() {
return
}
types := map[string]string{"release": "TaskReleased", "complete": "TaskCompleted", "block": "TaskBlocked"}
e = domain.Event{ID: id(), Type: types[action], TaskID: taskID, Version: t.Version + 1, Payload: json.RawMessage(`{"source":"api"}`)}
var p map[string]any
if r.Body != nil {
if json.NewDecoder(r.Body).Decode(&p) != nil {
p = map[string]any{}
}
}
if p == nil {
p = map[string]any{}
}
if action == "release" && p["reason"] == nil && p["handoff_ref"] == nil {
p["reason"] = "released_by_api"
}
if action == "block" && p["blocker"] == nil {
p["blocker"] = "blocked_by_api"
}
if action == "complete" && p["report_ref"] == nil {
ref, putErr := s.PutArtifact([]byte("completed without an attached report\n"))
if putErr != nil {
http.Error(w, putErr.Error(), 500)
return
}
p["report_ref"] = ref
}
ePayload, _ := json.Marshal(p)
e = domain.Event{ID: id(), Type: types[action], TaskID: taskID, Version: t.Version + 1, Payload: ePayload}
err = s.Append(e)
default:
http.Error(w, "unknown action", 404)
@@ -204,6 +230,21 @@ func main() {
}()
}
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok\n")) })
if base := os.Getenv("ORCHESTRA_GITEA_URL"); base != "" {
g := provider.Gitea{BaseURL: base, Token: os.Getenv("ORCHESTRA_GITEA_TOKEN"), WebhookSecret: os.Getenv("ORCHESTRA_GITEA_WEBHOOK_SECRET"), Owner: os.Getenv("ORCHESTRA_GITEA_OWNER"), Repo: os.Getenv("ORCHESTRA_GITEA_REPO")}
mux.Handle("/v1/providers/gitea/webhook", g.WebhookHandler(s))
go func() {
for {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
_, e := g.Poll(ctx, s)
cancel()
if e != nil {
log.Printf("gitea poll: %v", e)
}
time.Sleep(time.Minute)
}
}()
}
port := os.Getenv("ORCHESTRA_PORT")
if port == "" {
port = "9145"