You've already forked agentic-coding-workflow
bugfix
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
// Package changerequest models the change_requests entity and the server-side
|
||||
// merge gate. A change request links a project/workspace/(requirement|issue)
|
||||
// and a source->target branch to an external (Gitea) pull request, carrying a
|
||||
// review verdict + CI state. The crux is Service.Merge, which hard-blocks the
|
||||
// host-side merge unless review_verdict=='approved' (and optionally
|
||||
// ci_state=='success'): an agent can open and merge PRs via MCP, but cannot
|
||||
// self-approve — approval is HTTP/web-only by policy.
|
||||
//
|
||||
// Layout mirrors internal/workspace (single package, service + repository +
|
||||
// handler + sqlc) to keep the aggregate cohesive.
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// State mirrors the change_requests.state CHECK constraint.
|
||||
type State string
|
||||
|
||||
// State enum values.
|
||||
const (
|
||||
StateOpen State = "open"
|
||||
StateMerged State = "merged"
|
||||
StateClosed State = "closed"
|
||||
)
|
||||
|
||||
// Verdict mirrors the change_requests.review_verdict CHECK constraint.
|
||||
type Verdict string
|
||||
|
||||
// Verdict enum values.
|
||||
const (
|
||||
VerdictPending Verdict = "pending"
|
||||
VerdictApproved Verdict = "approved"
|
||||
VerdictChangesRequested Verdict = "changes_requested"
|
||||
VerdictRejected Verdict = "rejected"
|
||||
)
|
||||
|
||||
// IsValid reports whether v is in the enum set.
|
||||
func (v Verdict) IsValid() bool {
|
||||
switch v {
|
||||
case VerdictPending, VerdictApproved, VerdictChangesRequested, VerdictRejected:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CIState mirrors the change_requests.ci_state CHECK constraint.
|
||||
type CIState string
|
||||
|
||||
// CIState enum values.
|
||||
const (
|
||||
CIUnknown CIState = "unknown"
|
||||
CIPending CIState = "pending"
|
||||
CISuccess CIState = "success"
|
||||
CIFailure CIState = "failure"
|
||||
)
|
||||
|
||||
// ChangeRequest is the change_requests row projection.
|
||||
type ChangeRequest struct {
|
||||
ID uuid.UUID
|
||||
ProjectID uuid.UUID
|
||||
WorkspaceID uuid.UUID
|
||||
RequirementID *uuid.UUID
|
||||
IssueID *uuid.UUID
|
||||
Number int
|
||||
Title string
|
||||
Description string
|
||||
SourceBranch string
|
||||
TargetBranch string
|
||||
State State
|
||||
ReviewVerdict Verdict
|
||||
CIState CIState
|
||||
Provider string
|
||||
ExternalID *int64
|
||||
ExternalURL string
|
||||
MergeCommitSHA string
|
||||
ReviewedBy *uuid.UUID
|
||||
ReviewedAt *time.Time
|
||||
CreatedBy uuid.UUID
|
||||
MergedAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Caller mirrors workspace.Caller: the user context driving auth + audit.
|
||||
type Caller struct {
|
||||
UserID uuid.UUID
|
||||
IsAdmin bool
|
||||
SessionID *uuid.UUID
|
||||
}
|
||||
|
||||
// CreateInput carries the fields to open a change request (and host PR).
|
||||
type CreateInput struct {
|
||||
SourceBranch string
|
||||
TargetBranch string // empty => workspace default branch
|
||||
Title string
|
||||
Description string
|
||||
RequirementID *uuid.UUID
|
||||
IssueID *uuid.UUID
|
||||
}
|
||||
|
||||
// Service is the change-request application service.
|
||||
type Service interface {
|
||||
Create(ctx context.Context, c Caller, wsID uuid.UUID, in CreateInput) (*ChangeRequest, error)
|
||||
Get(ctx context.Context, c Caller, id uuid.UUID) (*ChangeRequest, error)
|
||||
GetByNumber(ctx context.Context, c Caller, projectSlug string, number int) (*ChangeRequest, error)
|
||||
ListByWorkspace(ctx context.Context, c Caller, wsID uuid.UUID) ([]*ChangeRequest, error)
|
||||
// Review records a human verdict (owner/admin only). It is intentionally NOT
|
||||
// exposed as an MCP tool so agents cannot self-approve their own PRs.
|
||||
Review(ctx context.Context, c Caller, id uuid.UUID, verdict Verdict, note string) (*ChangeRequest, error)
|
||||
// Merge is the gate: requires review_verdict=='approved' (+ ci success when
|
||||
// RequireCIPass), then merges the host PR and persists merged state.
|
||||
Merge(ctx context.Context, c Caller, id uuid.UUID, method string) (*ChangeRequest, error)
|
||||
// SyncStatus refreshes ci_state/state from the host (provider.GetPR).
|
||||
SyncStatus(ctx context.Context, c Caller, id uuid.UUID) (*ChangeRequest, error)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// dto.go defines the HTTP request/response shapes for the change-request module.
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ===== request DTO =====
|
||||
|
||||
type createReq struct {
|
||||
SourceBranch string `json:"source_branch"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
RequirementID *uuid.UUID `json:"requirement_id"`
|
||||
IssueID *uuid.UUID `json:"issue_id"`
|
||||
}
|
||||
|
||||
type reviewReq struct {
|
||||
Verdict string `json:"verdict"`
|
||||
Note string `json:"note"`
|
||||
}
|
||||
|
||||
type mergeReq struct {
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
// ===== response DTO =====
|
||||
|
||||
type changeRequestResp struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
WorkspaceID uuid.UUID `json:"workspace_id"`
|
||||
RequirementID *uuid.UUID `json:"requirement_id"`
|
||||
IssueID *uuid.UUID `json:"issue_id"`
|
||||
Number int `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
SourceBranch string `json:"source_branch"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
State string `json:"state"`
|
||||
ReviewVerdict string `json:"review_verdict"`
|
||||
CIState string `json:"ci_state"`
|
||||
Provider string `json:"provider"`
|
||||
ExternalID *int64 `json:"external_id"`
|
||||
ExternalURL string `json:"external_url"`
|
||||
MergeCommitSHA string `json:"merge_commit_sha"`
|
||||
ReviewedBy *uuid.UUID `json:"reviewed_by"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
CreatedBy uuid.UUID `json:"created_by"`
|
||||
MergedAt *time.Time `json:"merged_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func toResp(cr *ChangeRequest) changeRequestResp {
|
||||
return changeRequestResp{
|
||||
ID: cr.ID, ProjectID: cr.ProjectID, WorkspaceID: cr.WorkspaceID,
|
||||
RequirementID: cr.RequirementID, IssueID: cr.IssueID, Number: cr.Number,
|
||||
Title: cr.Title, Description: cr.Description,
|
||||
SourceBranch: cr.SourceBranch, TargetBranch: cr.TargetBranch,
|
||||
State: string(cr.State), ReviewVerdict: string(cr.ReviewVerdict),
|
||||
CIState: string(cr.CIState), Provider: cr.Provider,
|
||||
ExternalID: cr.ExternalID, ExternalURL: cr.ExternalURL, MergeCommitSHA: cr.MergeCommitSHA,
|
||||
ReviewedBy: cr.ReviewedBy, ReviewedAt: cr.ReviewedAt, CreatedBy: cr.CreatedBy,
|
||||
MergedAt: cr.MergedAt, CreatedAt: cr.CreatedAt, UpdatedAt: cr.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
// handler.go exposes the change-request HTTP endpoints under middleware.Auth,
|
||||
// mirroring workspace/handler.go. Routes:
|
||||
//
|
||||
// POST /api/v1/workspaces/{wsID}/change-requests create
|
||||
// GET /api/v1/workspaces/{wsID}/change-requests list
|
||||
// GET /api/v1/change-requests/{id} get
|
||||
// POST /api/v1/change-requests/{id}/review review (human approve/reject)
|
||||
// POST /api/v1/change-requests/{id}/merge gated merge
|
||||
// POST /api/v1/change-requests/{id}/sync refresh status from host
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
httpx "github.com/yan1h/agent-coding-workflow/internal/transport/http"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/transport/http/middleware"
|
||||
)
|
||||
|
||||
// AdminLookup resolves is_admin for a user (narrow interface, same as
|
||||
// workspace.AdminLookup so the userAdminAdapter can be reused).
|
||||
type AdminLookup interface {
|
||||
IsAdmin(ctx context.Context, id uuid.UUID) (bool, error)
|
||||
}
|
||||
|
||||
// Handler holds the change-request service + auth deps.
|
||||
type Handler struct {
|
||||
svc Service
|
||||
resolver middleware.SessionResolver
|
||||
users AdminLookup
|
||||
}
|
||||
|
||||
// NewHandler constructs the Handler.
|
||||
func NewHandler(svc Service, resolver middleware.SessionResolver, users AdminLookup) *Handler {
|
||||
return &Handler{svc: svc, resolver: resolver, users: users}
|
||||
}
|
||||
|
||||
// Mount registers the change-request routes on r under the Auth middleware.
|
||||
func (h *Handler) Mount(r chi.Router) {
|
||||
auth := middleware.Auth(h.resolver, middleware.AuthOptions{})
|
||||
|
||||
r.With(auth).Route("/api/v1/workspaces/{wsID}/change-requests", func(r chi.Router) {
|
||||
r.Post("/", h.create)
|
||||
r.Get("/", h.list)
|
||||
})
|
||||
r.With(auth).Route("/api/v1/change-requests/{id}", func(r chi.Router) {
|
||||
r.Get("/", h.get)
|
||||
r.Post("/review", h.review)
|
||||
r.Post("/merge", h.merge)
|
||||
r.Post("/sync", h.sync)
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) caller(r *http.Request) (Caller, error) {
|
||||
uid, ok := middleware.UserIDFromContext(r.Context())
|
||||
if !ok {
|
||||
return Caller{}, errs.New(errs.CodeUnauthorized, "unauthenticated")
|
||||
}
|
||||
isAdmin, err := h.users.IsAdmin(r.Context(), uid)
|
||||
if err != nil {
|
||||
return Caller{}, err
|
||||
}
|
||||
return Caller{UserID: uid, IsAdmin: isAdmin}, nil
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, body any) { httpx.WriteJSON(w, status, body) }
|
||||
|
||||
func writeErr(w http.ResponseWriter, r *http.Request, err error) {
|
||||
httpx.WriteError(w, middleware.RequestIDFromContext(r.Context()), err)
|
||||
}
|
||||
|
||||
func parseUUID(s string) (uuid.UUID, error) {
|
||||
id, err := uuid.Parse(s)
|
||||
if err != nil {
|
||||
return uuid.Nil, errs.Wrap(err, errs.CodeInvalidInput, "invalid uuid")
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (h *Handler) create(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
wsID, err := parseUUID(chi.URLParam(r, "wsID"))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
var req createReq
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeErr(w, r, errs.Wrap(err, errs.CodeInvalidInput, "decode body"))
|
||||
return
|
||||
}
|
||||
cr, err := h.svc.Create(r.Context(), c, wsID, CreateInput{
|
||||
SourceBranch: req.SourceBranch, TargetBranch: req.TargetBranch,
|
||||
Title: req.Title, Description: req.Description,
|
||||
RequirementID: req.RequirementID, IssueID: req.IssueID,
|
||||
})
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, toResp(cr))
|
||||
}
|
||||
|
||||
func (h *Handler) list(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
wsID, err := parseUUID(chi.URLParam(r, "wsID"))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
out, err := h.svc.ListByWorkspace(r.Context(), c, wsID)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
resp := make([]changeRequestResp, 0, len(out))
|
||||
for _, cr := range out {
|
||||
resp = append(resp, toResp(cr))
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (h *Handler) get(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
id, err := parseUUID(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
cr, err := h.svc.Get(r.Context(), c, id)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, toResp(cr))
|
||||
}
|
||||
|
||||
func (h *Handler) review(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
id, err := parseUUID(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
var req reviewReq
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeErr(w, r, errs.Wrap(err, errs.CodeInvalidInput, "decode body"))
|
||||
return
|
||||
}
|
||||
cr, err := h.svc.Review(r.Context(), c, id, Verdict(req.Verdict), req.Note)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, toResp(cr))
|
||||
}
|
||||
|
||||
func (h *Handler) merge(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
id, err := parseUUID(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
var req mergeReq
|
||||
// merge body is optional (method default)
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
cr, err := h.svc.Merge(r.Context(), c, id, req.Method)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, toResp(cr))
|
||||
}
|
||||
|
||||
func (h *Handler) sync(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := h.caller(r)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
id, err := parseUUID(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
cr, err := h.svc.SyncStatus(r.Context(), c, id)
|
||||
if err != nil {
|
||||
writeErr(w, r, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, toResp(cr))
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/transport/http/middleware"
|
||||
)
|
||||
|
||||
// fakeSvc implements Service for handler tests.
|
||||
type fakeSvc struct {
|
||||
mergeErr error
|
||||
cr *ChangeRequest
|
||||
}
|
||||
|
||||
func (f *fakeSvc) Create(_ context.Context, c Caller, wsID uuid.UUID, _ CreateInput) (*ChangeRequest, error) {
|
||||
return &ChangeRequest{ID: uuid.New(), WorkspaceID: wsID, Number: 1, State: StateOpen, ReviewVerdict: VerdictPending, CreatedBy: c.UserID}, nil
|
||||
}
|
||||
func (f *fakeSvc) Get(_ context.Context, _ Caller, id uuid.UUID) (*ChangeRequest, error) {
|
||||
return &ChangeRequest{ID: id, State: StateOpen}, nil
|
||||
}
|
||||
func (f *fakeSvc) GetByNumber(_ context.Context, _ Caller, _ string, n int) (*ChangeRequest, error) {
|
||||
return &ChangeRequest{ID: uuid.New(), Number: n}, nil
|
||||
}
|
||||
func (f *fakeSvc) ListByWorkspace(_ context.Context, _ Caller, wsID uuid.UUID) ([]*ChangeRequest, error) {
|
||||
return []*ChangeRequest{{ID: uuid.New(), WorkspaceID: wsID, Number: 1}}, nil
|
||||
}
|
||||
func (f *fakeSvc) Review(_ context.Context, _ Caller, id uuid.UUID, v Verdict, _ string) (*ChangeRequest, error) {
|
||||
return &ChangeRequest{ID: id, ReviewVerdict: v}, nil
|
||||
}
|
||||
func (f *fakeSvc) Merge(_ context.Context, _ Caller, id uuid.UUID, _ string) (*ChangeRequest, error) {
|
||||
if f.mergeErr != nil {
|
||||
return nil, f.mergeErr
|
||||
}
|
||||
return &ChangeRequest{ID: id, State: StateMerged}, nil
|
||||
}
|
||||
func (f *fakeSvc) SyncStatus(_ context.Context, _ Caller, id uuid.UUID) (*ChangeRequest, error) {
|
||||
return &ChangeRequest{ID: id, CIState: CISuccess}, nil
|
||||
}
|
||||
|
||||
type fakeResolver struct{ valid map[string]uuid.UUID }
|
||||
|
||||
func (f *fakeResolver) ResolveSession(_ context.Context, token string) (uuid.UUID, bool, error) {
|
||||
uid, ok := f.valid[token]
|
||||
return uid, ok, nil
|
||||
}
|
||||
|
||||
type fakeAdmin struct{}
|
||||
|
||||
func (fakeAdmin) IsAdmin(_ context.Context, _ uuid.UUID) (bool, error) { return false, nil }
|
||||
|
||||
func newTestHandler(svc Service, tok string, uid uuid.UUID) chi.Router {
|
||||
resolver := &fakeResolver{valid: map[string]uuid.UUID{tok: uid}}
|
||||
h := NewHandler(svc, resolver, fakeAdmin{})
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.RequestID)
|
||||
h.Mount(r)
|
||||
return r
|
||||
}
|
||||
|
||||
func TestHandler_Unauthenticated(t *testing.T) {
|
||||
t.Parallel()
|
||||
r := newTestHandler(&fakeSvc{}, "tok", uuid.New())
|
||||
req := httptest.NewRequest("GET", "/api/v1/workspaces/"+uuid.NewString()+"/change-requests", nil)
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusUnauthorized, w.Code)
|
||||
}
|
||||
|
||||
func TestHandler_CreateAndList(t *testing.T) {
|
||||
t.Parallel()
|
||||
uid := uuid.New()
|
||||
r := newTestHandler(&fakeSvc{}, "tok", uid)
|
||||
wsID := uuid.New()
|
||||
|
||||
body, _ := json.Marshal(createReq{SourceBranch: "feat", Title: "T"})
|
||||
req := httptest.NewRequest("POST", "/api/v1/workspaces/"+wsID.String()+"/change-requests", bytes.NewReader(body))
|
||||
req.Header.Set("Authorization", "Bearer tok")
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusCreated, w.Code)
|
||||
|
||||
req = httptest.NewRequest("GET", "/api/v1/workspaces/"+wsID.String()+"/change-requests", nil)
|
||||
req.Header.Set("Authorization", "Bearer tok")
|
||||
w = httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
}
|
||||
|
||||
func TestHandler_MergeGateReturns412(t *testing.T) {
|
||||
t.Parallel()
|
||||
svc := &fakeSvc{mergeErr: errs.New(errs.CodeFailedPrecondition, "merge blocked: review not approved")}
|
||||
r := newTestHandler(svc, "tok", uuid.New())
|
||||
|
||||
req := httptest.NewRequest("POST", "/api/v1/change-requests/"+uuid.NewString()+"/merge", nil)
|
||||
req.Header.Set("Authorization", "Bearer tok")
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusPreconditionFailed, w.Code)
|
||||
}
|
||||
|
||||
func TestHandler_MergeHappyPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
r := newTestHandler(&fakeSvc{}, "tok", uuid.New())
|
||||
|
||||
req := httptest.NewRequest("POST", "/api/v1/change-requests/"+uuid.NewString()+"/merge", bytes.NewReader([]byte(`{"method":"squash"}`)))
|
||||
req.Header.Set("Authorization", "Bearer tok")
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var resp changeRequestResp
|
||||
require.NoError(t, json.NewDecoder(w.Body).Decode(&resp))
|
||||
require.Equal(t, string(StateMerged), resp.State)
|
||||
}
|
||||
|
||||
func TestHandler_Review(t *testing.T) {
|
||||
t.Parallel()
|
||||
r := newTestHandler(&fakeSvc{}, "tok", uuid.New())
|
||||
|
||||
body, _ := json.Marshal(reviewReq{Verdict: "approved", Note: "lgtm"})
|
||||
req := httptest.NewRequest("POST", "/api/v1/change-requests/"+uuid.NewString()+"/review", bytes.NewReader(body))
|
||||
req.Header.Set("Authorization", "Bearer tok")
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var resp changeRequestResp
|
||||
require.NoError(t, json.NewDecoder(w.Body).Decode(&resp))
|
||||
require.Equal(t, "approved", resp.ReviewVerdict)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
-- name: NextChangeRequestNumber :one
|
||||
-- Per-project monotonic number; FOR UPDATE not needed because the
|
||||
-- max(number)+1 INSERT runs inside the same tx, but we lock existing project
|
||||
-- rows to serialize concurrent creates within a project.
|
||||
SELECT COALESCE(MAX(number), 0) + 1 FROM change_requests WHERE project_id = $1 FOR UPDATE;
|
||||
|
||||
-- name: CreateChangeRequest :one
|
||||
INSERT INTO change_requests (
|
||||
id, project_id, workspace_id, requirement_id, issue_id, number,
|
||||
title, description, source_branch, target_branch,
|
||||
state, review_verdict, ci_state, provider, external_id, external_url,
|
||||
merge_commit_sha, created_by
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6,
|
||||
$7, $8, $9, $10,
|
||||
'open', 'pending', $11, $12, $13, $14,
|
||||
'', $15
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetChangeRequestByID :one
|
||||
SELECT * FROM change_requests WHERE id = $1;
|
||||
|
||||
-- name: GetChangeRequestByNumber :one
|
||||
SELECT cr.* FROM change_requests cr
|
||||
JOIN projects p ON p.id = cr.project_id
|
||||
WHERE p.slug = $1 AND cr.number = $2;
|
||||
|
||||
-- name: ListChangeRequestsByWorkspace :many
|
||||
SELECT * FROM change_requests
|
||||
WHERE workspace_id = $1
|
||||
ORDER BY number DESC;
|
||||
|
||||
-- name: ListChangeRequestsByProject :many
|
||||
SELECT * FROM change_requests
|
||||
WHERE project_id = $1
|
||||
ORDER BY number DESC;
|
||||
|
||||
-- name: UpdateChangeRequestReview :one
|
||||
UPDATE change_requests
|
||||
SET review_verdict = $2,
|
||||
reviewed_by = $3,
|
||||
reviewed_at = now(),
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateChangeRequestState :one
|
||||
UPDATE change_requests
|
||||
SET state = $2,
|
||||
merge_commit_sha = $3,
|
||||
merged_at = $4,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateChangeRequestCI :one
|
||||
UPDATE change_requests
|
||||
SET ci_state = $2,
|
||||
state = $3,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
@@ -0,0 +1,264 @@
|
||||
// repository.go is a thin wrapper over the sqlc layer: pgtype<->domain
|
||||
// conversion, pgx.ErrNoRows -> errs.NotFound translation, and unique-violation
|
||||
// detection. Mirrors internal/workspace/repository.go.
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgerrcode"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
changerequestsqlc "github.com/yan1h/agent-coding-workflow/internal/changerequest/sqlc"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
)
|
||||
|
||||
// Tx is the transaction handle exposed to the service: NextNumber + Create run
|
||||
// in one tx so per-project numbering is serialized.
|
||||
type Tx interface {
|
||||
NextNumber(ctx context.Context, projectID uuid.UUID) (int, error)
|
||||
Create(ctx context.Context, cr *ChangeRequest) (*ChangeRequest, error)
|
||||
}
|
||||
|
||||
// Repository is the change-request module's PG dependency.
|
||||
type Repository interface {
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*ChangeRequest, error)
|
||||
GetByNumber(ctx context.Context, projectSlug string, number int) (*ChangeRequest, error)
|
||||
ListByWorkspace(ctx context.Context, wsID uuid.UUID) ([]*ChangeRequest, error)
|
||||
ListByProject(ctx context.Context, projectID uuid.UUID) ([]*ChangeRequest, error)
|
||||
UpdateReview(ctx context.Context, id uuid.UUID, verdict Verdict, reviewedBy uuid.UUID) (*ChangeRequest, error)
|
||||
UpdateState(ctx context.Context, id uuid.UUID, st State, mergeSHA string, mergedAt *time.Time) (*ChangeRequest, error)
|
||||
UpdateCI(ctx context.Context, id uuid.UUID, ci CIState, st State) (*ChangeRequest, error)
|
||||
InTx(ctx context.Context, fn func(Tx) error) error
|
||||
}
|
||||
|
||||
// IsUniqueViolation reports whether err is a PG unique constraint violation.
|
||||
func IsUniqueViolation(err error) bool {
|
||||
var pg *pgconn.PgError
|
||||
return errors.As(err, &pg) && pg.Code == pgerrcode.UniqueViolation
|
||||
}
|
||||
|
||||
type pgRepo struct {
|
||||
pool *pgxpool.Pool
|
||||
q *changerequestsqlc.Queries
|
||||
}
|
||||
|
||||
// NewPostgresRepository builds a Repository from a pgxpool.
|
||||
func NewPostgresRepository(pool *pgxpool.Pool) Repository {
|
||||
return &pgRepo{pool: pool, q: changerequestsqlc.New(pool)}
|
||||
}
|
||||
|
||||
// ===== conversion helpers =====
|
||||
|
||||
func toPgUUID(u uuid.UUID) pgtype.UUID { return pgtype.UUID{Bytes: u, Valid: true} }
|
||||
|
||||
func toPgUUIDPtr(u *uuid.UUID) pgtype.UUID {
|
||||
if u == nil {
|
||||
return pgtype.UUID{Valid: false}
|
||||
}
|
||||
return pgtype.UUID{Bytes: *u, Valid: true}
|
||||
}
|
||||
|
||||
func fromPgUUID(p pgtype.UUID) uuid.UUID {
|
||||
if !p.Valid {
|
||||
return uuid.Nil
|
||||
}
|
||||
return uuid.UUID(p.Bytes)
|
||||
}
|
||||
|
||||
func fromPgUUIDPtr(p pgtype.UUID) *uuid.UUID {
|
||||
if !p.Valid {
|
||||
return nil
|
||||
}
|
||||
u := uuid.UUID(p.Bytes)
|
||||
return &u
|
||||
}
|
||||
|
||||
func toPgTimePtr(t *time.Time) pgtype.Timestamptz {
|
||||
if t == nil {
|
||||
return pgtype.Timestamptz{Valid: false}
|
||||
}
|
||||
return pgtype.Timestamptz{Time: *t, Valid: true}
|
||||
}
|
||||
|
||||
func fromPgTimePtr(t pgtype.Timestamptz) *time.Time {
|
||||
if !t.Valid {
|
||||
return nil
|
||||
}
|
||||
v := t.Time
|
||||
return &v
|
||||
}
|
||||
|
||||
func rowToCR(r changerequestsqlc.ChangeRequest) *ChangeRequest {
|
||||
return &ChangeRequest{
|
||||
ID: fromPgUUID(r.ID),
|
||||
ProjectID: fromPgUUID(r.ProjectID),
|
||||
WorkspaceID: fromPgUUID(r.WorkspaceID),
|
||||
RequirementID: fromPgUUIDPtr(r.RequirementID),
|
||||
IssueID: fromPgUUIDPtr(r.IssueID),
|
||||
Number: int(r.Number),
|
||||
Title: r.Title,
|
||||
Description: r.Description,
|
||||
SourceBranch: r.SourceBranch,
|
||||
TargetBranch: r.TargetBranch,
|
||||
State: State(r.State),
|
||||
ReviewVerdict: Verdict(r.ReviewVerdict),
|
||||
CIState: CIState(r.CiState),
|
||||
Provider: r.Provider,
|
||||
ExternalID: r.ExternalID,
|
||||
ExternalURL: r.ExternalUrl,
|
||||
MergeCommitSHA: r.MergeCommitSha,
|
||||
ReviewedBy: fromPgUUIDPtr(r.ReviewedBy),
|
||||
ReviewedAt: fromPgTimePtr(r.ReviewedAt),
|
||||
CreatedBy: fromPgUUID(r.CreatedBy),
|
||||
MergedAt: fromPgTimePtr(r.MergedAt),
|
||||
CreatedAt: r.CreatedAt.Time,
|
||||
UpdatedAt: r.UpdatedAt.Time,
|
||||
}
|
||||
}
|
||||
|
||||
// ===== queries =====
|
||||
|
||||
func (r *pgRepo) GetByID(ctx context.Context, id uuid.UUID) (*ChangeRequest, error) {
|
||||
row, err := r.q.GetChangeRequestByID(ctx, toPgUUID(id))
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, errs.New(errs.CodeNotFound, "change request not found")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "get change request")
|
||||
}
|
||||
return rowToCR(row), nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) GetByNumber(ctx context.Context, projectSlug string, number int) (*ChangeRequest, error) {
|
||||
row, err := r.q.GetChangeRequestByNumber(ctx, changerequestsqlc.GetChangeRequestByNumberParams{
|
||||
Slug: projectSlug,
|
||||
Number: int32(number),
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, errs.New(errs.CodeNotFound, "change request not found")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "get change request by number")
|
||||
}
|
||||
return rowToCR(row), nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) ListByWorkspace(ctx context.Context, wsID uuid.UUID) ([]*ChangeRequest, error) {
|
||||
rows, err := r.q.ListChangeRequestsByWorkspace(ctx, toPgUUID(wsID))
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "list change requests by workspace")
|
||||
}
|
||||
out := make([]*ChangeRequest, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, rowToCR(row))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) ListByProject(ctx context.Context, projectID uuid.UUID) ([]*ChangeRequest, error) {
|
||||
rows, err := r.q.ListChangeRequestsByProject(ctx, toPgUUID(projectID))
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "list change requests by project")
|
||||
}
|
||||
out := make([]*ChangeRequest, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, rowToCR(row))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) UpdateReview(ctx context.Context, id uuid.UUID, verdict Verdict, reviewedBy uuid.UUID) (*ChangeRequest, error) {
|
||||
row, err := r.q.UpdateChangeRequestReview(ctx, changerequestsqlc.UpdateChangeRequestReviewParams{
|
||||
ID: toPgUUID(id),
|
||||
ReviewVerdict: string(verdict),
|
||||
ReviewedBy: toPgUUID(reviewedBy),
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, errs.New(errs.CodeNotFound, "change request not found")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "update change request review")
|
||||
}
|
||||
return rowToCR(row), nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) UpdateState(ctx context.Context, id uuid.UUID, st State, mergeSHA string, mergedAt *time.Time) (*ChangeRequest, error) {
|
||||
row, err := r.q.UpdateChangeRequestState(ctx, changerequestsqlc.UpdateChangeRequestStateParams{
|
||||
ID: toPgUUID(id),
|
||||
State: string(st),
|
||||
MergeCommitSha: mergeSHA,
|
||||
MergedAt: toPgTimePtr(mergedAt),
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, errs.New(errs.CodeNotFound, "change request not found")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "update change request state")
|
||||
}
|
||||
return rowToCR(row), nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) UpdateCI(ctx context.Context, id uuid.UUID, ci CIState, st State) (*ChangeRequest, error) {
|
||||
row, err := r.q.UpdateChangeRequestCI(ctx, changerequestsqlc.UpdateChangeRequestCIParams{
|
||||
ID: toPgUUID(id),
|
||||
CiState: string(ci),
|
||||
State: string(st),
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, errs.New(errs.CodeNotFound, "change request not found")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "update change request ci")
|
||||
}
|
||||
return rowToCR(row), nil
|
||||
}
|
||||
|
||||
func (r *pgRepo) InTx(ctx context.Context, fn func(Tx) error) error {
|
||||
return pgx.BeginFunc(ctx, r.pool, func(tx pgx.Tx) error {
|
||||
return fn(&pgTx{q: r.q.WithTx(tx)})
|
||||
})
|
||||
}
|
||||
|
||||
type pgTx struct{ q *changerequestsqlc.Queries }
|
||||
|
||||
func (t *pgTx) NextNumber(ctx context.Context, projectID uuid.UUID) (int, error) {
|
||||
n, err := t.q.NextChangeRequestNumber(ctx, toPgUUID(projectID))
|
||||
if err != nil {
|
||||
return 0, errs.Wrap(err, errs.CodeInternal, "next change request number")
|
||||
}
|
||||
return int(n), nil
|
||||
}
|
||||
|
||||
func (t *pgTx) Create(ctx context.Context, cr *ChangeRequest) (*ChangeRequest, error) {
|
||||
row, err := t.q.CreateChangeRequest(ctx, changerequestsqlc.CreateChangeRequestParams{
|
||||
ID: toPgUUID(cr.ID),
|
||||
ProjectID: toPgUUID(cr.ProjectID),
|
||||
WorkspaceID: toPgUUID(cr.WorkspaceID),
|
||||
RequirementID: toPgUUIDPtr(cr.RequirementID),
|
||||
IssueID: toPgUUIDPtr(cr.IssueID),
|
||||
Number: int32(cr.Number),
|
||||
Title: cr.Title,
|
||||
Description: cr.Description,
|
||||
SourceBranch: cr.SourceBranch,
|
||||
TargetBranch: cr.TargetBranch,
|
||||
CiState: string(cr.CIState),
|
||||
Provider: cr.Provider,
|
||||
ExternalID: cr.ExternalID,
|
||||
ExternalUrl: cr.ExternalURL,
|
||||
CreatedBy: toPgUUID(cr.CreatedBy),
|
||||
})
|
||||
if err != nil {
|
||||
if IsUniqueViolation(err) {
|
||||
return nil, errs.Wrap(err, errs.CodeConflict, "change request number already used")
|
||||
}
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "create change request")
|
||||
}
|
||||
return rowToCR(row), nil
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
// service.go implements the change-request application service, including the
|
||||
// merge gate (Service.Merge). Auth delegates to ProjectAccess (owner+admin
|
||||
// write), mirroring workspace's narrow-interface approach so this package does
|
||||
// not depend on internal/project wholesale.
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/audit"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/vcs"
|
||||
)
|
||||
|
||||
// WorkspaceLookup resolves a workspace's project + remote URL + default branch
|
||||
// for RepoRef derivation and target-branch defaulting. Narrow interface over
|
||||
// workspace.Repository so we avoid importing the full workspace service.
|
||||
type WorkspaceLookup interface {
|
||||
GetWorkspaceMeta(ctx context.Context, wsID uuid.UUID) (WorkspaceMeta, error)
|
||||
}
|
||||
|
||||
// WorkspaceMeta is the workspace projection the change-request service needs.
|
||||
type WorkspaceMeta struct {
|
||||
ProjectID uuid.UUID
|
||||
GitRemoteURL string
|
||||
DefaultBranch string
|
||||
}
|
||||
|
||||
// ProjectAccess is the auth interface (same shape as workspace.ProjectAccess):
|
||||
// ResolveByID returns (canRead, canWrite, err) for a project.
|
||||
type ProjectAccess interface {
|
||||
ResolveByID(ctx context.Context, callerID uuid.UUID, isAdmin bool, projectID uuid.UUID) (bool, bool, error)
|
||||
}
|
||||
|
||||
// Config controls the merge gate policy.
|
||||
type Config struct {
|
||||
RequireCIPass bool // when true, merge also requires ci_state=='success'
|
||||
MergeMethod string // default host merge method ("merge"|"squash"|"rebase"); "merge" when empty
|
||||
Host string // bare host the provider serves, for RepoRef host check; empty => skip
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
ws WorkspaceLookup
|
||||
rec audit.Recorder
|
||||
provider vcs.Provider
|
||||
pa ProjectAccess
|
||||
cfg Config
|
||||
}
|
||||
|
||||
// NewService constructs the change-request Service.
|
||||
func NewService(repo Repository, ws WorkspaceLookup, rec audit.Recorder, provider vcs.Provider, pa ProjectAccess, cfg Config) Service {
|
||||
if cfg.MergeMethod == "" {
|
||||
cfg.MergeMethod = "merge"
|
||||
}
|
||||
return &service{repo: repo, ws: ws, rec: rec, provider: provider, pa: pa, cfg: cfg}
|
||||
}
|
||||
|
||||
// Create opens a host PR and persists the change_requests row.
|
||||
func (s *service) Create(ctx context.Context, c Caller, wsID uuid.UUID, in CreateInput) (*ChangeRequest, error) {
|
||||
meta, err := s.ws.GetWorkspaceMeta(ctx, wsID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardWrite(ctx, c, meta.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.SourceBranch == "" {
|
||||
return nil, errs.New(errs.CodeInvalidInput, "source_branch required")
|
||||
}
|
||||
if in.Title == "" {
|
||||
return nil, errs.New(errs.CodeInvalidInput, "title required")
|
||||
}
|
||||
target := in.TargetBranch
|
||||
if target == "" {
|
||||
target = meta.DefaultBranch
|
||||
}
|
||||
if target == "" {
|
||||
target = "main"
|
||||
}
|
||||
if in.SourceBranch == target {
|
||||
return nil, errs.New(errs.CodeInvalidInput, "source_branch and target_branch must differ")
|
||||
}
|
||||
|
||||
repoRef, err := vcs.ParseRepoRef(meta.GitRemoteURL, s.cfg.Host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pr, err := s.provider.CreatePR(ctx, vcs.CreatePRInput{
|
||||
Repo: repoRef, Head: in.SourceBranch, Base: target,
|
||||
Title: in.Title, Body: in.Description,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeUpstream, "open pull request")
|
||||
}
|
||||
|
||||
cr := &ChangeRequest{
|
||||
ID: uuid.New(),
|
||||
ProjectID: meta.ProjectID,
|
||||
WorkspaceID: wsID,
|
||||
RequirementID: in.RequirementID,
|
||||
IssueID: in.IssueID,
|
||||
Title: in.Title,
|
||||
Description: in.Description,
|
||||
SourceBranch: in.SourceBranch,
|
||||
TargetBranch: target,
|
||||
CIState: CIState(pr.CIState),
|
||||
Provider: "gitea",
|
||||
ExternalURL: pr.HTMLURL,
|
||||
CreatedBy: c.UserID,
|
||||
}
|
||||
if cr.CIState == "" {
|
||||
cr.CIState = CIUnknown
|
||||
}
|
||||
extID := pr.Number
|
||||
cr.ExternalID = &extID
|
||||
|
||||
var created *ChangeRequest
|
||||
err = s.repo.InTx(ctx, func(tx Tx) error {
|
||||
n, nerr := tx.NextNumber(ctx, meta.ProjectID)
|
||||
if nerr != nil {
|
||||
return nerr
|
||||
}
|
||||
cr.Number = n
|
||||
c2, cerr := tx.Create(ctx, cr)
|
||||
if cerr != nil {
|
||||
return cerr
|
||||
}
|
||||
created = c2
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.audit(ctx, &c.UserID, "change_request.created", created.ID.String(), map[string]any{
|
||||
"number": created.Number, "external_id": extID, "source": in.SourceBranch, "target": target,
|
||||
})
|
||||
return created, nil
|
||||
}
|
||||
|
||||
func (s *service) Get(ctx context.Context, c Caller, id uuid.UUID) (*ChangeRequest, error) {
|
||||
cr, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardRead(ctx, c, cr.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cr, nil
|
||||
}
|
||||
|
||||
func (s *service) GetByNumber(ctx context.Context, c Caller, projectSlug string, number int) (*ChangeRequest, error) {
|
||||
cr, err := s.repo.GetByNumber(ctx, projectSlug, number)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardRead(ctx, c, cr.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cr, nil
|
||||
}
|
||||
|
||||
func (s *service) ListByWorkspace(ctx context.Context, c Caller, wsID uuid.UUID) ([]*ChangeRequest, error) {
|
||||
meta, err := s.ws.GetWorkspaceMeta(ctx, wsID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardRead(ctx, c, meta.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.ListByWorkspace(ctx, wsID)
|
||||
}
|
||||
|
||||
// Review records a human verdict. Owner/admin only. Not an MCP tool.
|
||||
func (s *service) Review(ctx context.Context, c Caller, id uuid.UUID, verdict Verdict, note string) (*ChangeRequest, error) {
|
||||
if !verdict.IsValid() || verdict == VerdictPending {
|
||||
return nil, errs.New(errs.CodeInvalidInput, "invalid review verdict")
|
||||
}
|
||||
cr, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardWrite(ctx, c, cr.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cr.State != StateOpen {
|
||||
return nil, errs.New(errs.CodeFailedPrecondition, "cannot review a non-open change request")
|
||||
}
|
||||
updated, err := s.repo.UpdateReview(ctx, id, verdict, c.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if note != "" && updated.ExternalID != nil {
|
||||
if repoRef, perr := s.repoRefFor(ctx, updated.WorkspaceID); perr == nil {
|
||||
_ = s.provider.Comment(ctx, repoRef, *updated.ExternalID, "Review ("+string(verdict)+"): "+note)
|
||||
}
|
||||
}
|
||||
s.audit(ctx, &c.UserID, "change_request.reviewed", id.String(), map[string]any{
|
||||
"verdict": string(verdict),
|
||||
})
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
// Merge is the gate. It requires review_verdict=='approved' (and ci success
|
||||
// when RequireCIPass and not admin), then merges the host PR.
|
||||
func (s *service) Merge(ctx context.Context, c Caller, id uuid.UUID, method string) (*ChangeRequest, error) {
|
||||
cr, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardWrite(ctx, c, cr.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cr.State != StateOpen {
|
||||
return nil, errs.New(errs.CodeFailedPrecondition, "change request is not open")
|
||||
}
|
||||
// THE GATE: review must be approved.
|
||||
if cr.ReviewVerdict != VerdictApproved {
|
||||
return nil, errs.New(errs.CodeFailedPrecondition, "merge blocked: review not approved")
|
||||
}
|
||||
// Optional CI gate; admins may override.
|
||||
if s.cfg.RequireCIPass && !c.IsAdmin && cr.CIState != CISuccess {
|
||||
return nil, errs.New(errs.CodeFailedPrecondition, "merge blocked: CI not passing")
|
||||
}
|
||||
if cr.ExternalID == nil {
|
||||
return nil, errs.New(errs.CodeFailedPrecondition, "change request has no external PR")
|
||||
}
|
||||
|
||||
repoRef, err := s.repoRefFor(ctx, cr.WorkspaceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mm := method
|
||||
if mm == "" {
|
||||
mm = s.cfg.MergeMethod
|
||||
}
|
||||
mergeSHA, err := s.provider.Merge(ctx, repoRef, *cr.ExternalID, vcs.MergeInput{Method: mm})
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeFailedPrecondition, "host merge failed")
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
updated, err := s.repo.UpdateState(ctx, id, StateMerged, mergeSHA, &now)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.audit(ctx, &c.UserID, "change_request.merged", id.String(), map[string]any{
|
||||
"method": mm, "merge_sha": mergeSHA,
|
||||
})
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
// SyncStatus refreshes ci_state/state from the host PR.
|
||||
func (s *service) SyncStatus(ctx context.Context, c Caller, id uuid.UUID) (*ChangeRequest, error) {
|
||||
cr, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.guardRead(ctx, c, cr.ProjectID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cr.ExternalID == nil {
|
||||
return cr, nil
|
||||
}
|
||||
repoRef, err := s.repoRefFor(ctx, cr.WorkspaceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pr, err := s.provider.GetPR(ctx, repoRef, *cr.ExternalID)
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeUpstream, "fetch pull request status")
|
||||
}
|
||||
newState := cr.State
|
||||
switch {
|
||||
case pr.Merged:
|
||||
newState = StateMerged
|
||||
case pr.State == "closed":
|
||||
newState = StateClosed
|
||||
default:
|
||||
newState = StateOpen
|
||||
}
|
||||
ci := CIState(pr.CIState)
|
||||
if !validCI(ci) {
|
||||
ci = CIUnknown
|
||||
}
|
||||
return s.repo.UpdateCI(ctx, id, ci, newState)
|
||||
}
|
||||
|
||||
// ===== helpers =====
|
||||
|
||||
func (s *service) repoRefFor(ctx context.Context, wsID uuid.UUID) (vcs.RepoRef, error) {
|
||||
meta, err := s.ws.GetWorkspaceMeta(ctx, wsID)
|
||||
if err != nil {
|
||||
return vcs.RepoRef{}, err
|
||||
}
|
||||
return vcs.ParseRepoRef(meta.GitRemoteURL, s.cfg.Host)
|
||||
}
|
||||
|
||||
func (s *service) guardRead(ctx context.Context, c Caller, projectID uuid.UUID) error {
|
||||
canRead, _, err := s.pa.ResolveByID(ctx, c.UserID, c.IsAdmin, projectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !canRead {
|
||||
return errs.New(errs.CodeForbidden, "no read access")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) guardWrite(ctx context.Context, c Caller, projectID uuid.UUID) error {
|
||||
_, canWrite, err := s.pa.ResolveByID(ctx, c.UserID, c.IsAdmin, projectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !canWrite {
|
||||
return errs.New(errs.CodeForbidden, "no write access")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) audit(ctx context.Context, uid *uuid.UUID, action, id string, meta map[string]any) {
|
||||
_ = s.rec.Record(ctx, audit.Entry{
|
||||
UserID: uid, Action: action, TargetType: "change_request", TargetID: id, Metadata: meta,
|
||||
})
|
||||
}
|
||||
|
||||
func validCI(ci CIState) bool {
|
||||
switch ci {
|
||||
case CIUnknown, CIPending, CISuccess, CIFailure:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
package changerequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/audit"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/vcs"
|
||||
)
|
||||
|
||||
// ===== fakes =====
|
||||
|
||||
type fakeRepo struct {
|
||||
items map[uuid.UUID]*ChangeRequest
|
||||
nextNum int
|
||||
}
|
||||
|
||||
func newFakeRepo() *fakeRepo { return &fakeRepo{items: map[uuid.UUID]*ChangeRequest{}, nextNum: 1} }
|
||||
|
||||
func (f *fakeRepo) GetByID(_ context.Context, id uuid.UUID) (*ChangeRequest, error) {
|
||||
cr, ok := f.items[id]
|
||||
if !ok {
|
||||
return nil, errs.New(errs.CodeNotFound, "not found")
|
||||
}
|
||||
cp := *cr
|
||||
return &cp, nil
|
||||
}
|
||||
func (f *fakeRepo) GetByNumber(_ context.Context, _ string, number int) (*ChangeRequest, error) {
|
||||
for _, cr := range f.items {
|
||||
if cr.Number == number {
|
||||
cp := *cr
|
||||
return &cp, nil
|
||||
}
|
||||
}
|
||||
return nil, errs.New(errs.CodeNotFound, "not found")
|
||||
}
|
||||
func (f *fakeRepo) ListByWorkspace(_ context.Context, wsID uuid.UUID) ([]*ChangeRequest, error) {
|
||||
var out []*ChangeRequest
|
||||
for _, cr := range f.items {
|
||||
if cr.WorkspaceID == wsID {
|
||||
cp := *cr
|
||||
out = append(out, &cp)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (f *fakeRepo) ListByProject(_ context.Context, pid uuid.UUID) ([]*ChangeRequest, error) {
|
||||
var out []*ChangeRequest
|
||||
for _, cr := range f.items {
|
||||
if cr.ProjectID == pid {
|
||||
cp := *cr
|
||||
out = append(out, &cp)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (f *fakeRepo) UpdateReview(_ context.Context, id uuid.UUID, v Verdict, by uuid.UUID) (*ChangeRequest, error) {
|
||||
cr := f.items[id]
|
||||
cr.ReviewVerdict = v
|
||||
cr.ReviewedBy = &by
|
||||
now := time.Now()
|
||||
cr.ReviewedAt = &now
|
||||
cp := *cr
|
||||
return &cp, nil
|
||||
}
|
||||
func (f *fakeRepo) UpdateState(_ context.Context, id uuid.UUID, st State, sha string, at *time.Time) (*ChangeRequest, error) {
|
||||
cr := f.items[id]
|
||||
cr.State = st
|
||||
cr.MergeCommitSHA = sha
|
||||
cr.MergedAt = at
|
||||
cp := *cr
|
||||
return &cp, nil
|
||||
}
|
||||
func (f *fakeRepo) UpdateCI(_ context.Context, id uuid.UUID, ci CIState, st State) (*ChangeRequest, error) {
|
||||
cr := f.items[id]
|
||||
cr.CIState = ci
|
||||
cr.State = st
|
||||
cp := *cr
|
||||
return &cp, nil
|
||||
}
|
||||
func (f *fakeRepo) InTx(ctx context.Context, fn func(Tx) error) error {
|
||||
return fn(&fakeTx{r: f})
|
||||
}
|
||||
|
||||
type fakeTx struct{ r *fakeRepo }
|
||||
|
||||
func (t *fakeTx) NextNumber(_ context.Context, _ uuid.UUID) (int, error) {
|
||||
n := t.r.nextNum
|
||||
t.r.nextNum++
|
||||
return n, nil
|
||||
}
|
||||
func (t *fakeTx) Create(_ context.Context, cr *ChangeRequest) (*ChangeRequest, error) {
|
||||
cp := *cr
|
||||
// mirror the DB INSERT defaults baked into the query (state/verdict).
|
||||
cp.State = StateOpen
|
||||
cp.ReviewVerdict = VerdictPending
|
||||
if cp.Provider == "" {
|
||||
cp.Provider = "gitea"
|
||||
}
|
||||
t.r.items[cr.ID] = &cp
|
||||
out := cp
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type fakeProvider struct {
|
||||
createPR *vcs.PullRequest
|
||||
getPR *vcs.PullRequest
|
||||
mergeSHA string
|
||||
mergeErr error
|
||||
mergeCalled bool
|
||||
}
|
||||
|
||||
func (p *fakeProvider) CreatePR(_ context.Context, _ vcs.CreatePRInput) (*vcs.PullRequest, error) {
|
||||
if p.createPR != nil {
|
||||
return p.createPR, nil
|
||||
}
|
||||
return &vcs.PullRequest{Number: 1, State: "open", HTMLURL: "http://h/pr/1", CIState: "unknown"}, nil
|
||||
}
|
||||
func (p *fakeProvider) GetPR(_ context.Context, _ vcs.RepoRef, _ int64) (*vcs.PullRequest, error) {
|
||||
if p.getPR != nil {
|
||||
return p.getPR, nil
|
||||
}
|
||||
return &vcs.PullRequest{Number: 1, State: "open", CIState: "success"}, nil
|
||||
}
|
||||
func (p *fakeProvider) Comment(_ context.Context, _ vcs.RepoRef, _ int64, _ string) error { return nil }
|
||||
func (p *fakeProvider) Merge(_ context.Context, _ vcs.RepoRef, _ int64, _ vcs.MergeInput) (string, error) {
|
||||
p.mergeCalled = true
|
||||
if p.mergeErr != nil {
|
||||
return "", p.mergeErr
|
||||
}
|
||||
if p.mergeSHA == "" {
|
||||
return "merged-sha", nil
|
||||
}
|
||||
return p.mergeSHA, nil
|
||||
}
|
||||
func (p *fakeProvider) ListIssues(_ context.Context, _ vcs.RepoRef, _ vcs.IssueListOptions) ([]vcs.Issue, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type fakeWS struct {
|
||||
meta WorkspaceMeta
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeWS) GetWorkspaceMeta(_ context.Context, _ uuid.UUID) (WorkspaceMeta, error) {
|
||||
return f.meta, f.err
|
||||
}
|
||||
|
||||
type fakePA struct {
|
||||
canRead, canWrite bool
|
||||
}
|
||||
|
||||
func (f *fakePA) ResolveByID(_ context.Context, _ uuid.UUID, _ bool, _ uuid.UUID) (bool, bool, error) {
|
||||
return f.canRead, f.canWrite, nil
|
||||
}
|
||||
|
||||
type nopRec struct{}
|
||||
|
||||
func (nopRec) Record(_ context.Context, _ audit.Entry) error { return nil }
|
||||
|
||||
var (
|
||||
tProj = uuid.New()
|
||||
tWS = uuid.New()
|
||||
tUser = uuid.New()
|
||||
)
|
||||
|
||||
func newSvc(t *testing.T, prov *fakeProvider, pa *fakePA, cfg Config) (*service, *fakeRepo) {
|
||||
t.Helper()
|
||||
repo := newFakeRepo()
|
||||
ws := &fakeWS{meta: WorkspaceMeta{ProjectID: tProj, GitRemoteURL: "https://git.jerryyan.net/owner/repo.git", DefaultBranch: "main"}}
|
||||
svc := NewService(repo, ws, nopRec{}, prov, pa, cfg).(*service)
|
||||
return svc, repo
|
||||
}
|
||||
|
||||
func caller() Caller { return Caller{UserID: tUser} }
|
||||
|
||||
// ===== tests =====
|
||||
|
||||
func TestCreate_PersistsPending(t *testing.T) {
|
||||
prov := &fakeProvider{createPR: &vcs.PullRequest{Number: 7, State: "open", HTMLURL: "http://h/7", CIState: "pending"}}
|
||||
svc, _ := newSvc(t, prov, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net"})
|
||||
|
||||
cr, err := svc.Create(context.Background(), caller(), tWS, CreateInput{
|
||||
SourceBranch: "feature", Title: "T",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, VerdictPending, cr.ReviewVerdict)
|
||||
assert.Equal(t, StateOpen, cr.State)
|
||||
assert.Equal(t, "main", cr.TargetBranch)
|
||||
require.NotNil(t, cr.ExternalID)
|
||||
assert.Equal(t, int64(7), *cr.ExternalID)
|
||||
assert.Equal(t, 1, cr.Number)
|
||||
assert.Equal(t, CIPending, cr.CIState)
|
||||
}
|
||||
|
||||
func TestCreate_RequiresWrite(t *testing.T) {
|
||||
svc, _ := newSvc(t, &fakeProvider{}, &fakePA{canRead: true, canWrite: false}, Config{Host: "git.jerryyan.net"})
|
||||
_, err := svc.Create(context.Background(), caller(), tWS, CreateInput{SourceBranch: "f", Title: "T"})
|
||||
require.Error(t, err)
|
||||
ae, _ := errs.As(err)
|
||||
assert.Equal(t, errs.CodeForbidden, ae.Code)
|
||||
}
|
||||
|
||||
func TestCreate_SameBranchRejected(t *testing.T) {
|
||||
svc, _ := newSvc(t, &fakeProvider{}, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net"})
|
||||
_, err := svc.Create(context.Background(), caller(), tWS, CreateInput{SourceBranch: "main", Title: "T"})
|
||||
require.Error(t, err)
|
||||
ae, _ := errs.As(err)
|
||||
assert.Equal(t, errs.CodeInvalidInput, ae.Code)
|
||||
}
|
||||
|
||||
// seed inserts an open, approved-able CR into the repo for merge tests.
|
||||
func seedCR(repo *fakeRepo, verdict Verdict, ci CIState) *ChangeRequest {
|
||||
id := uuid.New()
|
||||
ext := int64(7)
|
||||
cr := &ChangeRequest{
|
||||
ID: id, ProjectID: tProj, WorkspaceID: tWS, Number: 1,
|
||||
Title: "T", SourceBranch: "feature", TargetBranch: "main",
|
||||
State: StateOpen, ReviewVerdict: verdict, CIState: ci,
|
||||
Provider: "gitea", ExternalID: &ext, CreatedBy: tUser,
|
||||
}
|
||||
repo.items[id] = cr
|
||||
return cr
|
||||
}
|
||||
|
||||
func TestMerge_DeniedWhenNotApproved(t *testing.T) {
|
||||
for _, v := range []Verdict{VerdictPending, VerdictChangesRequested, VerdictRejected} {
|
||||
prov := &fakeProvider{}
|
||||
svc, repo := newSvc(t, prov, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net"})
|
||||
cr := seedCR(repo, v, CISuccess)
|
||||
|
||||
_, err := svc.Merge(context.Background(), caller(), cr.ID, "")
|
||||
require.Error(t, err, v)
|
||||
ae, _ := errs.As(err)
|
||||
assert.Equal(t, errs.CodeFailedPrecondition, ae.Code, v)
|
||||
assert.False(t, prov.mergeCalled, "provider.Merge must NOT be called when verdict=%s", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMerge_DeniedWhenCINotPassing(t *testing.T) {
|
||||
prov := &fakeProvider{}
|
||||
svc, repo := newSvc(t, prov, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net", RequireCIPass: true})
|
||||
cr := seedCR(repo, VerdictApproved, CIFailure)
|
||||
|
||||
_, err := svc.Merge(context.Background(), caller(), cr.ID, "")
|
||||
require.Error(t, err)
|
||||
ae, _ := errs.As(err)
|
||||
assert.Equal(t, errs.CodeFailedPrecondition, ae.Code)
|
||||
assert.False(t, prov.mergeCalled)
|
||||
}
|
||||
|
||||
func TestMerge_AdminBypassesCI(t *testing.T) {
|
||||
prov := &fakeProvider{mergeSHA: "sha-x"}
|
||||
svc, repo := newSvc(t, prov, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net", RequireCIPass: true})
|
||||
cr := seedCR(repo, VerdictApproved, CIFailure)
|
||||
|
||||
out, err := svc.Merge(context.Background(), Caller{UserID: tUser, IsAdmin: true}, cr.ID, "")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, prov.mergeCalled)
|
||||
assert.Equal(t, StateMerged, out.State)
|
||||
assert.Equal(t, "sha-x", out.MergeCommitSHA)
|
||||
}
|
||||
|
||||
func TestMerge_AllowedWhenApproved(t *testing.T) {
|
||||
prov := &fakeProvider{mergeSHA: "sha-y"}
|
||||
svc, repo := newSvc(t, prov, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net", RequireCIPass: true})
|
||||
cr := seedCR(repo, VerdictApproved, CISuccess)
|
||||
|
||||
out, err := svc.Merge(context.Background(), caller(), cr.ID, "squash")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, prov.mergeCalled)
|
||||
assert.Equal(t, StateMerged, out.State)
|
||||
assert.NotNil(t, out.MergedAt)
|
||||
assert.Equal(t, "sha-y", out.MergeCommitSHA)
|
||||
}
|
||||
|
||||
func TestReview_SetsReviewer(t *testing.T) {
|
||||
svc, repo := newSvc(t, &fakeProvider{}, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net"})
|
||||
cr := seedCR(repo, VerdictPending, CIUnknown)
|
||||
|
||||
out, err := svc.Review(context.Background(), caller(), cr.ID, VerdictApproved, "lgtm")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, VerdictApproved, out.ReviewVerdict)
|
||||
require.NotNil(t, out.ReviewedBy)
|
||||
assert.Equal(t, tUser, *out.ReviewedBy)
|
||||
}
|
||||
|
||||
func TestReview_RequiresWrite(t *testing.T) {
|
||||
svc, repo := newSvc(t, &fakeProvider{}, &fakePA{canRead: true, canWrite: false}, Config{Host: "git.jerryyan.net"})
|
||||
cr := seedCR(repo, VerdictPending, CIUnknown)
|
||||
_, err := svc.Review(context.Background(), caller(), cr.ID, VerdictApproved, "")
|
||||
require.Error(t, err)
|
||||
ae, _ := errs.As(err)
|
||||
assert.Equal(t, errs.CodeForbidden, ae.Code)
|
||||
}
|
||||
|
||||
func TestSyncStatus_RefreshesCIAndState(t *testing.T) {
|
||||
prov := &fakeProvider{getPR: &vcs.PullRequest{Number: 7, State: "closed", Merged: true, CIState: "success", MergeCommitSHA: "z"}}
|
||||
svc, repo := newSvc(t, prov, &fakePA{canRead: true, canWrite: true}, Config{Host: "git.jerryyan.net"})
|
||||
cr := seedCR(repo, VerdictApproved, CIUnknown)
|
||||
|
||||
out, err := svc.SyncStatus(context.Background(), caller(), cr.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, CISuccess, out.CIState)
|
||||
assert.Equal(t, StateMerged, out.State)
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: change_requests.sql
|
||||
|
||||
package changerequestsqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createChangeRequest = `-- name: CreateChangeRequest :one
|
||||
INSERT INTO change_requests (
|
||||
id, project_id, workspace_id, requirement_id, issue_id, number,
|
||||
title, description, source_branch, target_branch,
|
||||
state, review_verdict, ci_state, provider, external_id, external_url,
|
||||
merge_commit_sha, created_by
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6,
|
||||
$7, $8, $9, $10,
|
||||
'open', 'pending', $11, $12, $13, $14,
|
||||
'', $15
|
||||
)
|
||||
RETURNING id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateChangeRequestParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
SourceBranch string `json:"source_branch"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
CiState string `json:"ci_state"`
|
||||
Provider string `json:"provider"`
|
||||
ExternalID *int64 `json:"external_id"`
|
||||
ExternalUrl string `json:"external_url"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateChangeRequest(ctx context.Context, arg CreateChangeRequestParams) (ChangeRequest, error) {
|
||||
row := q.db.QueryRow(ctx, createChangeRequest,
|
||||
arg.ID,
|
||||
arg.ProjectID,
|
||||
arg.WorkspaceID,
|
||||
arg.RequirementID,
|
||||
arg.IssueID,
|
||||
arg.Number,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.SourceBranch,
|
||||
arg.TargetBranch,
|
||||
arg.CiState,
|
||||
arg.Provider,
|
||||
arg.ExternalID,
|
||||
arg.ExternalUrl,
|
||||
arg.CreatedBy,
|
||||
)
|
||||
var i ChangeRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getChangeRequestByID = `-- name: GetChangeRequestByID :one
|
||||
SELECT id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at FROM change_requests WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetChangeRequestByID(ctx context.Context, id pgtype.UUID) (ChangeRequest, error) {
|
||||
row := q.db.QueryRow(ctx, getChangeRequestByID, id)
|
||||
var i ChangeRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getChangeRequestByNumber = `-- name: GetChangeRequestByNumber :one
|
||||
SELECT cr.id, cr.project_id, cr.workspace_id, cr.requirement_id, cr.issue_id, cr.number, cr.title, cr.description, cr.source_branch, cr.target_branch, cr.state, cr.review_verdict, cr.ci_state, cr.provider, cr.external_id, cr.external_url, cr.merge_commit_sha, cr.reviewed_by, cr.reviewed_at, cr.created_by, cr.merged_at, cr.created_at, cr.updated_at FROM change_requests cr
|
||||
JOIN projects p ON p.id = cr.project_id
|
||||
WHERE p.slug = $1 AND cr.number = $2
|
||||
`
|
||||
|
||||
type GetChangeRequestByNumberParams struct {
|
||||
Slug string `json:"slug"`
|
||||
Number int32 `json:"number"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetChangeRequestByNumber(ctx context.Context, arg GetChangeRequestByNumberParams) (ChangeRequest, error) {
|
||||
row := q.db.QueryRow(ctx, getChangeRequestByNumber, arg.Slug, arg.Number)
|
||||
var i ChangeRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listChangeRequestsByProject = `-- name: ListChangeRequestsByProject :many
|
||||
SELECT id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at FROM change_requests
|
||||
WHERE project_id = $1
|
||||
ORDER BY number DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListChangeRequestsByProject(ctx context.Context, projectID pgtype.UUID) ([]ChangeRequest, error) {
|
||||
rows, err := q.db.Query(ctx, listChangeRequestsByProject, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ChangeRequest
|
||||
for rows.Next() {
|
||||
var i ChangeRequest
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listChangeRequestsByWorkspace = `-- name: ListChangeRequestsByWorkspace :many
|
||||
SELECT id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at FROM change_requests
|
||||
WHERE workspace_id = $1
|
||||
ORDER BY number DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListChangeRequestsByWorkspace(ctx context.Context, workspaceID pgtype.UUID) ([]ChangeRequest, error) {
|
||||
rows, err := q.db.Query(ctx, listChangeRequestsByWorkspace, workspaceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ChangeRequest
|
||||
for rows.Next() {
|
||||
var i ChangeRequest
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const nextChangeRequestNumber = `-- name: NextChangeRequestNumber :one
|
||||
SELECT COALESCE(MAX(number), 0) + 1 FROM change_requests WHERE project_id = $1 FOR UPDATE
|
||||
`
|
||||
|
||||
// Per-project monotonic number; FOR UPDATE not needed because the
|
||||
// max(number)+1 INSERT runs inside the same tx, but we lock existing project
|
||||
// rows to serialize concurrent creates within a project.
|
||||
func (q *Queries) NextChangeRequestNumber(ctx context.Context, projectID pgtype.UUID) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, nextChangeRequestNumber, projectID)
|
||||
var column_1 int32
|
||||
err := row.Scan(&column_1)
|
||||
return column_1, err
|
||||
}
|
||||
|
||||
const updateChangeRequestCI = `-- name: UpdateChangeRequestCI :one
|
||||
UPDATE change_requests
|
||||
SET ci_state = $2,
|
||||
state = $3,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateChangeRequestCIParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CiState string `json:"ci_state"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateChangeRequestCI(ctx context.Context, arg UpdateChangeRequestCIParams) (ChangeRequest, error) {
|
||||
row := q.db.QueryRow(ctx, updateChangeRequestCI, arg.ID, arg.CiState, arg.State)
|
||||
var i ChangeRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateChangeRequestReview = `-- name: UpdateChangeRequestReview :one
|
||||
UPDATE change_requests
|
||||
SET review_verdict = $2,
|
||||
reviewed_by = $3,
|
||||
reviewed_at = now(),
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateChangeRequestReviewParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ReviewVerdict string `json:"review_verdict"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateChangeRequestReview(ctx context.Context, arg UpdateChangeRequestReviewParams) (ChangeRequest, error) {
|
||||
row := q.db.QueryRow(ctx, updateChangeRequestReview, arg.ID, arg.ReviewVerdict, arg.ReviewedBy)
|
||||
var i ChangeRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateChangeRequestState = `-- name: UpdateChangeRequestState :one
|
||||
UPDATE change_requests
|
||||
SET state = $2,
|
||||
merge_commit_sha = $3,
|
||||
merged_at = $4,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, project_id, workspace_id, requirement_id, issue_id, number, title, description, source_branch, target_branch, state, review_verdict, ci_state, provider, external_id, external_url, merge_commit_sha, reviewed_by, reviewed_at, created_by, merged_at, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateChangeRequestStateParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
State string `json:"state"`
|
||||
MergeCommitSha string `json:"merge_commit_sha"`
|
||||
MergedAt pgtype.Timestamptz `json:"merged_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateChangeRequestState(ctx context.Context, arg UpdateChangeRequestStateParams) (ChangeRequest, error) {
|
||||
row := q.db.QueryRow(ctx, updateChangeRequestState,
|
||||
arg.ID,
|
||||
arg.State,
|
||||
arg.MergeCommitSha,
|
||||
arg.MergedAt,
|
||||
)
|
||||
var i ChangeRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.WorkspaceID,
|
||||
&i.RequirementID,
|
||||
&i.IssueID,
|
||||
&i.Number,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.SourceBranch,
|
||||
&i.TargetBranch,
|
||||
&i.State,
|
||||
&i.ReviewVerdict,
|
||||
&i.CiState,
|
||||
&i.Provider,
|
||||
&i.ExternalID,
|
||||
&i.ExternalUrl,
|
||||
&i.MergeCommitSha,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedBy,
|
||||
&i.MergedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package changerequestsqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,593 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package changerequestsqlc
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pgvector/pgvector-go"
|
||||
)
|
||||
|
||||
type AcpAgentKind struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
BinaryPath string `json:"binary_path"`
|
||||
Args []string `json:"args"`
|
||||
EncryptedEnv []byte `json:"encrypted_env"`
|
||||
Enabled bool `json:"enabled"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ToolAllowlist []string `json:"tool_allowlist"`
|
||||
ClientType string `json:"client_type"`
|
||||
EncryptedMcpServers []byte `json:"encrypted_mcp_servers"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
MaxCostUsd pgtype.Numeric `json:"max_cost_usd"`
|
||||
MaxTokens *int64 `json:"max_tokens"`
|
||||
MaxWallClockSeconds *int32 `json:"max_wall_clock_seconds"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type AcpAgentKindConfigFile struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
RelPath string `json:"rel_path"`
|
||||
EncryptedContent []byte `json:"encrypted_content"`
|
||||
UpdatedBy pgtype.UUID `json:"updated_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type AcpEvent struct {
|
||||
ID int64 `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
Direction string `json:"direction"`
|
||||
RpcKind string `json:"rpc_kind"`
|
||||
Method *string `json:"method"`
|
||||
Payload []byte `json:"payload"`
|
||||
PayloadSize int32 `json:"payload_size"`
|
||||
Truncated bool `json:"truncated"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcpPermissionRequest struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
AgentRequestID string `json:"agent_request_id"`
|
||||
ToolName string `json:"tool_name"`
|
||||
ToolCall []byte `json:"tool_call"`
|
||||
Options []byte `json:"options"`
|
||||
Status string `json:"status"`
|
||||
ChosenOptionID *string `json:"chosen_option_id"`
|
||||
DecidedBy pgtype.UUID `json:"decided_by"`
|
||||
DecidedAt pgtype.Timestamptz `json:"decided_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcpSession struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
AgentSessionID *string `json:"agent_session_id"`
|
||||
Branch string `json:"branch"`
|
||||
CwdPath string `json:"cwd_path"`
|
||||
IsMainWorktree bool `json:"is_main_worktree"`
|
||||
Status string `json:"status"`
|
||||
Pid *int32 `json:"pid"`
|
||||
ExitCode *int32 `json:"exit_code"`
|
||||
LastError *string `json:"last_error"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
EndedAt pgtype.Timestamptz `json:"ended_at"`
|
||||
LastStopReason *string `json:"last_stop_reason"`
|
||||
OrchestratorStepID pgtype.UUID `json:"orchestrator_step_id"`
|
||||
PromptTokens int64 `json:"prompt_tokens"`
|
||||
CompletionTokens int64 `json:"completion_tokens"`
|
||||
ThinkingTokens int64 `json:"thinking_tokens"`
|
||||
TotalCostUsd pgtype.Numeric `json:"total_cost_usd"`
|
||||
LastActivityAt pgtype.Timestamptz `json:"last_activity_at"`
|
||||
BudgetMaxCostUsd pgtype.Numeric `json:"budget_max_cost_usd"`
|
||||
BudgetMaxTokens *int64 `json:"budget_max_tokens"`
|
||||
BudgetMaxWallClockSeconds *int32 `json:"budget_max_wall_clock_seconds"`
|
||||
TerminatedReason *string `json:"terminated_reason"`
|
||||
SandboxMode *string `json:"sandbox_mode"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
TokensTotal int64 `json:"tokens_total"`
|
||||
}
|
||||
|
||||
type AcpSessionUsage struct {
|
||||
ID int64 `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
PromptTokens int64 `json:"prompt_tokens"`
|
||||
CompletionTokens int64 `json:"completion_tokens"`
|
||||
ThinkingTokens int64 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
SourceEventID *int64 `json:"source_event_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcpTurn struct {
|
||||
ID int64 `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
TurnIndex int32 `json:"turn_index"`
|
||||
PromptRequestID *string `json:"prompt_request_id"`
|
||||
Status string `json:"status"`
|
||||
StopReason *string `json:"stop_reason"`
|
||||
UpdateCount int32 `json:"update_count"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
||||
}
|
||||
|
||||
type AuditLog struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Action string `json:"action"`
|
||||
TargetType *string `json:"target_type"`
|
||||
TargetID *string `json:"target_id"`
|
||||
Ip *netip.Addr `json:"ip"`
|
||||
Metadata []byte `json:"metadata"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type ChangeRequest struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
SourceBranch string `json:"source_branch"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
State string `json:"state"`
|
||||
ReviewVerdict string `json:"review_verdict"`
|
||||
CiState string `json:"ci_state"`
|
||||
Provider string `json:"provider"`
|
||||
ExternalID *int64 `json:"external_id"`
|
||||
ExternalUrl string `json:"external_url"`
|
||||
MergeCommitSha string `json:"merge_commit_sha"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
MergedAt pgtype.Timestamptz `json:"merged_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type CodeChunk struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
RunID pgtype.UUID `json:"run_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
FilePath string `json:"file_path"`
|
||||
Lang *string `json:"lang"`
|
||||
StartLine int32 `json:"start_line"`
|
||||
EndLine int32 `json:"end_line"`
|
||||
Content string `json:"content"`
|
||||
ContentSha []byte `json:"content_sha"`
|
||||
TokenCount *int32 `json:"token_count"`
|
||||
Embedding *pgvector.Vector `json:"embedding"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type CodeIndexRun struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
WorktreeID pgtype.UUID `json:"worktree_id"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Status string `json:"status"`
|
||||
EmbeddingEndpointID pgtype.UUID `json:"embedding_endpoint_id"`
|
||||
EmbeddingModel string `json:"embedding_model"`
|
||||
Dims int32 `json:"dims"`
|
||||
FilesIndexed int32 `json:"files_indexed"`
|
||||
ChunksIndexed int32 `json:"chunks_indexed"`
|
||||
Error *string `json:"error"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
FinishedAt pgtype.Timestamptz `json:"finished_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type CommitSummary struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
WorktreeID pgtype.UUID `json:"worktree_id"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Kind string `json:"kind"`
|
||||
Title *string `json:"title"`
|
||||
BodyMd string `json:"body_md"`
|
||||
Model *string `json:"model"`
|
||||
Status string `json:"status"`
|
||||
Error *string `json:"error"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Conversation struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
SystemPrompt string `json:"system_prompt"`
|
||||
Title *string `json:"title"`
|
||||
TitleGeneratedAt pgtype.Timestamptz `json:"title_generated_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
}
|
||||
|
||||
type CryptoKey struct {
|
||||
Version int32 `json:"version"`
|
||||
Provider string `json:"provider"`
|
||||
KeyRef *string `json:"key_ref"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type GitCredential struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Kind string `json:"kind"`
|
||||
Username *string `json:"username"`
|
||||
EncryptedSecret []byte `json:"encrypted_secret"`
|
||||
Fingerprint *string `json:"fingerprint"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
AssigneeID pgtype.UUID `json:"assignee_id"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
ClosedAt pgtype.Timestamptz `json:"closed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
ParentID pgtype.UUID `json:"parent_id"`
|
||||
Priority int32 `json:"priority"`
|
||||
}
|
||||
|
||||
type IssueDependency struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
BlockedID pgtype.UUID `json:"blocked_id"`
|
||||
BlockerID pgtype.UUID `json:"blocker_id"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Payload []byte `json:"payload"`
|
||||
Status string `json:"status"`
|
||||
ScheduledAt pgtype.Timestamptz `json:"scheduled_at"`
|
||||
Attempts int32 `json:"attempts"`
|
||||
MaxAttempts int32 `json:"max_attempts"`
|
||||
LeasedAt pgtype.Timestamptz `json:"leased_at"`
|
||||
LeasedBy *string `json:"leased_by"`
|
||||
LastError *string `json:"last_error"`
|
||||
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LlmEndpoint struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
DisplayName string `json:"display_name"`
|
||||
BaseUrl string `json:"base_url"`
|
||||
ApiKeyEncrypted []byte `json:"api_key_encrypted"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type LlmModel struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EndpointID pgtype.UUID `json:"endpoint_id"`
|
||||
ModelID string `json:"model_id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Capabilities []byte `json:"capabilities"`
|
||||
ContextWindow int32 `json:"context_window"`
|
||||
MaxOutputTokens int32 `json:"max_output_tokens"`
|
||||
PromptPricePerMillionUsd pgtype.Numeric `json:"prompt_price_per_million_usd"`
|
||||
CompletionPricePerMillionUsd pgtype.Numeric `json:"completion_price_per_million_usd"`
|
||||
ThinkingPricePerMillionUsd pgtype.Numeric `json:"thinking_price_per_million_usd"`
|
||||
IsTitleGenerator bool `json:"is_title_generator"`
|
||||
Enabled bool `json:"enabled"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LlmUsage struct {
|
||||
ID int64 `json:"id"`
|
||||
ConversationID pgtype.UUID `json:"conversation_id"`
|
||||
MessageID int64 `json:"message_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EndpointID pgtype.UUID `json:"endpoint_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type McpToken struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
TokenHash []byte `json:"token_hash"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
Issuer string `json:"issuer"`
|
||||
Scope []byte `json:"scope"`
|
||||
AcpSessionID pgtype.UUID `json:"acp_session_id"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
|
||||
RevokedAt pgtype.Timestamptz `json:"revoked_at"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
ID int64 `json:"id"`
|
||||
ConversationID pgtype.UUID `json:"conversation_id"`
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
Thinking *string `json:"thinking"`
|
||||
ToolCalls []byte `json:"tool_calls"`
|
||||
Status string `json:"status"`
|
||||
ErrorMessage *string `json:"error_message"`
|
||||
PromptTokens *int32 `json:"prompt_tokens"`
|
||||
CompletionTokens *int32 `json:"completion_tokens"`
|
||||
ThinkingTokens *int32 `json:"thinking_tokens"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type MessageAttachment struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
MessageID *int64 `json:"message_id"`
|
||||
Filename string `json:"filename"`
|
||||
MimeType string `json:"mime_type"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
Sha256 string `json:"sha256"`
|
||||
StoragePath string `json:"storage_path"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Topic string `json:"topic"`
|
||||
Severity string `json:"severity"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Link *string `json:"link"`
|
||||
Metadata []byte `json:"metadata"`
|
||||
ReadAt pgtype.Timestamptz `json:"read_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type NotificationPref struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EmailEnabled bool `json:"email_enabled"`
|
||||
ImEnabled bool `json:"im_enabled"`
|
||||
ImWebhookUrlEnc []byte `json:"im_webhook_url_enc"`
|
||||
MinSeverity string `json:"min_severity"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type OrchestratorRun struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Status string `json:"status"`
|
||||
CurrentPhase string `json:"current_phase"`
|
||||
Config []byte `json:"config"`
|
||||
LastError *string `json:"last_error"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
EndedAt pgtype.Timestamptz `json:"ended_at"`
|
||||
}
|
||||
|
||||
type OrchestratorStep struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
RunID pgtype.UUID `json:"run_id"`
|
||||
Phase string `json:"phase"`
|
||||
Attempt int32 `json:"attempt"`
|
||||
ParentStepID pgtype.UUID `json:"parent_step_id"`
|
||||
Depth int32 `json:"depth"`
|
||||
Status string `json:"status"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
AcpSessionID pgtype.UUID `json:"acp_session_id"`
|
||||
Prompt string `json:"prompt"`
|
||||
StopReason *string `json:"stop_reason"`
|
||||
GateResult []byte `json:"gate_result"`
|
||||
LastError *string `json:"last_error"`
|
||||
JobID pgtype.UUID `json:"job_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
EndedAt pgtype.Timestamptz `json:"ended_at"`
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Visibility string `json:"visibility"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
ArchivedAt pgtype.Timestamptz `json:"archived_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ProjectMember struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
AddedBy pgtype.UUID `json:"added_by"`
|
||||
}
|
||||
|
||||
type ProjectMemory struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Kind string `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Tags []string `json:"tags"`
|
||||
Source string `json:"source"`
|
||||
Embedding *pgvector.Vector `json:"embedding"`
|
||||
EmbeddingModel *string `json:"embedding_model"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type PromptTemplate struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
Scope string `json:"scope"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Requirement struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Phase string `json:"phase"`
|
||||
Status string `json:"status"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
ClosedAt pgtype.Timestamptz `json:"closed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
}
|
||||
|
||||
type RequirementArtifact struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
Phase string `json:"phase"`
|
||||
Version int32 `json:"version"`
|
||||
Content string `json:"content"`
|
||||
Note string `json:"note"`
|
||||
SourceMessageID *int64 `json:"source_message_id"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Verdict string `json:"verdict"`
|
||||
}
|
||||
|
||||
type RequirementPhasePointer struct {
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
Phase string `json:"phase"`
|
||||
ApprovedArtifactID pgtype.UUID `json:"approved_artifact_id"`
|
||||
ApprovedBy pgtype.UUID `json:"approved_by"`
|
||||
ApprovedAt pgtype.Timestamptz `json:"approved_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
DisplayName string `json:"display_name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type UserSession struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
TokenHash []byte `json:"token_hash"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
LastSeenAt pgtype.Timestamptz `json:"last_seen_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
GitRemoteUrl string `json:"git_remote_url"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
MainPath string `json:"main_path"`
|
||||
SyncStatus string `json:"sync_status"`
|
||||
LastSyncedAt pgtype.Timestamptz `json:"last_synced_at"`
|
||||
LastSyncError *string `json:"last_sync_error"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ActiveMainSessionID pgtype.UUID `json:"active_main_session_id"`
|
||||
}
|
||||
|
||||
type WorkspaceRunProfile struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Command string `json:"command"`
|
||||
Args []string `json:"args"`
|
||||
EncryptedEnv []byte `json:"encrypted_env"`
|
||||
Enabled bool `json:"enabled"`
|
||||
LastStartedAt pgtype.Timestamptz `json:"last_started_at"`
|
||||
LastExitCode *int32 `json:"last_exit_code"`
|
||||
LastError string `json:"last_error"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type WorkspaceWorktree struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Branch string `json:"branch"`
|
||||
Path string `json:"path"`
|
||||
Status string `json:"status"`
|
||||
ActiveHolder *string `json:"active_holder"`
|
||||
AcquiredAt pgtype.Timestamptz `json:"acquired_at"`
|
||||
LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
PruneWarningAt pgtype.Timestamptz `json:"prune_warning_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user