github

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package github provides a client for the GitHub Contents API. It fetches file contents and directory listings from repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRateLimitError added in v1.2.0

func IsRateLimitError(err error) bool

IsRateLimitError reports whether err is a GitHub API rate-limit error.

Types

type Client

type Client struct {
	BaseURL    string       // defaults to "https://api.github.com"
	Token      string       // optional bearer token
	HTTPClient *http.Client // optional; falls back to http.DefaultClient
}

Client accesses the GitHub Contents API.

func (*Client) FetchDir

func (c *Client) FetchDir(ctx context.Context, owner, repo, ref, path string) ([]ContentEntry, error)

FetchDir lists the contents of a directory in a GitHub repository.

func (*Client) FetchDirRecursive added in v1.1.0

func (c *Client) FetchDirRecursive(ctx context.Context, owner, repo, ref, root string) ([]ContentEntry, error)

FetchDirRecursive lists all files under root recursively using BFS. Directories are not included in the results. The initial call to root propagates errors; errors on individual subdirectories are silently skipped. Pass root="" to start from the repository root.

func (*Client) FetchFile

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

FetchFile downloads the raw content of a file from a GitHub repository.

func (*Client) FetchZipAndExtract added in v1.2.0

func (c *Client) FetchZipAndExtract(ctx context.Context, owner, repo, ref, targetDir string) error

FetchZipAndExtract downloads the repository as a ZIP archive and extracts all files into targetDir, preserving the directory tree but stripping the top-level "{repo}-{sha}/" prefix that GitHub adds inside the archive.

It uses the GitHub zipball API endpoint which supports both authenticated and unauthenticated (public repos) requests. For public repos this bypasses the 60 req/hr Contents API rate limit — the zipball is served from codeload.github.com.

ref may be a branch, tag, or commit SHA; an empty ref uses the default branch.

type ContentEntry

type ContentEntry struct {
	Name string `json:"name"`
	Path string `json:"path"`
	Type string `json:"type"` // "file" or "dir"
}

ContentEntry represents a file or directory in a GitHub repository listing.

Jump to

Keyboard shortcuts

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