Documentation
¶
Overview ¶
Package github provides GitHub API integration.
Index ¶
- Constants
- func AuthMethod() string
- func GetToken() (string, error)
- func GetTokenFromEnv() string
- func GetTokenFromGHCLI() (string, error)
- func IsGHCLIAvailable() bool
- func IsGHCLIInstalled() bool
- func IsNotFoundError(err error) bool
- func SortByStars(results []SearchResult)
- type Client
- func (c *Client) FetchFile(ctx context.Context, owner, repo, path, branch string) (*FetchResult, error)
- func (c *Client) FileExists(ctx context.Context, owner, repo, path, branch string) (bool, error)
- func (c *Client) GetDefaultBranch(ctx context.Context, owner, repo string) (string, error)
- func (c *Client) ListDirectory(ctx context.Context, owner, repo, path, branch string) ([]DirectoryEntry, error)
- func (c *Client) RepoExists(ctx context.Context, owner, repo string) (bool, error)
- func (c *Client) SearchByTopic(ctx context.Context, topic string, query string) ([]SearchResult, error)
- func (c *Client) SearchConfigs(ctx context.Context, query string) ([]SearchResult, error)
- type DirectoryEntry
- type FetchResult
- type SearchResult
Constants ¶
const (
// EnvGitHubToken is the environment variable for fallback token auth.
EnvGitHubToken = "STAGHORN_GITHUB_TOKEN"
)
Variables ¶
This section is empty.
Functions ¶
func AuthMethod ¶
func AuthMethod() string
AuthMethod returns a string describing the current auth method.
func GetToken ¶
GetToken resolves a GitHub token using the auth chain. Priority: 1) gh auth token, 2) STAGHORN_GITHUB_TOKEN env
func GetTokenFromGHCLI ¶
GetTokenFromGHCLI executes `gh auth token` to get token.
func IsGHCLIAvailable ¶
func IsGHCLIAvailable() bool
IsGHCLIAvailable checks if the gh CLI is installed and authenticated.
func IsGHCLIInstalled ¶
func IsGHCLIInstalled() bool
IsGHCLIInstalled checks if the gh CLI binary is installed (but not necessarily authenticated).
func IsNotFoundError ¶ added in v0.8.0
IsNotFoundError returns true if the error is a 404 Not Found from the GitHub API.
func SortByStars ¶ added in v0.3.0
func SortByStars(results []SearchResult)
SortByStars sorts results by star count (descending).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub API for staghorn's needs.
func NewClientWithToken ¶
NewClientWithToken creates a GitHub client with explicit token.
func NewUnauthenticatedClient ¶ added in v0.3.0
NewUnauthenticatedClient creates a GitHub client without authentication. This works for public repositories only and has lower rate limits (60/hour). Use this when accessing public configs without requiring user auth.
func (*Client) FetchFile ¶
func (c *Client) FetchFile(ctx context.Context, owner, repo, path, branch string) (*FetchResult, error)
FetchFile fetches a file from a repo. The context is used for request cancellation and timeouts.
func (*Client) FileExists ¶
FileExists checks if a file exists in a repo. The context is used for request cancellation and timeouts.
func (*Client) GetDefaultBranch ¶
GetDefaultBranch returns the repo's default branch. The context is used for request cancellation and timeouts.
func (*Client) ListDirectory ¶
func (c *Client) ListDirectory(ctx context.Context, owner, repo, path, branch string) ([]DirectoryEntry, error)
ListDirectory lists contents of a directory in a repo. Returns nil, nil if the directory doesn't exist. The context is used for request cancellation and timeouts.
func (*Client) RepoExists ¶
RepoExists checks if a repository exists and is accessible. The context is used for request cancellation and timeouts.
func (*Client) SearchByTopic ¶ added in v0.3.0
func (c *Client) SearchByTopic(ctx context.Context, topic string, query string) ([]SearchResult, error)
SearchByTopic searches for repositories with a specific topic. This is used to discover public staghorn configs tagged with "staghorn-config".
func (*Client) SearchConfigs ¶ added in v0.3.0
SearchConfigs searches for staghorn config repositories. It searches for repos with the "staghorn-config" topic and optionally filters by query.
type DirectoryEntry ¶
type DirectoryEntry struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // "file" or "dir"
SHA string `json:"sha"`
}
DirectoryEntry represents an item in a directory listing.
type FetchResult ¶
type FetchResult struct {
Content string
ETag string
SHA string
NotModified bool // True if server returned 304
}
FetchResult contains the result of a fetch operation.
type SearchResult ¶ added in v0.3.0
type SearchResult struct {
Owner string
Repo string
Description string
Stars int
Topics []string
URL string
}
SearchResult represents a repository found via search.
func FilterByLanguage ¶ added in v0.3.0
func FilterByLanguage(results []SearchResult, lang string) []SearchResult
FilterByLanguage filters search results to only those supporting a specific language. Languages are determined by the repo's topics (e.g., "python", "typescript"). Common aliases are normalized (e.g., "golang" -> "go", "py" -> "python").
func FilterByTag ¶ added in v0.3.0
func FilterByTag(results []SearchResult, tag string) []SearchResult
FilterByTag filters search results to only those with a specific tag/topic.
func (*SearchResult) FullName ¶ added in v0.3.0
func (r *SearchResult) FullName() string
FullName returns the owner/repo string.