github

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 10 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).

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 (*Client) FetchFile

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

FetchFile fetches a file from a repo. If etag is provided and content hasn't changed, returns NotModified=true.

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.

func (*Client) GetDefaultBranch

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

GetDefaultBranch returns the repo's default branch.

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.

func (*Client) RepoExists

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

RepoExists checks if a repository exists and is accessible.

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.

Jump to

Keyboard shortcuts

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