github

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package github provides GitHub API integration.

Index

Constants

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

func GetToken() (string, error)

GetToken resolves a GitHub token using the auth chain. Priority: 1) gh auth token, 2) STAGHORN_GITHUB_TOKEN env

func GetTokenFromEnv

func GetTokenFromEnv() string

GetTokenFromEnv reads STAGHORN_GITHUB_TOKEN.

func GetTokenFromGHCLI

func GetTokenFromGHCLI() (string, error)

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

func IsNotFoundError(err error) bool

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 NewClient

func NewClient() (*Client, error)

NewClient creates a GitHub client using go-gh (automatic auth).

func NewClientWithToken

func NewClientWithToken(token string) (*Client, error)

NewClientWithToken creates a GitHub client with explicit token.

func NewUnauthenticatedClient added in v0.3.0

func NewUnauthenticatedClient() (*Client, error)

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

func (c *Client) FileExists(ctx context.Context, owner, repo, path, branch string) (bool, error)

FileExists checks if a file exists in a repo. The context is used for request cancellation and timeouts.

func (*Client) GetDefaultBranch

func (c *Client) GetDefaultBranch(ctx context.Context, owner, repo string) (string, error)

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

func (c *Client) RepoExists(ctx context.Context, owner, repo string) (bool, error)

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

func (c *Client) SearchConfigs(ctx context.Context, query string) ([]SearchResult, error)

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.

Jump to

Keyboard shortcuts

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