githubx

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetArchive

func GetArchive(
	ctx context.Context,
	c *http.Client,
	url string,
) (_ string, err error)

GetArchive downloads and uncompresses a source archive from GitHub.

It returns the name of a temporary directory containing the root of the repository.

func ListInstallations

func ListInstallations(
	ctx context.Context,
	c *github.Client,
	fn func(context.Context, *github.Installation) error,
) error

ListInstallations calls fn for each installation of the application.

func ListRepos

func ListRepos(
	ctx context.Context,
	c *github.Client,
	fn func(context.Context, *github.Repository) error,
) error

ListRepos calls fn for each repository that the application can access.

func NewOAuthEndpoint

func NewOAuthEndpoint(u *url.URL) oauth2.Endpoint

NewOAuthEndpoint returns the OAuth endpoint configuration to use for the GitHub installation at the given URL.

If u is empty, the configuration for github.com is returned.

Types

type AppTokenSource

type AppTokenSource struct {
	// AppID is the GitHub application ID.
	AppID int64

	// PrivateKey is the application's private key.
	PrivateKey *rsa.PrivateKey

	// TTL is the default amount of time that each token remains valid.
	// If it is non-positive, a value of 1 minute is used.
	TTL time.Duration
}

AppTokenSource is an implementation of oauth2.TokenSource that generates GitHub API tokens that authenticate as a GitHub application.

func (*AppTokenSource) Token

func (s *AppTokenSource) Token() (*oauth2.Token, error)

Token returns an OAuth token that authenticates as the GitHub application.

type Connector

type Connector struct {
	// AppClient is a GitHub client that is setup to authenticate using the
	// GitHub application's credentials.
	AppClient *github.Client

	// OAuthConfig is the OAuth configuration for the application. It may be nil
	// if the application does not authenticate or act on behalf of GitHub
	// users.
	OAuthConfig *oauth2.Config

	// Permissions optionally limits the client's permissions to a subset of
	// those available to the application.
	//
	// If it is nil, the full set of permissions granted to the application are
	// granted to each new client.
	Permissions *github.InstallationPermissions

	// Transport is the HTTP transport used by GitHub clients created by the
	// connector. If it is nil the default transport is used.
	Transport http.RoundTripper
}

Connector creates GitHub clients with different authentication credentials on behalf of a GitHub application.

func NewConnector

func NewConnector(
	appID int64,
	appKey *rsa.PrivateKey,
	clientID string,
	clientSecret string,
	baseURL *url.URL,
	transport http.RoundTripper,
) (*Connector, error)

NewConnector returns a new connector.

This is a convenience function that configures the connector with useful defaults.

clientID is the OAuth client ID. If it is empty the OAuth configuration is omitted.

baseURL is the base URL for the API of a GitHub Enterprise Server installation. If it is nil or empty the connector uses github.com.

transport is the HTTP transport used by the GitHub clients created by the connector. If it is nil the default HTTP transport is used.

func (*Connector) InstallationClient

func (c *Connector) InstallationClient(ctx context.Context, id int64) (*github.Client, error)

InstallationClient returns a GitHub client that is authenticated as a specific installation of a GitHub application.

func (*Connector) RepositoryClient

func (c *Connector) RepositoryClient(ctx context.Context, id int64) (*github.Client, bool, error)

RepositoryClient returns a GitHub client that is authenticated as a the installation of a GitHub application that grants the application access to a specific repository.

The client uses an access token that is only granted access to the specified repository.

func (*Connector) UserClient

func (c *Connector) UserClient(ctx context.Context, t *oauth2.Token) (*github.Client, error)

UserClient returns a GitHub client that is authenticated as a GitHub user who has granted the application permission to act on their behalf.

type InstallationTokenSource

type InstallationTokenSource struct {
	// AppClient is a GitHub client that is authenticated as the application
	// itself. See AppTokenSource.
	AppClient *github.Client

	// InstallationID is the ID of the installation.
	InstallationID int64

	// Options is a set of options to use when generating installation-specific
	// tokens.
	Options *github.InstallationTokenOptions

	// RequestTimeout is the amount of time to allow for token generation via
	// the GitHub client. If it is non-positive, a value of 10 seconds is used.
	RequestTimeout time.Duration
}

InstallationTokenSource is an implementation of oauth2.TokenSource that generates GitHub API tokens that authenticate a specific installation of a GitHub application.

func (*InstallationTokenSource) Token

func (s *InstallationTokenSource) Token() (*oauth2.Token, error)

Token returns an OAuth token that authenticates as a specific installation of a GitHub application.

Jump to

Keyboard shortcuts

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