feat(repo_update): tool for archiving + metadata patches

Adds a repo_update tool exposing PATCH /api/v1/repos/{owner}/{name}
with optional pointer fields (archived, description, private,
website, template). Only fields set by the caller are sent on the
wire, so the server patches exactly what was asked for.

Originally needed to archive ingestion-svc cleanly instead of
leaving a README tombstone, and to flip template-go-{agent,web}
to template=true so create_project_from_template stops failing
the "is not marked as template" guard.

Wire-level enforcement of "at least one field" returns ErrValidation
before any network call, preventing no-op PATCHes.

private=false (making a repo public) is allowed but flagged in the
tool description with a "verify intent before calling" warning.
The earlier issue draft suggested an ntfy confirmation hook for
that path — out of scope for this PR; the warning string is the
minimum that fits inside the tool surface today.

Wires NewRepoUpdate into cmd/gitea-mcp/main.go alongside the rest
of the repo_* family.

Closes #12
This commit is contained in:
Mathias
2026-05-16 23:01:33 +02:00
parent 5545d6ab4b
commit eeefc626ed
3 changed files with 153 additions and 48 deletions

View File

@@ -21,18 +21,20 @@ func NewRepoUpdate(c *gitea.Client, a *allowlist.Allowlist) *RepoUpdate {
func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
return registry.ToolDescriptor{
Name: "repo_update",
Description: "Update repository metadata (description, visibility, default branch, website).",
Name: "repo_update",
Description: "Update repository metadata via PATCH (archived, description, private, website, template). " +
"Only fields explicitly set in the call are patched. " +
"WARNING: private=false exposes the repo publicly — verify intent before calling.",
InputSchema: json.RawMessage(`{
"type":"object",
"properties":{
"owner":{"type":"string"},
"name":{"type":"string"},
"archived":{"type":"boolean","description":"Mark repo as archived (read-only). Reversible."},
"description":{"type":"string"},
"private":{"type":"boolean"},
"website":{"type":"string"},
"default_branch":{"type":"string"},
"confirm":{"type":"string","description":"Required when setting private=false. Must equal the repo name."}
"private":{"type":"boolean","description":"Toggle visibility. false makes the repo public."},
"website":{"type":"string","description":"Homepage URL"},
"template":{"type":"boolean","description":"Toggle template-repo flag"}
},
"required":["owner","name"]
}`),
@@ -40,13 +42,13 @@ func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
}
type repoUpdateArgs struct {
Owner string `json:"owner"`
Name string `json:"name"`
Description *string `json:"description"`
Private *bool `json:"private"`
Website *string `json:"website"`
DefaultBranch *string `json:"default_branch"`
Confirm string `json:"confirm"`
Owner string `json:"owner"`
Name string `json:"name"`
Archived *bool `json:"archived,omitempty"`
Description *string `json:"description,omitempty"`
Private *bool `json:"private,omitempty"`
Website *string `json:"website,omitempty"`
Template *bool `json:"template,omitempty"`
}
func (t *RepoUpdate) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
@@ -57,20 +59,23 @@ func (t *RepoUpdate) Call(ctx context.Context, raw json.RawMessage) (json.RawMes
if err := t.a.Check(args.Owner); err != nil {
return nil, err
}
// Making a repo public is a significant action — require explicit confirmation.
if args.Private != nil && !*args.Private {
if args.Confirm != args.Name {
return nil, fmt.Errorf("setting private=false makes the repo public: set confirm=%q to proceed", args.Name)
}
if args.Name == "" {
return nil, fmt.Errorf("name required: %w", gitea.ErrValidation)
}
r, err := t.c.UpdateRepo(ctx, args.Owner, args.Name, gitea.UpdateRepoArgs{
Description: args.Description,
Private: args.Private,
Website: args.Website,
DefaultBranch: args.DefaultBranch,
if args.Archived == nil && args.Description == nil && args.Private == nil &&
args.Website == nil && args.Template == nil {
return nil, fmt.Errorf("at least one updatable field must be set: %w", gitea.ErrValidation)
}
updated, err := t.c.EditRepo(ctx, args.Owner, args.Name, gitea.EditRepoArgs{
Archived: args.Archived,
Description: args.Description,
Private: args.Private,
Website: args.Website,
Template: args.Template,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("edit repo: %w", err)
}
return textOK(r)
return textOK(updated)
}