85 lines
2.1 KiB
Go
85 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/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,
|
|
})
|
|
}
|