mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-02-27 09:05:12 +00:00
## 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>
31 lines
758 B
Go
31 lines
758 B
Go
package gitea
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
mcpContext "gitea.com/gitea/gitea-mcp/pkg/context"
|
|
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
|
)
|
|
|
|
func TestTokenFromContext(t *testing.T) {
|
|
orig := flag.Token
|
|
defer func() { flag.Token = orig }()
|
|
|
|
flag.Token = "flag-token"
|
|
|
|
t.Run("context token wins", func(t *testing.T) {
|
|
ctx := context.WithValue(context.Background(), mcpContext.TokenContextKey, "ctx-token")
|
|
if got := tokenFromContext(ctx); got != "ctx-token" {
|
|
t.Fatalf("tokenFromContext() = %q, want %q", got, "ctx-token")
|
|
}
|
|
})
|
|
|
|
t.Run("fallback to flag token", func(t *testing.T) {
|
|
ctx := context.Background()
|
|
if got := tokenFromContext(ctx); got != "flag-token" {
|
|
t.Fatalf("tokenFromContext() = %q, want %q", got, "flag-token")
|
|
}
|
|
})
|
|
}
|