chore: add golangci-lint, bump Go to 1.26, fix all lint issues (#133)

## Summary
- Add `.golangci.yml` with linter configuration matching the main gitea repo
- Add `lint`, `lint-fix`, `lint-go`, `lint-go-fix`, and `security-check` Makefile targets
- Add `tidy` Makefile target (extracts min Go version from `go.mod` for `-compat` flag)
- Bump minimum Go version to 1.26
- Update golangci-lint to v2.10.1
- Replace `golang/govulncheck-action` with `make security-check` in CI
- Add `make lint` step to CI
- Fix all lint issues across the codebase (formatting, `errors.New` vs `fmt.Errorf`, `any` vs `interface{}`, unused returns, stuttering names, Go 1.26 `new(expr)`, etc.)
- Remove unused `pkg/ptr` package (inlined by Go 1.26 `new(expr)`)
- Remove dead linter exclusions (staticcheck, gocritic, testifylint, dupl)

## Test plan
- [x] `make lint` passes
- [x] `go test ./...` passes
- [x] `make build` succeeds

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/133
Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-committed-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind
2026-02-22 17:10:04 +00:00
committed by techknowlogick
parent 4d5fa3ab2c
commit 8728c04748
34 changed files with 727 additions and 675 deletions

View File

@@ -6,5 +6,3 @@ import (
// Tool is the registry for all Actions-related MCP tools.
var Tool = tool.New()

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
@@ -67,7 +68,7 @@ func fetchJobLogBytes(ctx context.Context, owner, repo string, jobID int64) ([]b
}
lastErr = err
var httpErr *gitea.HTTPError
if errors.As(err, &httpErr) && (httpErr.StatusCode == 404 || httpErr.StatusCode == 405) {
if errors.As(err, &httpErr) && (httpErr.StatusCode == http.StatusNotFound || httpErr.StatusCode == http.StatusMethodNotAllowed) {
continue
}
return nil, p, err
@@ -109,15 +110,15 @@ func GetRepoActionJobLogPreviewFn(ctx context.Context, req mcp.CallToolRequest)
log.Debugf("Called GetRepoActionJobLogPreviewFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
jobIDFloat, ok := req.GetArguments()["job_id"].(float64)
if !ok || jobIDFloat <= 0 {
return to.ErrorResult(fmt.Errorf("job_id is required"))
return to.ErrorResult(errors.New("job_id is required"))
}
tailLinesFloat, _ := req.GetArguments()["tail_lines"].(float64)
maxBytesFloat, _ := req.GetArguments()["max_bytes"].(float64)
@@ -140,13 +141,13 @@ func GetRepoActionJobLogPreviewFn(ctx context.Context, req mcp.CallToolRequest)
limited, truncated := limitBytes(tailed, maxBytes)
return to.TextResult(map[string]any{
"endpoint": usedPath,
"job_id": jobID,
"bytes": len(raw),
"tail_lines": tailLines,
"max_bytes": maxBytes,
"truncated": truncated,
"log": string(limited),
"endpoint": usedPath,
"job_id": jobID,
"bytes": len(raw),
"tail_lines": tailLines,
"max_bytes": maxBytes,
"truncated": truncated,
"log": string(limited),
})
}
@@ -154,15 +155,15 @@ func DownloadRepoActionJobLogFn(ctx context.Context, req mcp.CallToolRequest) (*
log.Debugf("Called DownloadRepoActionJobLogFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
jobIDFloat, ok := req.GetArguments()["job_id"].(float64)
if !ok || jobIDFloat <= 0 {
return to.ErrorResult(fmt.Errorf("job_id is required"))
return to.ErrorResult(errors.New("job_id is required"))
}
outputPath, _ := req.GetArguments()["output_path"].(string)
jobID := int64(jobIDFloat)
@@ -194,5 +195,3 @@ func DownloadRepoActionJobLogFn(ctx context.Context, req mcp.CallToolRequest) (*
"bytes": len(raw),
})
}

View File

@@ -20,5 +20,3 @@ func TestLimitBytesKeepsTail(t *testing.T) {
t.Fatalf("limitBytes tail = %q, want %q", string(out), "6789")
}
}

View File

@@ -4,7 +4,10 @@ import (
"context"
"errors"
"fmt"
"maps"
"net/http"
"net/url"
"strconv"
"gitea.com/gitea/gitea-mcp/pkg/gitea"
"gitea.com/gitea/gitea-mcp/pkg/log"
@@ -125,32 +128,32 @@ func init() {
Tool.RegisterRead(server.ServerTool{Tool: ListRepoActionRunJobsTool, Handler: ListRepoActionRunJobsFn})
}
func doJSONWithFallback(ctx context.Context, method string, paths []string, query url.Values, body any, respOut any) (string, int, error) {
func doJSONWithFallback(ctx context.Context, method string, paths []string, query url.Values, body, respOut any) error {
var lastErr error
for _, p := range paths {
status, err := gitea.DoJSON(ctx, method, p, query, body, respOut)
_, err := gitea.DoJSON(ctx, method, p, query, body, respOut)
if err == nil {
return p, status, nil
return nil
}
lastErr = err
var httpErr *gitea.HTTPError
if errors.As(err, &httpErr) && (httpErr.StatusCode == 404 || httpErr.StatusCode == 405) {
if errors.As(err, &httpErr) && (httpErr.StatusCode == http.StatusNotFound || httpErr.StatusCode == http.StatusMethodNotAllowed) {
continue
}
return p, status, err
return err
}
return "", 0, lastErr
return lastErr
}
func ListRepoActionWorkflowsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ListRepoActionWorkflowsFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -161,11 +164,11 @@ func ListRepoActionWorkflowsFn(ctx context.Context, req mcp.CallToolRequest) (*m
pageSize = 50
}
query := url.Values{}
query.Set("page", fmt.Sprintf("%d", int(page)))
query.Set("limit", fmt.Sprintf("%d", int(pageSize)))
query.Set("page", strconv.Itoa(int(page)))
query.Set("limit", strconv.Itoa(int(pageSize)))
var result any
_, _, err := doJSONWithFallback(ctx, "GET",
err := doJSONWithFallback(ctx, "GET",
[]string{
fmt.Sprintf("repos/%s/%s/actions/workflows", url.PathEscape(owner), url.PathEscape(repo)),
},
@@ -181,19 +184,19 @@ func GetRepoActionWorkflowFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
log.Debugf("Called GetRepoActionWorkflowFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
workflowID, ok := req.GetArguments()["workflow_id"].(string)
if !ok || workflowID == "" {
return to.ErrorResult(fmt.Errorf("workflow_id is required"))
return to.ErrorResult(errors.New("workflow_id is required"))
}
var result any
_, _, err := doJSONWithFallback(ctx, "GET",
err := doJSONWithFallback(ctx, "GET",
[]string{
fmt.Sprintf("repos/%s/%s/actions/workflows/%s", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(workflowID)),
},
@@ -209,30 +212,28 @@ func DispatchRepoActionWorkflowFn(ctx context.Context, req mcp.CallToolRequest)
log.Debugf("Called DispatchRepoActionWorkflowFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
workflowID, ok := req.GetArguments()["workflow_id"].(string)
if !ok || workflowID == "" {
return to.ErrorResult(fmt.Errorf("workflow_id is required"))
return to.ErrorResult(errors.New("workflow_id is required"))
}
ref, ok := req.GetArguments()["ref"].(string)
if !ok || ref == "" {
return to.ErrorResult(fmt.Errorf("ref is required"))
return to.ErrorResult(errors.New("ref is required"))
}
var inputs map[string]any
if raw, exists := req.GetArguments()["inputs"]; exists {
if m, ok := raw.(map[string]any); ok {
inputs = m
} else if m, ok := raw.(map[string]interface{}); ok {
} else if m, ok := raw.(map[string]any); ok {
inputs = make(map[string]any, len(m))
for k, v := range m {
inputs[k] = v
}
maps.Copy(inputs, m)
}
}
@@ -243,7 +244,7 @@ func DispatchRepoActionWorkflowFn(ctx context.Context, req mcp.CallToolRequest)
body["inputs"] = inputs
}
_, _, err := doJSONWithFallback(ctx, "POST",
err := doJSONWithFallback(ctx, "POST",
[]string{
fmt.Sprintf("repos/%s/%s/actions/workflows/%s/dispatches", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(workflowID)),
fmt.Sprintf("repos/%s/%s/actions/workflows/%s/dispatch", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(workflowID)),
@@ -252,7 +253,7 @@ func DispatchRepoActionWorkflowFn(ctx context.Context, req mcp.CallToolRequest)
)
if err != nil {
var httpErr *gitea.HTTPError
if errors.As(err, &httpErr) && (httpErr.StatusCode == 404 || httpErr.StatusCode == 405) {
if errors.As(err, &httpErr) && (httpErr.StatusCode == http.StatusNotFound || httpErr.StatusCode == http.StatusMethodNotAllowed) {
return to.ErrorResult(fmt.Errorf("workflow dispatch not supported on this Gitea version (endpoint returned %d). Check https://docs.gitea.com/api/1.24/ for available Actions endpoints", httpErr.StatusCode))
}
return to.ErrorResult(fmt.Errorf("dispatch action workflow err: %v", err))
@@ -264,11 +265,11 @@ func ListRepoActionRunsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca
log.Debugf("Called ListRepoActionRunsFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -281,14 +282,14 @@ func ListRepoActionRunsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca
statusFilter, _ := req.GetArguments()["status"].(string)
query := url.Values{}
query.Set("page", fmt.Sprintf("%d", int(page)))
query.Set("limit", fmt.Sprintf("%d", int(pageSize)))
query.Set("page", strconv.Itoa(int(page)))
query.Set("limit", strconv.Itoa(int(pageSize)))
if statusFilter != "" {
query.Set("status", statusFilter)
}
var result any
_, _, err := doJSONWithFallback(ctx, "GET",
err := doJSONWithFallback(ctx, "GET",
[]string{
fmt.Sprintf("repos/%s/%s/actions/runs", url.PathEscape(owner), url.PathEscape(repo)),
},
@@ -304,19 +305,19 @@ func GetRepoActionRunFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Call
log.Debugf("Called GetRepoActionRunFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
runID, ok := req.GetArguments()["run_id"].(float64)
if !ok || runID <= 0 {
return to.ErrorResult(fmt.Errorf("run_id is required"))
return to.ErrorResult(errors.New("run_id is required"))
}
var result any
_, _, err := doJSONWithFallback(ctx, "GET",
err := doJSONWithFallback(ctx, "GET",
[]string{
fmt.Sprintf("repos/%s/%s/actions/runs/%d", url.PathEscape(owner), url.PathEscape(repo), int64(runID)),
},
@@ -332,18 +333,18 @@ func CancelRepoActionRunFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.C
log.Debugf("Called CancelRepoActionRunFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
runID, ok := req.GetArguments()["run_id"].(float64)
if !ok || runID <= 0 {
return to.ErrorResult(fmt.Errorf("run_id is required"))
return to.ErrorResult(errors.New("run_id is required"))
}
_, _, err := doJSONWithFallback(ctx, "POST",
err := doJSONWithFallback(ctx, "POST",
[]string{
fmt.Sprintf("repos/%s/%s/actions/runs/%d/cancel", url.PathEscape(owner), url.PathEscape(repo), int64(runID)),
},
@@ -359,18 +360,18 @@ func RerunRepoActionRunFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca
log.Debugf("Called RerunRepoActionRunFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
runID, ok := req.GetArguments()["run_id"].(float64)
if !ok || runID <= 0 {
return to.ErrorResult(fmt.Errorf("run_id is required"))
return to.ErrorResult(errors.New("run_id is required"))
}
_, _, err := doJSONWithFallback(ctx, "POST",
err := doJSONWithFallback(ctx, "POST",
[]string{
fmt.Sprintf("repos/%s/%s/actions/runs/%d/rerun", url.PathEscape(owner), url.PathEscape(repo), int64(runID)),
fmt.Sprintf("repos/%s/%s/actions/runs/%d/rerun-failed-jobs", url.PathEscape(owner), url.PathEscape(repo), int64(runID)),
@@ -379,7 +380,7 @@ func RerunRepoActionRunFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca
)
if err != nil {
var httpErr *gitea.HTTPError
if errors.As(err, &httpErr) && (httpErr.StatusCode == 404 || httpErr.StatusCode == 405) {
if errors.As(err, &httpErr) && (httpErr.StatusCode == http.StatusNotFound || httpErr.StatusCode == http.StatusMethodNotAllowed) {
return to.ErrorResult(fmt.Errorf("workflow rerun not supported on this Gitea version (endpoint returned %d). Check https://docs.gitea.com/api/1.24/ for available Actions endpoints", httpErr.StatusCode))
}
return to.ErrorResult(fmt.Errorf("rerun action run err: %v", err))
@@ -391,11 +392,11 @@ func ListRepoActionJobsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca
log.Debugf("Called ListRepoActionJobsFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -408,14 +409,14 @@ func ListRepoActionJobsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca
statusFilter, _ := req.GetArguments()["status"].(string)
query := url.Values{}
query.Set("page", fmt.Sprintf("%d", int(page)))
query.Set("limit", fmt.Sprintf("%d", int(pageSize)))
query.Set("page", strconv.Itoa(int(page)))
query.Set("limit", strconv.Itoa(int(pageSize)))
if statusFilter != "" {
query.Set("status", statusFilter)
}
var result any
_, _, err := doJSONWithFallback(ctx, "GET",
err := doJSONWithFallback(ctx, "GET",
[]string{
fmt.Sprintf("repos/%s/%s/actions/jobs", url.PathEscape(owner), url.PathEscape(repo)),
},
@@ -431,15 +432,15 @@ func ListRepoActionRunJobsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
log.Debugf("Called ListRepoActionRunJobsFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
runID, ok := req.GetArguments()["run_id"].(float64)
if !ok || runID <= 0 {
return to.ErrorResult(fmt.Errorf("run_id is required"))
return to.ErrorResult(errors.New("run_id is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -451,11 +452,11 @@ func ListRepoActionRunJobsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
}
query := url.Values{}
query.Set("page", fmt.Sprintf("%d", int(page)))
query.Set("limit", fmt.Sprintf("%d", int(pageSize)))
query.Set("page", strconv.Itoa(int(page)))
query.Set("limit", strconv.Itoa(int(pageSize)))
var result any
_, _, err := doJSONWithFallback(ctx, "GET",
err := doJSONWithFallback(ctx, "GET",
[]string{
fmt.Sprintf("repos/%s/%s/actions/runs/%d/jobs", url.PathEscape(owner), url.PathEscape(repo), int64(runID)),
},

View File

@@ -2,6 +2,7 @@ package actions
import (
"context"
"errors"
"fmt"
"net/url"
"time"
@@ -27,7 +28,7 @@ const (
type secretMeta struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
CreatedAt time.Time `json:"created_at,omitzero"`
}
var (
@@ -97,11 +98,11 @@ func ListRepoActionSecretsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
log.Debugf("Called ListRepoActionSecretsFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -142,19 +143,19 @@ func UpsertRepoActionSecretFn(ctx context.Context, req mcp.CallToolRequest) (*mc
log.Debugf("Called UpsertRepoActionSecretFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
data, ok := req.GetArguments()["data"].(string)
if !ok || data == "" {
return to.ErrorResult(fmt.Errorf("data is required"))
return to.ErrorResult(errors.New("data is required"))
}
description, _ := req.GetArguments()["description"].(string)
@@ -177,15 +178,15 @@ func DeleteRepoActionSecretFn(ctx context.Context, req mcp.CallToolRequest) (*mc
log.Debugf("Called DeleteRepoActionSecretFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
secretName, ok := req.GetArguments()["secretName"].(string)
if !ok || secretName == "" {
return to.ErrorResult(fmt.Errorf("secretName is required"))
return to.ErrorResult(errors.New("secretName is required"))
}
client, err := gitea.ClientFromContext(ctx)
@@ -203,7 +204,7 @@ func ListOrgActionSecretsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.
log.Debugf("Called ListOrgActionSecretsFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -244,15 +245,15 @@ func UpsertOrgActionSecretFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
log.Debugf("Called UpsertOrgActionSecretFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
data, ok := req.GetArguments()["data"].(string)
if !ok || data == "" {
return to.ErrorResult(fmt.Errorf("data is required"))
return to.ErrorResult(errors.New("data is required"))
}
description, _ := req.GetArguments()["description"].(string)
@@ -275,11 +276,11 @@ func DeleteOrgActionSecretFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
log.Debugf("Called DeleteOrgActionSecretFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
secretName, ok := req.GetArguments()["secretName"].(string)
if !ok || secretName == "" {
return to.ErrorResult(fmt.Errorf("secretName is required"))
return to.ErrorResult(errors.New("secretName is required"))
}
escapedOrg := url.PathEscape(org)

View File

@@ -2,8 +2,10 @@ package actions
import (
"context"
"errors"
"fmt"
"net/url"
"strconv"
"gitea.com/gitea/gitea-mcp/pkg/gitea"
"gitea.com/gitea/gitea-mcp/pkg/log"
@@ -21,11 +23,11 @@ const (
UpdateRepoActionVariableToolName = "update_repo_action_variable"
DeleteRepoActionVariableToolName = "delete_repo_action_variable"
ListOrgActionVariablesToolName = "list_org_action_variables"
GetOrgActionVariableToolName = "get_org_action_variable"
CreateOrgActionVariableToolName = "create_org_action_variable"
UpdateOrgActionVariableToolName = "update_org_action_variable"
DeleteOrgActionVariableToolName = "delete_org_action_variable"
ListOrgActionVariablesToolName = "list_org_action_variables"
GetOrgActionVariableToolName = "get_org_action_variable"
CreateOrgActionVariableToolName = "create_org_action_variable"
UpdateOrgActionVariableToolName = "update_org_action_variable"
DeleteOrgActionVariableToolName = "delete_org_action_variable"
)
var (
@@ -131,11 +133,11 @@ func ListRepoActionVariablesFn(ctx context.Context, req mcp.CallToolRequest) (*m
log.Debugf("Called ListRepoActionVariablesFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -147,8 +149,8 @@ func ListRepoActionVariablesFn(ctx context.Context, req mcp.CallToolRequest) (*m
}
query := url.Values{}
query.Set("page", fmt.Sprintf("%d", int(page)))
query.Set("limit", fmt.Sprintf("%d", int(pageSize)))
query.Set("page", strconv.Itoa(int(page)))
query.Set("limit", strconv.Itoa(int(pageSize)))
var result any
_, err := gitea.DoJSON(ctx, "GET", fmt.Sprintf("repos/%s/%s/actions/variables", url.PathEscape(owner), url.PathEscape(repo)), query, nil, &result)
@@ -162,15 +164,15 @@ func GetRepoActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
log.Debugf("Called GetRepoActionVariableFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
client, err := gitea.ClientFromContext(ctx)
@@ -188,19 +190,19 @@ func CreateRepoActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*
log.Debugf("Called CreateRepoActionVariableFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
value, ok := req.GetArguments()["value"].(string)
if !ok || value == "" {
return to.ErrorResult(fmt.Errorf("value is required"))
return to.ErrorResult(errors.New("value is required"))
}
client, err := gitea.ClientFromContext(ctx)
@@ -218,19 +220,19 @@ func UpdateRepoActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*
log.Debugf("Called UpdateRepoActionVariableFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
value, ok := req.GetArguments()["value"].(string)
if !ok || value == "" {
return to.ErrorResult(fmt.Errorf("value is required"))
return to.ErrorResult(errors.New("value is required"))
}
client, err := gitea.ClientFromContext(ctx)
@@ -248,15 +250,15 @@ func DeleteRepoActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*
log.Debugf("Called DeleteRepoActionVariableFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok || owner == "" {
return to.ErrorResult(fmt.Errorf("owner is required"))
return to.ErrorResult(errors.New("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok || repo == "" {
return to.ErrorResult(fmt.Errorf("repo is required"))
return to.ErrorResult(errors.New("repo is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
client, err := gitea.ClientFromContext(ctx)
@@ -274,7 +276,7 @@ func ListOrgActionVariablesFn(ctx context.Context, req mcp.CallToolRequest) (*mc
log.Debugf("Called ListOrgActionVariablesFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
page, _ := req.GetArguments()["page"].(float64)
if page <= 0 {
@@ -302,11 +304,11 @@ func GetOrgActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.
log.Debugf("Called GetOrgActionVariableFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
client, err := gitea.ClientFromContext(ctx)
@@ -324,15 +326,15 @@ func CreateOrgActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*m
log.Debugf("Called CreateOrgActionVariableFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
value, ok := req.GetArguments()["value"].(string)
if !ok || value == "" {
return to.ErrorResult(fmt.Errorf("value is required"))
return to.ErrorResult(errors.New("value is required"))
}
description, _ := req.GetArguments()["description"].(string)
@@ -355,15 +357,15 @@ func UpdateOrgActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*m
log.Debugf("Called UpdateOrgActionVariableFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
value, ok := req.GetArguments()["value"].(string)
if !ok || value == "" {
return to.ErrorResult(fmt.Errorf("value is required"))
return to.ErrorResult(errors.New("value is required"))
}
description, _ := req.GetArguments()["description"].(string)
@@ -385,11 +387,11 @@ func DeleteOrgActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*m
log.Debugf("Called DeleteOrgActionVariableFn")
org, ok := req.GetArguments()["org"].(string)
if !ok || org == "" {
return to.ErrorResult(fmt.Errorf("org is required"))
return to.ErrorResult(errors.New("org is required"))
}
name, ok := req.GetArguments()["name"].(string)
if !ok || name == "" {
return to.ErrorResult(fmt.Errorf("name is required"))
return to.ErrorResult(errors.New("name is required"))
}
_, err := gitea.DoJSON(ctx, "DELETE", fmt.Sprintf("orgs/%s/actions/variables/%s", url.PathEscape(org), url.PathEscape(name)), nil, nil, nil)
@@ -398,5 +400,3 @@ func DeleteOrgActionVariableFn(ctx context.Context, req mcp.CallToolRequest) (*m
}
return to.TextResult(map[string]any{"message": "variable deleted"})
}