codesearch

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package codesearch searches code on GitHub and GitLab. GitHub token (GITHUB_PERSONAL_ACCESS_TOKEN) is optional; GitLab requires GITLAB_TOKEN.

Index

Constants

This section is empty.

Variables

View Source
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 GitLabAPIBase

func GitLabAPIBase() string

GitLabAPIBase returns the GitLab API v4 base URL.

func GitLabToken

func GitLabToken() string

GitLabToken returns the first configured GitLab token from the environment.

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 Available

func Available() []ProviderID

Available returns providers that CodeSearch may use.

func NormalizeProvider

func NormalizeProvider(raw string) (ProviderID, bool)

NormalizeProvider maps aliases to canonical provider ids.

type Result

type Result struct {
	Repository string
	Path       string
	URL        string
	Snippet    string
}

Result is a normalized code search hit.

func SearchGitHubAt

func SearchGitHubAt(ctx context.Context, client *resty.Client, endpoint, query, token string) ([]Result, error)

SearchGitHubAt calls a GitHub code search endpoint (for tests in other packages).

func SearchGitLabAt

func SearchGitLabAt(ctx context.Context, client *resty.Client, endpoint, query, token string) ([]Result, error)

SearchGitLabAt calls a GitLab code search endpoint (for tests in other packages).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL