github

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package github reads repository contents from the GitHub API.

It covers what a generator needs to track a file published upstream: find the commit that last touched it, list the tree at that commit, and fetch a file or the whole repository at it. Going through the API rather than cloning keeps the fetch to what is wanted, and yields a commit SHA to record alongside whatever was generated so a result can be traced back to what produced it.

Index

Constants

View Source
const (
	DefaultHost        = "api.github.com"
	DefaultArchiveHost = "github.com"
)

Variables

View Source
var ErrUnexpectedCommitCount = errors.New("unexpected number of commits")

ErrUnexpectedCommitCount reports an answer that does not name exactly the one commit that was asked for.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(options ...github_config.Option) *Client

func (*Client) Blob

func (c *Client) Blob(
	ctx context.Context,
	owner string,
	repo string,
	fileSha string,
	options ...fetch_config.Option,
) (*blob.Blob, error)

Blob returns a file's contents.

func (*Client) CommitArchive

func (c *Client) CommitArchive(
	ctx context.Context,
	owner string,
	repo string,
	reference string,
	options ...fetch_config.Option,
) (*zip.Reader, error)

CommitArchive returns the repository at a revision, as an archive.

func (*Client) LatestCommit

func (c *Client) LatestCommit(
	ctx context.Context,
	owner string,
	repo string,
	path string,
	options ...fetch_config.Option,
) (*commit.Commit, error)

LatestCommit returns the commit that last touched path.

Asking for the commit behind a single path, rather than the head of the branch, is what makes a generated file's provenance meaningful: the SHA names the revision that last changed the thing it was generated from.

func (*Client) Tree

func (c *Client) Tree(
	ctx context.Context,
	owner string,
	repo string,
	treeSha string,
	options ...fetch_config.Option,
) (*tree.Tree, error)

Tree returns the repository listing a tree sha names.

Directories

Path Synopsis
types
blob
Package blob holds a file's contents as the GitHub API reports them.
Package blob holds a file's contents as the GitHub API reports them.
commit
Package commit holds a commit as the GitHub API reports one.
Package commit holds a commit as the GitHub API reports one.
tree
Package tree holds a repository listing as the GitHub API reports one.
Package tree holds a repository listing as the GitHub API reports one.

Jump to

Keyboard shortcuts

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