Adds PATCH /api/config/repos/{owner}/{name}, a dedicated seam distinct
from the generic dotted-key PATCH /api/config path: a repository is
one element of []config.Repo, not a flat key. Traced the mechanism
before adding any new plumbing -- overlay.Nest/ApplyOverlayValues
already handle "repos" as a single whole-slice key with no dot, so
the fix is a webui handler plus a bootstrap seam that reads the
daemon's live, untrimmed Repos (never webui.RepoView, which omits
Preflight/TestGlob), mutates the one matched field via the pure
applyRepoFieldUpdate helper, and republishes through the existing
UpdateConfig(ctx, {"repos": repos}) path unchanged.
config-row.js's row() gains an opts.save override so an edit can be
redirected to a different persistence call. The repositories table
renders an autosaving checkbox for the two booleans and a
save-on-blur/Enter input for max_retries, via api.configRepoUpdate.
Closes archie-core-b6ew.6, and with it archie-core-b6ew.
69 lines
2.7 KiB
Go
69 lines
2.7 KiB
Go
package archied
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/overlay"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
// applyDottedOverlay decodes dotted-path updates into cfg. yaml cannot
|
|
// decode dotted keys ("budgets.max_steps" is not a struct field), so
|
|
// the updates are nested into a map first -- the same nesting the
|
|
// overlay store's Snapshot performs -- then decoded with the same
|
|
// field-level merge the file overlay uses. cfg must be a copy the
|
|
// caller owns (a Clone of the published config); it is never decoded
|
|
// into a published snapshot directly.
|
|
func applyDottedOverlay(cfg *config.Config, updates map[string]any) error {
|
|
nested := make(map[string]any)
|
|
for key, value := range updates {
|
|
if err := overlay.Nest(nested, key, value); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return configuration.ApplyOverlayValues(cfg, nested)
|
|
}
|
|
|
|
// applyRepoFieldUpdate returns a copy of repos with one editable field
|
|
// changed on the repository matched by owner/name (archie-core-b6ew.6).
|
|
// repos must already be a caller-owned copy (config.Config.Clone's
|
|
// Repos) -- this mutates the matched element in place and returns the
|
|
// same slice, matching applyDottedOverlay's "caller owns the copy"
|
|
// contract. Kept as a pure function, separate from
|
|
// installUpdateRepoFieldHandler's closure, so the field-matching and
|
|
// type-coercion logic is directly unit-testable without constructing a
|
|
// full boot.
|
|
func applyRepoFieldUpdate(repos []config.Repo, owner, name, field string, value any) ([]config.Repo, error) {
|
|
if !webui.RepoEditableFields[field] {
|
|
return nil, fmt.Errorf("%w: repo field %s is not editable from the dashboard", webui.ErrConfigUpdateInvalid, field)
|
|
}
|
|
index := slices.IndexFunc(repos, func(r config.Repo) bool { return r.Owner == owner && r.Name == name })
|
|
if index < 0 {
|
|
return nil, fmt.Errorf("%w: repository %s/%s is not configured", webui.ErrConfigUpdateInvalid, owner, name)
|
|
}
|
|
switch field {
|
|
case "allow_concurrent":
|
|
v, ok := value.(bool)
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: allow_concurrent must be a boolean", webui.ErrConfigUpdateInvalid)
|
|
}
|
|
repos[index].AllowConcurrent = v
|
|
case "review_enabled":
|
|
v, ok := value.(bool)
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: review_enabled must be a boolean", webui.ErrConfigUpdateInvalid)
|
|
}
|
|
repos[index].ReviewEnabled = v
|
|
case "max_retries":
|
|
v, ok := value.(float64)
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: max_retries must be a number", webui.ErrConfigUpdateInvalid)
|
|
}
|
|
repos[index].MaxRetries = int(v)
|
|
}
|
|
return repos, nil
|
|
}
|