githubclient

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 17 Imported by: 1 module, 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

Index

Constants

View Source
const (
	// MaxRetries is how many times a retryable response is sent again.
	MaxRetries = 5
	// DefaultTimeout is how long one attempt waits for GitHub to answer.
	// The wait between attempts is outside this deadline.
	DefaultTimeout = 30 * time.Second
)

Variables

View Source
var ErrAuthTimedOut = errors.New("github auth timed out")

ErrAuthTimedOut is returned when `gh auth token` does not finish within ghAuthTimeout.

View Source
var ErrAuthUnavailable = errors.New("github auth unavailable")

ErrAuthUnavailable is returned when neither GITHUB_TOKEN nor gh CLI auth is available.

View Source
var ErrRateLimited = errors.New("github rate limited")

ErrRateLimited is returned by a client built with FailOnRateLimit when GitHub answers with a rate limit. The error also wraps errors.ErrTooManyRequests.

Functions

func New

func New(token string, baseURL string, opts ...Option) (*gh.Client, error)

New returns a GitHub API client. An empty token sends requests without a bearer token. An empty baseURL uses https://api.github.com/ and https://uploads.github.com/. Any other absolute http or https baseURL keeps uploads on that same host, under /api/uploads/. Each attempt waits DefaultTimeout. A 429 or 5xx is retried up to MaxRetries times, as is a primary or secondary rate limit. Retry-After is the wait when GitHub sends a positive number of seconds. A primary limit waits until X-RateLimit-Reset, a Unix timestamp. Either of those waits is capped at one hour. While a request waits out a Retry-After, every other request through the client waits with it. Otherwise a spent primary limit, marked by X-RateLimit-Remaining 0, or a 5xx holds only its own request, and a secondary rate limit or a 429 holds every request. FailOnRateLimit replaces the rate limit waits with an error. A client timeout returns an error that wraps errors.ErrTimeout and does not include the request URL.

func NewApp added in v0.17.3

func NewApp(appID int64, privateKey []byte, baseURL string, opts ...Option) (*gh.Client, error)

NewApp returns a client that authenticates as the GitHub App itself, with a JWT signed by privateKey, a PEM-encoded RSA key. Use it for App endpoints, such as GET /app and GET /repos/{owner}/{repo}/installation. Each attempt signs a new JWT. baseURL and opts work as they do for New.

func ResolveToken

func ResolveToken() (string, error)

Types

type Installation added in v0.17.3

type Installation struct {
	// Client calls the REST API with the installation's token. It retries as New describes, and
	// each attempt sends the token Token returns at that moment.
	Client *gh.Client
	// contains filtered or unexported fields
}

Installation authenticates as one installation of a GitHub App. Its REST client and Token share one installation access token.

func NewInstallation added in v0.17.3

func NewInstallation(appID, installationID int64, privateKey []byte, baseURL string, permissions *gh.InstallationPermissions, opts ...Option) (*Installation, error)

NewInstallation returns an Installation for installationID of the App appID. It mints tokens through a NewApp client, with a JWT signed by privateKey, a PEM-encoded RSA key. permissions limits what each token may do; nil asks for every permission the installation has. baseURL and opts work as they do for New, for both the REST client and minting, so a GitHub Enterprise Server baseURL serves both.

func (*Installation) Token added in v0.17.3

func (i *Installation) Token(ctx context.Context) (string, error)

Token returns the installation access token that Client sends, for git over HTTPS with the user x-access-token. It mints a token on first use and again when the cached one has a minute or less left, and otherwise returns the cached one. Minting retries, waits, and fails as New describes. A call that waits for another call's mint returns ctx.Err() if ctx ends first.

type Option added in v0.17.3

type Option func(*options)

Option configures a client from New, NewApp, or NewInstallation.

func FailOnRateLimit added in v0.17.3

func FailOnRateLimit() Option

FailOnRateLimit makes a rate limit return an error wrapping ErrRateLimited at once, instead of waiting it out and retrying. A rate limit is a primary or secondary limit, a 429, or a 403 or 5xx that carries a Retry-After. Other requests through the client are not held. A 5xx without a Retry-After is still retried with the backoff New describes. Use it where a later run can pick the work up, such as a cron job.

Jump to

Keyboard shortcuts

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