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 ¶
- func KnownHosts() []string
- type Client
- func (c *Client) Changes(ctx context.Context, p forge.Project, sha string) ([]forge.Change, error)
- func (c *Client) ClosedChanges(ctx context.Context, projects []forge.Project, sha string) (map[forge.Project][]forge.Change, error)
- func (c *Client) Contains(ctx context.Context, p forge.Project, ancestor, descendant string) (bool, error)
- func (c *Client) DefaultBranch(ctx context.Context, p forge.Project) (string, error)
- func (c *Client) Exists(ctx context.Context, p forge.Project) error
- type Options
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 (*Client) Changes ¶
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 ¶
DefaultBranch returns p's default branch, from the same cached lookup as Exists.
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.