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 BranchDelete struct { c *gitea.Client a *allowlist.Allowlist } func NewBranchDelete(c *gitea.Client, a *allowlist.Allowlist) *BranchDelete { return &BranchDelete{c: c, a: a} } func (t *BranchDelete) Descriptor() registry.ToolDescriptor { return registry.ToolDescriptor{ Name: "branch_delete", Description: "Delete a branch from a repository.", InputSchema: json.RawMessage(`{ "type":"object", "properties":{ "owner":{"type":"string"}, "name":{"type":"string"}, "branch":{"type":"string"} }, "required":["owner","name","branch"] }`), } } type branchDeleteArgs struct { Owner string `json:"owner"` Name string `json:"name"` Branch string `json:"branch"` } func (t *BranchDelete) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) { var args branchDeleteArgs if err := parseArgs(raw, &args); err != nil { return nil, err } if err := t.a.Check(args.Owner); err != nil { return nil, err } if args.Branch == "" { return nil, fmt.Errorf("branch is required: %w", gitea.ErrValidation) } if err := t.c.DeleteBranch(ctx, args.Owner, args.Name, args.Branch); err != nil { return nil, err } return textOK(map[string]any{ "deleted": true, "branch": args.Branch, }) }