githubapi

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultResponseSizeLimit int64 = 10 * 1024 * 1024

DefaultResponseSizeLimit is the maximum GraphQL HTTP response body size a Client accepts for decoding unless configured otherwise. It is 10 MiB.

View Source
const LatestCommit_Operation = "" /* 350-byte string literal not displayed */

The query executed by LatestCommit.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.3.0

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

Client executes GraphQL operations against an HTTP endpoint.

Configure bearer authentication with Client.SetBearerToken. Other request behavior, including other authentication schemes, belongs on the supplied http.Client or its http.RoundTripper. A Client may be used concurrently after construction.

func NewClient added in v0.3.0

func NewClient(endpoint string, httpClient *http.Client) *Client

NewClient returns a client for endpoint. It shallow-copies httpClient, or http.DefaultClient when httpClient is nil, and configures the copy to refuse redirects by default. Changes to the supplied client after this call, including its CheckRedirect function, do not affect the returned Client. The supplied CheckRedirect is discarded; use Client.SetAllowRedirects to opt in to redirects.

func (*Client) AllowRedirects added in v0.4.0

func (c *Client) AllowRedirects() bool

AllowRedirects reports whether client follows redirects. New clients refuse redirects by default.

func (*Client) LatestCommit added in v0.3.0

func (c *Client) LatestCommit(
	ctx context.Context,
	vars LatestCommitVariables,
) (*LatestCommitResponse, error)

func (*Client) RateLimit added in v0.3.0

func (c *Client) RateLimit() (RateLimit, bool)

RateLimit returns the latest valid primary rate-limit snapshot observed by client. The boolean is false until a response includes a valid X-RateLimit-Remaining header.

The snapshot is advisory: other clients and processes can consume the same GitHub rate-limit budget after it is observed.

func (*Client) ResponseSizeLimit added in v0.3.0

func (c *Client) ResponseSizeLimit() int64

ResponseSizeLimit returns the maximum HTTP response body size Client accepts for decoding. A newly constructed Client uses DefaultResponseSizeLimit.

func (*Client) SetAllowRedirects added in v0.4.0

func (c *Client) SetAllowRedirects(allow bool) error

SetAllowRedirects configures whether client follows redirects. When enabled, client follows at most 10 redirects and removes Authorization when a redirect leaves the original request origin. Credentials added by a custom http.RoundTripper cannot be removed because the transport reapplies them on every hop. It may be called concurrently with [Client._octoqlExecute].

func (*Client) SetBearerToken added in v0.3.0

func (c *Client) SetBearerToken(token string) error

SetBearerToken configures the OAuth 2.0 bearer token sent with each request. token must use the RFC 6750 b64token syntax. It may be called concurrently with [Client._octoqlExecute] to rotate credentials.

func (*Client) SetResponseSizeLimit added in v0.3.0

func (c *Client) SetResponseSizeLimit(limit int64) error

SetResponseSizeLimit configures the maximum HTTP response body size Client accepts for decoding. limit must be greater than zero. It may be called concurrently with [Client._octoqlExecute].

type Error added in v0.3.0

type Error struct {
	Type       ErrorType      `json:"type,omitempty"`
	Message    string         `json:"message"`
	Path       Path           `json:"path,omitempty"`
	Locations  []Location     `json:"locations,omitempty"`
	Extensions map[string]any `json:"extensions,omitempty"`
}

Error describes an error returned in a GraphQL response.

func (*Error) Error added in v0.3.0

func (e *Error) Error() string

Error returns the GraphQL error message and response path.

func (*Error) GraphQLExtensions added in v0.3.0

func (e *Error) GraphQLExtensions() map[string]any

GraphQLExtensions returns a shallow clone of the GraphQL error extensions.

func (*Error) GraphQLMessage added in v0.3.0

func (e *Error) GraphQLMessage() string

GraphQLMessage returns the GraphQL error message.

func (*Error) GraphQLPath added in v0.3.0

func (e *Error) GraphQLPath() []any

GraphQLPath returns a defensive copy of the GraphQL response path.

func (*Error) GraphQLType added in v0.3.0

func (e *Error) GraphQLType() string

GraphQLType returns GitHub's GraphQL error category.

type ErrorType added in v0.3.0

type ErrorType string

ErrorType identifies a GitHub GraphQL error category. It is an open string type so values introduced by GitHub remain available to callers.

type Errors added in v0.3.0

type Errors []*Error

Errors is the list of errors returned in a GraphQL response.

func (Errors) Error added in v0.3.0

func (e Errors) Error() string

Error returns a stable summary of all GraphQL errors.

func (Errors) GraphQLError added in v0.3.0

func (e Errors) GraphQLError(index int) error

GraphQLError returns one GraphQL error as a package-neutral error value.

func (Errors) GraphQLErrorCount added in v0.3.0

func (e Errors) GraphQLErrorCount() int

GraphQLErrorCount returns the number of GraphQL errors.

func (Errors) Unwrap added in v0.3.0

func (e Errors) Unwrap() []error

Unwrap exposes individual GraphQL errors to errors.Is, errors.As, and errors.AsType.

type LatestCommitPartialDataError

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

LatestCommitPartialDataError contains partial data returned by LatestCommit.

func (*LatestCommitPartialDataError) Error

func (*LatestCommitPartialDataError) PartialData

func (*LatestCommitPartialDataError) PartialDataValue added in v0.3.0

func (e *LatestCommitPartialDataError) PartialDataValue() any

PartialDataValue returns the partial response as an untyped value.

func (*LatestCommitPartialDataError) Unwrap

func (e *LatestCommitPartialDataError) Unwrap() error

type LatestCommitRepository

type LatestCommitRepository struct {
	// The Ref associated with the repository's default branch.
	DefaultBranchRef *LatestCommitRepositoryDefaultBranchRef `json:"defaultBranchRef"`
}

LatestCommitRepository includes the requested fields of the GraphQL type Repository. The GraphQL type's documentation follows.

A repository contains the content for a project.

func (*LatestCommitRepository) GetDefaultBranchRef

GetDefaultBranchRef returns LatestCommitRepository.DefaultBranchRef, and is useful for accessing the field via an interface.

type LatestCommitRepositoryDefaultBranchRef

type LatestCommitRepositoryDefaultBranchRef struct {
	// The object the ref points to. Returns null when object does not exist.
	Target LatestCommitRepositoryDefaultBranchRefTargetGitObject `json:"-"`
}

LatestCommitRepositoryDefaultBranchRef includes the requested fields of the GraphQL type Ref. The GraphQL type's documentation follows.

Represents a Git reference.

func (*LatestCommitRepositoryDefaultBranchRef) GetTarget

GetTarget returns LatestCommitRepositoryDefaultBranchRef.Target, and is useful for accessing the field via an interface.

func (*LatestCommitRepositoryDefaultBranchRef) MarshalJSON

func (v *LatestCommitRepositoryDefaultBranchRef) MarshalJSON() ([]byte, error)

func (*LatestCommitRepositoryDefaultBranchRef) UnmarshalJSON

func (v *LatestCommitRepositoryDefaultBranchRef) UnmarshalJSON(b []byte) error

type LatestCommitRepositoryDefaultBranchRefTargetCommit

type LatestCommitRepositoryDefaultBranchRefTargetCommit struct {
	Typename string `json:"__typename"`
	// The linear commit history starting from (and including) this commit, in the same order as `git log`.
	History LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnection `json:"history"`
}

LatestCommitRepositoryDefaultBranchRefTargetCommit includes the requested fields of the GraphQL type Commit. The GraphQL type's documentation follows.

Represents a Git commit.

func (*LatestCommitRepositoryDefaultBranchRefTargetCommit) GetHistory

GetHistory returns LatestCommitRepositoryDefaultBranchRefTargetCommit.History, and is useful for accessing the field via an interface.

func (*LatestCommitRepositoryDefaultBranchRefTargetCommit) GetTypename

GetTypename returns LatestCommitRepositoryDefaultBranchRefTargetCommit.Typename, and is useful for accessing the field via an interface.

type LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnection

type LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnection struct {
	// A list of nodes.
	Nodes []*LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnectionNodesCommit `json:"nodes"`
}

LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnection includes the requested fields of the GraphQL type CommitHistoryConnection. The GraphQL type's documentation follows.

The connection type for Commit.

func (*LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnection) GetNodes

GetNodes returns LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnection.Nodes, and is useful for accessing the field via an interface.

type LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnectionNodesCommit

type LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnectionNodesCommit struct {
	// The Git object ID
	Oid string `json:"oid"`
}

LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnectionNodesCommit includes the requested fields of the GraphQL type Commit. The GraphQL type's documentation follows.

Represents a Git commit.

func (*LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnectionNodesCommit) GetOid

GetOid returns LatestCommitRepositoryDefaultBranchRefTargetCommitHistoryCommitHistoryConnectionNodesCommit.Oid, and is useful for accessing the field via an interface.

type LatestCommitRepositoryDefaultBranchRefTargetGitObject

type LatestCommitRepositoryDefaultBranchRefTargetGitObject interface {

	// GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values).
	GetTypename() string
	// contains filtered or unexported methods
}

LatestCommitRepositoryDefaultBranchRefTargetGitObject includes the requested fields of the GraphQL interface GitObject.

LatestCommitRepositoryDefaultBranchRefTargetGitObject is implemented by the following types: LatestCommitRepositoryDefaultBranchRefTargetCommit LatestCommitRepositoryDefaultBranchRefTargetGitObjectOctoqlOther The GraphQL type's documentation follows.

Represents a Git object.

type LatestCommitRepositoryDefaultBranchRefTargetGitObjectOctoqlOther

type LatestCommitRepositoryDefaultBranchRefTargetGitObjectOctoqlOther struct {
	Typename string `json:"__typename"`
}

LatestCommitRepositoryDefaultBranchRefTargetGitObjectOctoqlOther represents LatestCommitRepositoryDefaultBranchRefTargetGitObject implementations not explicitly selected by a fragment. Use GetTypename to identify the concrete GraphQL type.

func (*LatestCommitRepositoryDefaultBranchRefTargetGitObjectOctoqlOther) GetTypename

GetTypename returns LatestCommitRepositoryDefaultBranchRefTargetGitObjectOctoqlOther.Typename, and is useful for accessing the field via an interface.

type LatestCommitResponse

type LatestCommitResponse struct {
	// Lookup a given repository by the owner and repository name.
	Repository *LatestCommitRepository `json:"repository"`
}

LatestCommitResponse is returned by LatestCommit on success.

func (*LatestCommitResponse) GetRepository

func (v *LatestCommitResponse) GetRepository() *LatestCommitRepository

GetRepository returns LatestCommitResponse.Repository, and is useful for accessing the field via an interface.

type LatestCommitVariables

type LatestCommitVariables struct {
	Owner string `json:"owner"`
	Name  string `json:"name"`
	Path  string `json:"path"`
}

LatestCommitVariables contains the variables accepted by LatestCommit.

type Location added in v0.3.0

type Location struct {
	Line   int `json:"line,omitempty"`
	Column int `json:"column,omitempty"`
}

Location identifies a line and column in a GraphQL document.

type Path added in v0.3.0

type Path []any

Path is a GraphQL response path. Each segment is either a string field name or an integer list index.

func (Path) MarshalJSON added in v0.3.0

func (p Path) MarshalJSON() ([]byte, error)

MarshalJSON encodes string and integer path segments in GraphQL wire format.

func (Path) String added in v0.3.0

func (p Path) String() string

String formats a path using dotted fields and bracketed list indexes.

func (*Path) UnmarshalJSON added in v0.3.0

func (p *Path) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes GraphQL string and integer path segments.

type RateLimit added in v0.3.0

type RateLimit struct {
	Limit      int
	Remaining  int
	Used       int
	Reset      time.Time
	Resource   string
	RetryAfter time.Duration
	RetryAt    time.Time
}

RateLimit describes the rate-limit headers returned by GitHub.

Missing or malformed response headers leave their corresponding fields at their zero values.

type RateLimitError added in v0.3.0

type RateLimitError struct {
	Kind      RateLimitKind
	RateLimit RateLimit
	Err       error
}

RateLimitError describes a response rejected because of a GitHub rate limit.

func (*RateLimitError) Error added in v0.3.0

func (e *RateLimitError) Error() string

Error returns a summary of the rate-limit failure.

func (*RateLimitError) RateLimitKind added in v0.3.0

func (e *RateLimitError) RateLimitKind() string

RateLimitKind returns the kind of rate limit that rejected the request.

func (*RateLimitError) RetryAt added in v0.3.0

func (e *RateLimitError) RetryAt() time.Time

RetryAt returns the primary reset time or secondary retry time.

func (*RateLimitError) Unwrap added in v0.3.0

func (e *RateLimitError) Unwrap() error

Unwrap exposes the response failure and its GraphQL or processing causes.

type RateLimitKind added in v0.3.0

type RateLimitKind string

RateLimitKind identifies the GitHub rate limit that rejected a request.

const (
	// RateLimitPrimary identifies exhaustion of GitHub's primary rate limit.
	RateLimitPrimary RateLimitKind = "primary"
	// RateLimitSecondary identifies GitHub's secondary rate limit.
	RateLimitSecondary RateLimitKind = "secondary"
)

type ResponseError added in v0.3.0

type ResponseError struct {
	// StatusCode is the HTTP response status.
	StatusCode int
	// RequestID is GitHub's X-GitHub-Request-ID value, when present.
	RequestID string
	// RawBody contains at most the first 64 KiB of a non-successful, over-limit,
	// or undecodable response. It is omitted for ordinary GraphQL errors.
	RawBody []byte
	// RawBodyTruncated reports whether RawBody omits trailing response bytes.
	RawBodyTruncated bool
	// contains filtered or unexported fields
}

ResponseError describes a failed GraphQL HTTP response.

func (*ResponseError) Error added in v0.3.0

func (e *ResponseError) Error() string

Error returns a stable summary of the failed response.

func (*ResponseError) GitHubRequestID added in v0.3.0

func (e *ResponseError) GitHubRequestID() string

GitHubRequestID returns the response's X-GitHub-Request-ID value.

func (*ResponseError) HTTPStatusCode added in v0.3.0

func (e *ResponseError) HTTPStatusCode() int

HTTPStatusCode returns the failed HTTP response status.

func (*ResponseError) Unwrap added in v0.3.0

func (e *ResponseError) Unwrap() error

Unwrap exposes decoded GraphQL errors and response processing failures to errors.Is, errors.As, and errors.AsType.

type ResponseSizeLimitError added in v0.3.0

type ResponseSizeLimitError struct {
	// Limit is the configured maximum response size in bytes.
	Limit int64
}

ResponseSizeLimitError reports that a GraphQL HTTP response exceeded Client's configured response-size limit.

func (*ResponseSizeLimitError) Error added in v0.3.0

func (e *ResponseSizeLimitError) Error() string

Error reports that the response exceeded its configured limit.

func (*ResponseSizeLimitError) ResponseSizeLimit added in v0.3.0

func (e *ResponseSizeLimitError) ResponseSizeLimit() int64

ResponseSizeLimit returns the configured response-size limit.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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