Allowlist.Check now takes ctx: when the caller authenticated with their own Gitea PAT (pass-through, v0.12.0), it skips the static GITEA_MCP_ALLOWED_OWNERS check entirely — Gitea's own permission model already gates that caller's access more precisely than a coarse owner-name list can. The static list still applies unchanged for the shared static-token/JWT path, where it's the only defense against the service token's blast radius. Mechanical: every tool call site already had ctx in scope, so this is a signature-only change at 41 call sites, no other tool behavior changes. Closes the "Deferred" item from #59. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"git.d-ma.be/mathias/gitea-mcp/internal/allowlist"
|
|
"git.d-ma.be/mathias/gitea-mcp/internal/gitea"
|
|
"git.d-ma.be/mathias/gitea-mcp/internal/registry"
|
|
)
|
|
|
|
type WorkflowRunList struct {
|
|
c *gitea.Client
|
|
a *allowlist.Allowlist
|
|
}
|
|
|
|
func NewWorkflowRunList(c *gitea.Client, a *allowlist.Allowlist) *WorkflowRunList {
|
|
return &WorkflowRunList{c: c, a: a}
|
|
}
|
|
|
|
func (t *WorkflowRunList) Descriptor() registry.ToolDescriptor {
|
|
return registry.ToolDescriptor{
|
|
Name: "workflow_run_list",
|
|
Description: "List recent Gitea Actions workflow runs with optional filters (branch, head_sha, status, event, workflow).",
|
|
InputSchema: json.RawMessage(`{
|
|
"type":"object",
|
|
"properties":{
|
|
"owner":{"type":"string"},
|
|
"repo":{"type":"string"},
|
|
"branch":{"type":"string"},
|
|
"head_sha":{"type":"string"},
|
|
"status":{"type":"string","enum":["queued","in_progress","completed","all"]},
|
|
"event":{"type":"string","enum":["push","pull_request","schedule","workflow_dispatch","all"]},
|
|
"workflow":{"type":"string"},
|
|
"page":{"type":"integer","minimum":1},
|
|
"limit":{"type":"integer","minimum":1,"maximum":50}
|
|
},
|
|
"required":["owner","repo"]
|
|
}`),
|
|
}
|
|
}
|
|
|
|
type workflowRunListArgs struct {
|
|
Owner string `json:"owner"`
|
|
Repo string `json:"repo"`
|
|
Branch string `json:"branch"`
|
|
HeadSHA string `json:"head_sha"`
|
|
Status string `json:"status"`
|
|
Event string `json:"event"`
|
|
Workflow string `json:"workflow"`
|
|
Page int `json:"page"`
|
|
Limit int `json:"limit"`
|
|
}
|
|
|
|
func (t *WorkflowRunList) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) {
|
|
var args workflowRunListArgs
|
|
if err := parseArgs(raw, &args); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := t.a.Check(ctx, args.Owner); err != nil {
|
|
return nil, err
|
|
}
|
|
args.Limit = capLimit(args.Limit, 10)
|
|
if args.Page < 1 {
|
|
args.Page = 1
|
|
}
|
|
resp, err := t.c.ListWorkflowRuns(ctx, args.Owner, args.Repo, gitea.ListWorkflowRunsArgs{
|
|
Branch: args.Branch,
|
|
HeadSHA: args.HeadSHA,
|
|
Status: args.Status,
|
|
Event: args.Event,
|
|
Workflow: args.Workflow,
|
|
Page: args.Page,
|
|
Limit: args.Limit,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := map[string]any{
|
|
"runs": resp.WorkflowRuns,
|
|
"total": resp.TotalCount,
|
|
}
|
|
if len(resp.WorkflowRuns) == args.Limit {
|
|
out["next_page"] = args.Page + 1
|
|
}
|
|
return textOK(out)
|
|
}
|