github

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package github provides HTTP client functionality for the GitHub API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchFileTree

func FetchFileTree(ctx context.Context, client *Client, owner, repo, branch string) string

FetchFileTree fetches the git tree for the given repo and branch. Returns only blob entries at depth <= 2 (paths with at most one '/'), sorted alphabetically, joined by newlines. Returns "" on any error — never returns an error.

func FetchOwnedRepos

func FetchOwnedRepos(ctx context.Context, client *Client) (<-chan Repo, <-chan error)

FetchOwnedRepos returns a channel that yields owned repos one at a time. Pagination is handled internally. The channel is closed when all pages are exhausted or an error occurs. Errors are sent on the errCh channel.

func FetchReadme

func FetchReadme(ctx context.Context, client *Client, owner, repo string) string

FetchReadme fetches and base64-decodes the README for the given repo. Returns ("", nil) if the repo has no README (404). Never returns an error — logs and returns empty string on any failure.

func FetchStarredRepos

func FetchStarredRepos(ctx context.Context, client *Client) (<-chan Repo, <-chan error)

FetchStarredRepos returns a channel that yields starred repos one at a time.

func ResetDefaultBaseURL

func ResetDefaultBaseURL()

ResetDefaultBaseURL resets the default base URL to the original value.

func SetDefaultBaseURL

func SetDefaultBaseURL(url string)

SetDefaultBaseURL sets the default base URL for new clients (for testing).

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client for the GitHub API.

func NewClient

func NewClient(pat string) *Client

NewClient creates a new GitHub API client with the given PAT.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do executes an HTTP request with the GitHub PAT auth header, User-Agent, and Accept headers set. On 429 or 403 with x-ratelimit-remaining=0, waits until x-ratelimit-reset and retries once. Returns RateLimitError if the retry also fails.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

Get is a convenience wrapper around Do for GET requests.

type Owner

type Owner struct {
	Login string `json:"login"`
	ID    int64  `json:"id"`
}

Owner represents a GitHub repository owner.

type PATValidationResult

type PATValidationResult struct {
	Valid  bool
	Login  string
	Scopes []string
	Error  string
}

PATValidationResult contains the result of validating a GitHub PAT.

func ValidatePAT

func ValidatePAT(ctx context.Context, client *Client) PATValidationResult

ValidatePAT calls GET /user and checks the x-oauth-scopes header. Returns a result even on failure — never returns an error directly.

type RateLimitError

type RateLimitError struct {
	ResetAt time.Time
}

RateLimitError is returned when the GitHub API rate limit is exceeded and the retry also failed.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RateLimitInfo

type RateLimitInfo struct {
	Limit     int
	Remaining int
	ResetAt   string // ISO datetime string
	Available bool
}

RateLimitInfo contains GitHub API rate limit information.

func GetRateLimitInfo

func GetRateLimitInfo(ctx context.Context, client *Client) *RateLimitInfo

GetRateLimitInfo fetches the current rate limit status. Returns nil on any error.

type Repo

type Repo struct {
	ID              int64    `json:"id"`
	NodeID          string   `json:"node_id"`
	Name            string   `json:"name"`
	FullName        string   `json:"full_name"`
	Description     *string  `json:"description"`
	Private         bool     `json:"private"`
	Owner           Owner    `json:"owner"`
	HTMLURL         string   `json:"html_url"`
	CloneURL        string   `json:"clone_url"`
	Language        *string  `json:"language"`
	StargazersCount int      `json:"stargazers_count"`
	ForksCount      int      `json:"forks_count"`
	DefaultBranch   string   `json:"default_branch"`
	Topics          []string `json:"topics"`
	PushedAt        string   `json:"pushed_at"`
	CreatedAt       string   `json:"created_at"`
	UpdatedAt       string   `json:"updated_at"`
	Archived        bool     `json:"archived"`
	Fork            bool     `json:"fork"`
	Size            int      `json:"size"`
}

Repo represents a GitHub repository from the API.

Jump to

Keyboard shortcuts

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