rdev/internal/handlers/sdlc_merge.go
jordan 56e3f83955 feat: add auth scopes, OpenAPI docs, SDLC guides, and code quality improvements
- Add auth.RequireScope() to all handler routes for proper authorization
- Add SDLC OpenAPI endpoint documentation (state, features, tasks, branches, merge, archive, orchestrator)
- Add SDLC documentation guides (getting-started, cli-reference, api-reference, command-catalog)
- Add artifact_test.go for SDLC artifact coverage
- Add CLAUDE.md rules: auth scopes requirement, error wrapping with %w
- Fix error wrapping to use %w instead of %v throughout codebase
- Improve CLI merge command with conflict detection and resolution
- Fix handler tests to include auth middleware for RequireScope
- Add cookbook tree runner scripts for automated testing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 13:55:50 -07:00

61 lines
1.6 KiB
Go

package handlers
import (
"context"
"errors"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/orchard9/rdev/pkg/api"
)
// MergeFeatureRequest is the request body for merging a feature.
type MergeFeatureRequest struct {
Strategy string `json:"strategy,omitempty"`
}
// MergeFeature merges a feature branch after all gates pass.
// POST /projects/{id}/sdlc/features/{slug}/merge
func (h *SDLCHandler) MergeFeature(w http.ResponseWriter, r *http.Request) {
projectID := chi.URLParam(r, "id")
slug := chi.URLParam(r, "slug")
var req MergeFeatureRequest
if err := api.DecodeJSON(r, &req); err != nil && !errors.Is(err, api.ErrEmptyBody) {
api.WriteBadRequest(w, r, "invalid request body")
return
}
strategy := req.Strategy
if strategy == "" {
strategy = "squash"
}
ctx, cancel := context.WithTimeout(r.Context(), TimeoutHeavyWrite)
defer cancel()
if err := h.sdlcService.MergeFeature(ctx, projectID, slug, strategy); err != nil {
writeSDLCError(w, r, err)
return
}
api.WriteSuccess(w, r, map[string]string{"status": "merged", "strategy": strategy})
}
// ArchiveFeature archives a released feature.
// POST /projects/{id}/sdlc/features/{slug}/archive
func (h *SDLCHandler) ArchiveFeature(w http.ResponseWriter, r *http.Request) {
projectID := chi.URLParam(r, "id")
slug := chi.URLParam(r, "slug")
ctx, cancel := context.WithTimeout(r.Context(), TimeoutStandard)
defer cancel()
if err := h.sdlcService.ArchiveFeature(ctx, projectID, slug); err != nil {
writeSDLCError(w, r, err)
return
}
api.WriteSuccess(w, r, map[string]string{"status": "archived"})
}