github

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 13 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

Overview

Package github is a small read-only GitHub API client. It sends GET requests to the REST API and queries to the GraphQL API, and it never sends a mutation. It waits out rate limits and retries server errors.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadCursor = errors.New("bad cursor")

ErrBadCursor is returned when GitHub does not accept a paging cursor.

View Source
var ErrForbidden = errors.New("github refused the query")

ErrForbidden marks a query the token is not allowed to make.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound marks a 404, or a GraphQL NOT_FOUND. A token without access to a private repository also gets this.

View Source
var ErrServer = errors.New("github server error")

ErrServer marks a failure on GitHub's side that a smaller request may avoid, such as a timeout on a heavy GraphQL query.

View Source
var ErrUnreachable = errors.New("github cannot be reached")

ErrUnreachable marks a request that never got to GitHub: no network, no name for the host, or nothing that listens there. A smaller request does not help with that.

Functions

func NextPage

func NextPage(h http.Header) string

NextPage returns the URL of the next page from a Link header, or "".

Types

type Client

type Client struct {
	Token string
	// BaseURL is the REST root, without a trailing slash.
	BaseURL string
	// GraphQLURL is the GraphQL endpoint.
	GraphQLURL string
	HTTP       *http.Client
	// MaxWait is the longest single rate-limit wait the client accepts before
	// it gives up with an error that names the reset time.
	MaxWait time.Duration
	// Logf receives progress lines, such as rate-limit waits. May be nil.
	Logf func(format string, a ...any)
	// Waiting is told how long the client is about to wait for a rate limit.
	// A display that sets it shows the wait itself, so the wait is then not
	// sent to Logf as well. May be nil.
	Waiting func(time.Duration)
	// UserAgent is sent with every request.
	UserAgent string

	// Calls counts HTTP requests sent, including retries. Read it when no
	// request is in flight.
	Calls int
	// contains filtered or unexported fields
}

Client talks to one GitHub host.

func New

func New(token string) *Client

New returns a client for github.com.

func (*Client) GraphQL

func (c *Client) GraphQL(ctx context.Context, query string, vars map[string]any, out any) error

GraphQL runs a query and decodes the "data" object into out. Mutations are refused: this client is read-only by construction.

func (*Client) REST

func (c *Client) REST(ctx context.Context, path string, query url.Values, out any) (http.Header, error)

REST sends a GET to path under the REST root and decodes the JSON response into out. It returns the response headers so the caller can read Link.

func (*Client) Requests added in v0.2.0

func (c *Client) Requests() int

Requests is the number of HTTP requests sent so far. Unlike Calls it is safe to read while requests are in flight.

Jump to

Keyboard shortcuts

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