Documentation
¶
Overview ¶
Package codesearch searches code on GitHub and GitLab. GitHub token (GITHUB_PERSONAL_ACCESS_TOKEN) is optional; GitLab requires GITLAB_TOKEN.
Index ¶
- Variables
- func Format(providers []ProviderID, query string, results []Result) string
- func GitHubRESTBase() string
- func GitHubToken() string
- func GitLabAPIBase() string
- func GitLabToken() string
- func Search(ctx context.Context, query, provider string) (used []ProviderID, results []Result, err error)
- func SetSearchFuncsForTest(gh githubSearchFunc, gl gitlabSearchFunc) func()
- type ProviderID
- type Result
Constants ¶
This section is empty.
Variables ¶
var HTTPClient = resty.New(). SetTimeout(20 * time.Second). SetRetryCount(2). SetRetryWaitTime(1 * time.Second). SetRetryMaxWaitTime(5 * time.Second). AddRetryConditions( func(r *resty.Response, err error) bool { if err != nil { return true } return r.StatusCode() >= 500 }, )
HTTPClient is used for outbound API requests. Tests may replace it.
Functions ¶
func Format ¶
func Format(providers []ProviderID, query string, results []Result) string
Format renders code search output for the CodeSearch tool.
func GitHubRESTBase ¶
func GitHubRESTBase() string
GitHubRESTBase returns the GitHub REST API root URL (with trailing slash). Follows github-mcp-server host rules: GITHUB_HOST for GHES / GHEC, default api.github.com.
func GitHubToken ¶
func GitHubToken() string
GitHubToken returns an optional GitHub token from the environment. Aligns with github-mcp-server (GITHUB_PERSONAL_ACCESS_TOKEN) plus common aliases.
func GitLabToken ¶
func GitLabToken() string
GitLabToken returns the first configured GitLab token from the environment.
func Search ¶
func Search(ctx context.Context, query, provider string) (used []ProviderID, results []Result, err error)
Search runs a code query across configured providers.
func SetSearchFuncsForTest ¶
func SetSearchFuncsForTest(gh githubSearchFunc, gl gitlabSearchFunc) func()
SetSearchFuncsForTest replaces provider search functions for the duration of a test.
Types ¶
type ProviderID ¶
type ProviderID string
ProviderID identifies a code search backend.
const ( ProviderGitHub ProviderID = "github" ProviderGitLab ProviderID = "gitlab" )
func NormalizeProvider ¶
func NormalizeProvider(raw string) (ProviderID, bool)
NormalizeProvider maps aliases to canonical provider ids.