github

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package github answers the cleanup engine's forge questions against the GitHub REST API: whether a project exists, its default branch, which pull requests contain a commit, and whether one commit contains another.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KnownHosts

func KnownHosts() []string

KnownHosts returns the hosts gh is configured for: GH_HOST, github.com when the environment holds a token for it, and every host in gh's config.

Types

type Client

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

Client queries the GitHub REST API on github.com and the hosts gh is configured for. It is safe for concurrent use.

func New

func New(opts Options) *Client

New returns a Client configured by opts.

func (*Client) Changes

func (c *Client) Changes(ctx context.Context, p forge.Project, sha string) ([]forge.Change, error)

Changes returns the pull requests in p that contain commit sha, as GitHub lists them for the commit. That list omits pull requests closed without merging, which ClosedChanges finds. An error wrapping forge.ErrCommitUnknown means p does not hold sha.

func (*Client) ClosedChanges added in v0.2.0

func (c *Client) ClosedChanges(ctx context.Context, projects []forge.Project, sha string) (map[forge.Project][]forge.Change, error)

ClosedChanges returns, by project, the pull requests in projects that contain commit sha as GitHub's search API finds them, among them the ones closed without merging that Changes omits. A project with none is absent from the result.

The projects on one host are searched together, in as few queries as GitHub's query length allows, each paced process-wide to stay inside the search API's per-user rate limit.

func (*Client) Contains

func (c *Client) Contains(ctx context.Context, p forge.Project, ancestor, descendant string) (bool, error)

Contains reports whether descendant includes ancestor in its history in p; two commits with no common ancestor answer false. An error wrapping forge.ErrCommitUnknown means p does not hold one of the two. GitHub answers a missing project with a 404 too, so the caller establishes p exists with Exists first.

func (*Client) DefaultBranch

func (c *Client) DefaultBranch(ctx context.Context, p forge.Project) (string, error)

DefaultBranch returns p's default branch, from the same cached lookup as Exists.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, p forge.Project) error

Exists returns nil when p exists and the credentials in use can see it, and an error wrapping forge.ErrProjectNotFound when GitHub answers 404.

type Options

type Options struct {
	// Transport, when set, carries every request in place of the default
	// transport.
	Transport http.RoundTripper
	// AuthToken, when set, authenticates every host in place of go-gh's
	// per-host token lookup.
	AuthToken string
}

Options configures a Client. Production passes the zero value, and go-gh's auth package resolves each host's token from the environment, gh's config, or the keyring. Whatever the options, a Client only talks to github.com and the hosts KnownHosts lists.

Jump to

Keyboard shortcuts

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