repo_create: POST /user/repos or /orgs/{org}/repos, is_org flag routes
repo_update: PATCH /repos/{owner}/{repo}, confirm required when private=false
repo_mirror_push: add/list/delete push mirrors, password never returned
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitea.d-ma.be/mathias/gitea-mcp/internal/allowlist"
|
|
"gitea.d-ma.be/mathias/gitea-mcp/internal/gitea"
|
|
"gitea.d-ma.be/mathias/gitea-mcp/internal/registry"
|
|
)
|
|
|
|
type RepoUpdate struct {
|
|
c *gitea.Client
|
|
a *allowlist.Allowlist
|
|
}
|
|
|
|
func NewRepoUpdate(c *gitea.Client, a *allowlist.Allowlist) *RepoUpdate {
|
|
return &RepoUpdate{c: c, a: a}
|
|
}
|
|
|
|
func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
|
|
return registry.ToolDescriptor{
|
|
Name: "repo_update",
|
|
Description: "Update repository metadata (description, visibility, default branch, website).",
|
|
InputSchema: json.RawMessage(`{
|
|
"type":"object",
|
|
"properties":{
|
|
"owner":{"type":"string"},
|
|
"name":{"type":"string"},
|
|
"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."}
|
|
},
|
|
"required":["owner","name"]
|
|
}`),
|
|
}
|
|
}
|
|
|
|
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"`
|
|
}
|
|
|
|
func (t *RepoUpdate) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
|
|
var args repoUpdateArgs
|
|
if err := parseArgs(raw, &args); err != nil {
|
|
return nil, err
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
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 err != nil {
|
|
return nil, err
|
|
}
|
|
return textOK(r)
|
|
}
|