fix/v02-patch: pr_files_diff, template_name, repo_update #26
@@ -22,7 +22,7 @@ func NewRepoUpdate(c *gitea.Client, a *allowlist.Allowlist) *RepoUpdate {
|
|||||||
func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
|
func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
|
||||||
return registry.ToolDescriptor{
|
return registry.ToolDescriptor{
|
||||||
Name: "repo_update",
|
Name: "repo_update",
|
||||||
Description: "Update repository metadata via PATCH (archived, description, private, website, template). " +
|
Description: "Update repository metadata (description, visibility, default branch, website, archived, template). " +
|
||||||
"Only fields explicitly set in the call are patched. " +
|
"Only fields explicitly set in the call are patched. " +
|
||||||
"WARNING: private=false exposes the repo publicly — verify intent before calling.",
|
"WARNING: private=false exposes the repo publicly — verify intent before calling.",
|
||||||
InputSchema: json.RawMessage(`{
|
InputSchema: json.RawMessage(`{
|
||||||
@@ -30,11 +30,13 @@ func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
|
|||||||
"properties":{
|
"properties":{
|
||||||
"owner":{"type":"string"},
|
"owner":{"type":"string"},
|
||||||
"name":{"type":"string"},
|
"name":{"type":"string"},
|
||||||
"archived":{"type":"boolean","description":"Mark repo as archived (read-only). Reversible."},
|
|
||||||
"description":{"type":"string"},
|
"description":{"type":"string"},
|
||||||
"private":{"type":"boolean","description":"Toggle visibility. false makes the repo public."},
|
"private":{"type":"boolean","description":"Toggle visibility. false makes the repo public."},
|
||||||
"website":{"type":"string","description":"Homepage URL"},
|
"website":{"type":"string","description":"Homepage URL"},
|
||||||
"template":{"type":"boolean","description":"Toggle template-repo flag"}
|
"default_branch":{"type":"string","description":"Rename the default branch"},
|
||||||
|
"archived":{"type":"boolean","description":"Mark repo as archived (read-only)."},
|
||||||
|
"template":{"type":"boolean","description":"Toggle template-repo flag"},
|
||||||
|
"confirm":{"type":"string","description":"Required when setting private=false. Must equal the repo name."}
|
||||||
},
|
},
|
||||||
"required":["owner","name"]
|
"required":["owner","name"]
|
||||||
}`),
|
}`),
|
||||||
@@ -42,13 +44,15 @@ func (t *RepoUpdate) Descriptor() registry.ToolDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type repoUpdateArgs struct {
|
type repoUpdateArgs struct {
|
||||||
Owner string `json:"owner"`
|
Owner string `json:"owner"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Archived *bool `json:"archived,omitempty"`
|
Description *string `json:"description,omitempty"`
|
||||||
Description *string `json:"description,omitempty"`
|
Private *bool `json:"private,omitempty"`
|
||||||
Private *bool `json:"private,omitempty"`
|
Website *string `json:"website,omitempty"`
|
||||||
Website *string `json:"website,omitempty"`
|
DefaultBranch *string `json:"default_branch,omitempty"`
|
||||||
Template *bool `json:"template,omitempty"`
|
Archived *bool `json:"archived,omitempty"`
|
||||||
|
Template *bool `json:"template,omitempty"`
|
||||||
|
Confirm string `json:"confirm"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *RepoUpdate) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
|
func (t *RepoUpdate) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
|
||||||
@@ -59,23 +63,29 @@ func (t *RepoUpdate) Call(ctx context.Context, raw json.RawMessage) (json.RawMes
|
|||||||
if err := t.a.Check(args.Owner); err != nil {
|
if err := t.a.Check(args.Owner); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if args.Name == "" {
|
|
||||||
return nil, fmt.Errorf("name required: %w", gitea.ErrValidation)
|
// 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.Archived == nil && args.Description == nil && args.Private == nil &&
|
|
||||||
args.Website == nil && args.Template == nil {
|
if args.Description == nil && args.Private == nil && args.Website == nil &&
|
||||||
|
args.DefaultBranch == nil && args.Archived == nil && args.Template == nil {
|
||||||
return nil, fmt.Errorf("at least one updatable field must be set: %w", gitea.ErrValidation)
|
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{
|
r, err := t.c.UpdateRepo(ctx, args.Owner, args.Name, gitea.UpdateRepoArgs{
|
||||||
Archived: args.Archived,
|
Description: args.Description,
|
||||||
Description: args.Description,
|
Private: args.Private,
|
||||||
Private: args.Private,
|
Website: args.Website,
|
||||||
Website: args.Website,
|
DefaultBranch: args.DefaultBranch,
|
||||||
Template: args.Template,
|
Archived: args.Archived,
|
||||||
|
Template: args.Template,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("edit repo: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
return textOK(updated)
|
return textOK(r)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user