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" ) // WorkflowRunStatus fetches the status of a Gitea Actions run. type WorkflowRunStatus struct { c *gitea.Client a *allowlist.Allowlist } func NewWorkflowRunStatus(c *gitea.Client, a *allowlist.Allowlist) *WorkflowRunStatus { return &WorkflowRunStatus{c: c, a: a} } func (t *WorkflowRunStatus) Descriptor() registry.ToolDescriptor { return registry.ToolDescriptor{ Name: "workflow_run_status", Description: "Get the status of a Gitea Actions workflow run.", InputSchema: json.RawMessage(`{ "type":"object", "properties":{ "owner":{"type":"string"}, "name":{"type":"string"}, "run_id":{"type":"integer","minimum":1} }, "required":["owner","name","run_id"] }`), } } type workflowRunStatusArgs struct { Owner string `json:"owner"` Name string `json:"name"` RunID int64 `json:"run_id"` } func (t *WorkflowRunStatus) Call(ctx context.Context, raw json.RawMessage) (json.RawMessage, error) { var args workflowRunStatusArgs if err := parseArgs(raw, &args); err != nil { return nil, err } if err := t.a.Check(args.Owner); err != nil { return nil, err } if args.RunID < 1 { return nil, fmt.Errorf("run_id must be >= 1: %w", gitea.ErrValidation) } run, err := t.c.GetWorkflowRun(ctx, args.Owner, args.Name, args.RunID) if err != nil { return nil, err } return textOK(map[string]any{ "run_id": run.ID, "status": run.Status, "conclusion": run.Conclusion, "started_at": run.StartedAt, "html_url": run.HTMLURL, }) }