Documentation
¶
Overview ¶
Package remote provides interfaces for fetching dependency manifest files from remote repositories.
Index ¶
- Constants
- Variables
- func ValidateContentSize(size int, path string) error
- func ValidatePath(path string) error
- type GitHubFetcher
- func (g *GitHubFetcher) GetFile(ctx context.Context, repo RepositoryRef, path string) (*RemoteFile, error)
- func (g *GitHubFetcher) ListFilePaths(ctx context.Context, repo RepositoryRef) ([]string, error)
- func (g *GitHubFetcher) SearchFiles(ctx context.Context, repo RepositoryRef, patterns []string) ([]RemoteFile, error)
- type GitHubSearcher
- type RemoteFetcher
- type RemoteFile
- type RepositoryRef
Constants ¶
const ( // MaxFileSize is the maximum allowed file size in bytes (10 MB). MaxFileSize = 10 * 1024 * 1024 // MaxPathLength is the maximum allowed path length. MaxPathLength = 4096 // MaxRefLength is the maximum allowed git reference length. MaxRefLength = 256 // MaxOwnerLength is the maximum allowed owner/org name length. MaxOwnerLength = 256 // MaxRepoLength is the maximum allowed repository name length. MaxRepoLength = 256 // MaxHostLength is the maximum allowed DNS hostname length. MaxHostLength = 253 )
Variables ¶
var ( // ErrRepositoryRefNil is returned when a repository reference is nil. ErrRepositoryRefNil = errors.New("repository reference cannot be nil") // ErrEmptyField is returned when a required field is empty. ErrEmptyField = errors.New("field cannot be empty") // ErrFieldTooLong is returned when a field exceeds maximum length. ErrFieldTooLong = errors.New("field exceeds maximum length") // ErrInvalidCharacters is returned when a field contains invalid characters. ErrInvalidCharacters = errors.New("contains invalid characters") // ErrCommandInjection is returned when a value could enable command injection. ErrCommandInjection = errors.New("potential command injection") // ErrPathTraversal is returned when a path contains traversal attempts. ErrPathTraversal = errors.New("path traversal attempt") // ErrAbsolutePath is returned when a path is absolute instead of relative. ErrAbsolutePath = errors.New("path must be relative, not absolute") // ErrNegativeSize is returned when content size is negative. ErrNegativeSize = errors.New("content size cannot be negative") // ErrFileTooLarge is returned when a file exceeds size limits. ErrFileTooLarge = errors.New("file size exceeds maximum") // ErrSearchOperatorInjection is returned when a pattern contains GitHub search operators. ErrSearchOperatorInjection = errors.New("pattern cannot contain GitHub search operator") // ErrPatternContainsPath is returned when a pattern contains path separators. ErrPatternContainsPath = errors.New("pattern cannot contain path separators") )
Functions ¶
func ValidateContentSize ¶
ValidateContentSize validates that content size is within acceptable limits.
func ValidatePath ¶
ValidatePath validates a file path to prevent path traversal attacks.
Types ¶
type GitHubFetcher ¶
type GitHubFetcher struct {
// contains filtered or unexported fields
}
GitHubFetcher implements RemoteFetcher using the GitHub API.
func NewGitHubFetcher ¶
func NewGitHubFetcher(client GitHubSearcher) *GitHubFetcher
NewGitHubFetcher creates a new GitHub-based remote fetcher.
func (*GitHubFetcher) GetFile ¶
func (g *GitHubFetcher) GetFile(ctx context.Context, repo RepositoryRef, path string) (*RemoteFile, error)
GetFile fetches a specific file from a repository. Implements RemoteFetcher.GetFile.
func (*GitHubFetcher) ListFilePaths ¶ added in v0.14.4
func (g *GitHubFetcher) ListFilePaths(ctx context.Context, repo RepositoryRef) ([]string, error)
ListFilePaths returns all file paths in a repository at the given ref using the Git Tree API (one request, not subject to Code Search rate limits). Useful for language detection before calling SearchFiles.
func (*GitHubFetcher) SearchFiles ¶
func (g *GitHubFetcher) SearchFiles(ctx context.Context, repo RepositoryRef, patterns []string) ([]RemoteFile, error)
SearchFiles searches for files matching the given patterns in a repository. Implements RemoteFetcher.SearchFiles.
Files are discovered by listing the full tree at the requested ref via the Git Tree API rather than GitHub Code Search: Code Search only indexes the default branch (returning paths that may not exist at the ref) and caps results at 100 per query.
type GitHubSearcher ¶
type GitHubSearcher interface {
// GetFileContent fetches the content of a file at a specific ref.
GetFileContent(ctx context.Context, owner, repo, path, ref string) ([]byte, error)
// ListFilePaths returns all file paths in a repository at the given ref using
// the Git Tree API (one request, not subject to Code Search rate limits).
// Useful for language detection before calling SearchFiles.
ListFilePaths(ctx context.Context, owner, repo, ref string) ([]string, error)
}
GitHubSearcher defines the minimal interface needed to search and fetch files from GitHub. This allows omnibump to work with different GitHub client implementations.
type RemoteFetcher ¶
type RemoteFetcher interface {
// SearchFiles searches for files matching the given patterns in a repository.
// Recursively searches the entire repository tree.
// patterns is a list of filename patterns to search for (e.g., ["go.mod", "pom.xml"])
// Returns a list of ALL found files with their paths and content.
// For multi-module repos, this will return multiple files (e.g., go.mod, api/go.mod, server/go.mod).
SearchFiles(ctx context.Context, repo RepositoryRef, patterns []string) ([]RemoteFile, error)
// GetFile fetches a specific file from a repository.
GetFile(ctx context.Context, repo RepositoryRef, path string) (*RemoteFile, error)
}
RemoteFetcher defines the interface for fetching files from remote repositories. Implementations can support different providers (GitHub, GitLab, Gitea, etc.)
type RemoteFile ¶
type RemoteFile struct {
// Path is the file path relative to repository root
// Examples: "go.mod", "api/go.mod", "pkg/server/go.mod"
Path string
// Content is the file content as bytes
Content []byte
// Metadata stores additional information about the file
Metadata map[string]string
}
RemoteFile represents a file fetched from a remote repository.
type RepositoryRef ¶
type RepositoryRef struct {
// Host is the git host (e.g., "github.com", "gitlab.com")
Host string
// Owner is the repository owner/organization
Owner string
// Repo is the repository name
Repo string
// Ref is the git reference (tag, branch, or commit SHA)
Ref string
}
RepositoryRef identifies a remote repository and ref (tag/branch/commit).
func (*RepositoryRef) Validate ¶
func (r *RepositoryRef) Validate() error
Validate validates all fields of a RepositoryRef.