gh

package
v0.0.0-...-ad5db61 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 20 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRateLimit             = errors.New("rate limit hit")
	ErrAssetNotFound         = errors.New("asset not found")
	ErrUnableToDownloadAsset = errors.New("unable to download asset")
	ErrUnableToReadAsset     = errors.New("unable to download asset")
	ErrFatalError            = errors.New("fatal error using github")
)
View Source
var (
	// ErrInvalidPrivateKey is returned when the PEM block cannot be parsed as an RSA private key.
	ErrInvalidPrivateKey = errors.New("invalid rsa private key")

	// ErrEmptyAppID is returned when app ID is empty.
	ErrEmptyAppID = errors.New("app id must not be empty")
)
View Source
var (
	// ErrEmptyInstallationID is returned when an installation ID is empty.
	ErrEmptyInstallationID = errors.New("installation id must not be empty")
)
View Source
var ErrFieldUnexpectedlyNil = errors.New("expected field to be non-nil")

ErrFieldUnexpectedlyNil is returned when a field that is expected to be non-nil is found to be nil. A lot of GitHub API fields are pointers, so we need to check for nil values.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(token string, opts ...ClientOption) *Client

NewClient creates a new Github Client. If the token is not empty, it will use it as the auth token to make calls.

func (*Client) DownloadFileFromRelease

func (c *Client) DownloadFileFromRelease(
	ctx context.Context,
	owner, repo string,
	httpClient *http.Client,
	filePattern string) (*ReleaseFile, error)

type ClientOption

type ClientOption func(*github.Client)

func WithBaseURL

func WithBaseURL(baseURL *url.URL) ClientOption

type GitHubUser

type GitHubUser struct {
	ID       int64
	Username string
}

type InstallationTokenProvider

type InstallationTokenProvider interface {
	GetInstallationToken(ctx context.Context, installationID string) (string, error)
}

InstallationTokenProvider retrieves a valid installation access token for a GitHub App installation.

type ReleaseFile

type ReleaseFile struct {
	Contents io.ReadCloser
	Info     ReleaseInfo
}

ReleaseFile represents a file in a given Github release.

type ReleaseInfo

type ReleaseInfo struct {
	// If the tag is valid, the will be non null.
	Tag *string
}

type RepoClient

type RepoClient interface {
	GetLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error)
}

type TokenCacher

type TokenCacher interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Cache(ctx context.Context, key string, in []byte) error
}

TokenCacher caches installation access tokens.

type TokenProvider

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

TokenProvider manages RS256 JWT minting and cached GitHub App installation access tokens.

func NewTokenProvider

func NewTokenProvider(appID string, privateKeyPEM []byte, cacher TokenCacher) (*TokenProvider, error)

NewTokenProvider returns a new TokenProvider configured with the given cacher and standard HTTP transport. Validates appID and parses privateKeyPEM at construction time to fail fast on invalid credentials.

func (*TokenProvider) GetInstallationToken

func (tp *TokenProvider) GetInstallationToken(ctx context.Context, installationID string) (string, error)

GetInstallationToken returns a valid GitHub App installation access token.

type UserEmail

type UserEmail struct {
	Email    string
	Verified bool
}

type UserGitHubClient

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

UserGitHubClient is a client that receives a token from a user that has installed our GitHub App. It uses that token to make requests on behalf of that user to verify things about them. It is different from the regular Client which is used for internal operations.

func NewUserGitHubClient

func NewUserGitHubClient(token string, opts ...ClientOption) *UserGitHubClient

NewUserGitHubClient creates a new UserGitHubClient with the given token. Assumes that the token is not empty.

func (*UserGitHubClient) GetCurrentUser

func (c *UserGitHubClient) GetCurrentUser(ctx context.Context) (*GitHubUser, error)

func (*UserGitHubClient) ListEmails

func (c *UserGitHubClient) ListEmails(ctx context.Context) ([]*UserEmail, error)

type UsersClient

type UsersClient interface {
	ListEmails(ctx context.Context, opts *github.ListOptions) ([]*github.UserEmail, *github.Response, error)
	Get(ctx context.Context, user string) (*github.User, *github.Response, error)
}

type WebhookVerifier

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

WebhookVerifier validates incoming GitHub webhook signatures using HMAC SHA-256.

func NewWebhookVerifier

func NewWebhookVerifier(secret []byte) *WebhookVerifier

NewWebhookVerifier creates a new WebhookVerifier with the provided secret.

func (*WebhookVerifier) VerifySignature

func (v *WebhookVerifier) VerifySignature(payload []byte, headerSig string) error

VerifySignature verifies a GitHub HMAC SHA-256 webhook signature header (e.g. "sha256=...").

Jump to

Keyboard shortcuts

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