issue_get: GET /repos/{owner}/{repo}/issues/{number} — full issue with labels, assignees, comment count
release_create: POST /repos/{owner}/{repo}/releases — create release and tag in one call
repo_delete: DELETE /repos/{owner}/{repo} — confirm=<repo name> required, blocks accidents
60 lines
1.6 KiB
Go
60 lines
1.6 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 RepoDelete struct {
|
|
c *gitea.Client
|
|
a *allowlist.Allowlist
|
|
}
|
|
|
|
func NewRepoDelete(c *gitea.Client, a *allowlist.Allowlist) *RepoDelete {
|
|
return &RepoDelete{c: c, a: a}
|
|
}
|
|
|
|
func (t *RepoDelete) Descriptor() registry.ToolDescriptor {
|
|
return registry.ToolDescriptor{
|
|
Name: "repo_delete",
|
|
Description: "Permanently delete a repository. Requires confirm=<repo name> to prevent accidents.",
|
|
InputSchema: json.RawMessage(`{
|
|
"type":"object",
|
|
"properties":{
|
|
"owner":{"type":"string"},
|
|
"name":{"type":"string"},
|
|
"confirm":{"type":"string","description":"Must equal the repo name exactly to proceed."}
|
|
},
|
|
"required":["owner","name","confirm"]
|
|
}`),
|
|
}
|
|
}
|
|
|
|
type repoDeleteArgs struct {
|
|
Owner string `json:"owner"`
|
|
Name string `json:"name"`
|
|
Confirm string `json:"confirm"`
|
|
}
|
|
|
|
func (t *RepoDelete) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
|
|
var args repoDeleteArgs
|
|
if err := parseArgs(raw, &args); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := t.a.Check(args.Owner); err != nil {
|
|
return nil, err
|
|
}
|
|
if args.Confirm != args.Name {
|
|
return nil, fmt.Errorf("repo_delete requires confirm=%q to match the repo name — got %q", args.Name, args.Confirm)
|
|
}
|
|
if err := t.c.DeleteRepo(ctx, args.Owner, args.Name); err != nil {
|
|
return nil, err
|
|
}
|
|
return textOK(map[string]string{"status": "deleted", "repo": args.Owner + "/" + args.Name})
|
|
}
|