feat(tools): issue_create with identity footer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathias Bergqvist
2026-05-04 22:51:40 +02:00
parent 2c6b9986e4
commit 6f43ff216f
5 changed files with 309 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"gitea.d-ma.be/mathias/gitea-mcp/internal/allowlist"
"gitea.d-ma.be/mathias/gitea-mcp/internal/auth"
"gitea.d-ma.be/mathias/gitea-mcp/internal/gitea"
"gitea.d-ma.be/mathias/gitea-mcp/internal/identity"
"gitea.d-ma.be/mathias/gitea-mcp/internal/registry"
)
type IssueCreate struct {
c *gitea.Client
a *allowlist.Allowlist
}
func NewIssueCreate(c *gitea.Client, a *allowlist.Allowlist) *IssueCreate {
return &IssueCreate{c: c, a: a}
}
func (t *IssueCreate) Descriptor() registry.ToolDescriptor {
return registry.ToolDescriptor{
Name: "issue_create",
Description: "Create an issue. Applies identity footer to body.",
InputSchema: json.RawMessage(`{
"type":"object",
"properties":{
"owner":{"type":"string"},
"name":{"type":"string"},
"title":{"type":"string"},
"body":{"type":"string"},
"labels":{"type":"array","items":{"type":"integer"}},
"assignees":{"type":"array","items":{"type":"string"}},
"milestone":{"type":"integer"}
},
"required":["owner","name","title"]
}`),
}
}
type issueCreateArgs struct {
Owner string `json:"owner"`
Name string `json:"name"`
Title string `json:"title"`
Body string `json:"body"`
Labels []int64 `json:"labels"`
Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"`
}
func (t *IssueCreate) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
var args issueCreateArgs
if err := parseArgs(raw, &args); err != nil {
return nil, err
}
if err := t.a.Check(args.Owner); err != nil {
return nil, err
}
if args.Title == "" {
return nil, fmt.Errorf("title is required: %w", gitea.ErrValidation)
}
body := identity.ApplyFooter(args.Body, auth.Caller(ctx))
iss, err := t.c.CreateIssue(ctx, args.Owner, args.Name, gitea.CreateIssueArgs{
Title: args.Title,
Body: body,
Labels: args.Labels,
Assignees: args.Assignees,
Milestone: args.Milestone,
})
if err != nil {
return nil, err
}
return textOK(map[string]any{
"number": iss.Number,
"title": iss.Title,
"html_url": iss.HTMLURL,
"state": iss.State,
})
}