Documentation
¶
Overview ¶
Package github provides GitHub App authentication, webhooks, and API client.
Index ¶
Constants ¶
const DefaultAPIURL = "https://api.github.com/"
DefaultAPIURL is the API base of GITHUB_API_URL when it is unset, the one go-github and ghinstallation default to.
Variables ¶
var ErrUserInfo = errors.New("must not contain user info")
ErrUserInfo is ParseBaseURL's error for a URL with user info.
Functions ¶
func NewClient ¶ added in v0.27.0
NewClient returns an unauthenticated go-github client on the API base apiURL: gh.NewClient's default when apiURL is "" or DefaultAPIURL, else WithEnterpriseURLs(apiURL, apiURL), which appends "api/v3/" to a base whose path does not end with it and whose host neither starts with "api." nor contains ".api.".
func ParseBaseURL ¶ added in v0.27.0
ParseBaseURL parses raw as an https or http URL with a host, no user info (ErrUserInfo), query or fragment. The URL stays out of its error: it may hold credentials. Its error reads after the setting's name.
func ParseWebURL ¶ added in v0.27.0
ParseWebURL validates raw as a GITHUB_URL: an https or http URL with a host, no user info, query or fragment, and no path other than "/". It returns the canonical base: scheme and host lowercased, the scheme's default port (443, 80) dropped and no trailing "/", the form of the URLs the host itself writes, which the case-sensitive PR URL rule compares against. Its error reads after the setting's name.
func ValidateAPIURL ¶ added in v0.27.0
ValidateAPIURL validates raw as a GITHUB_API_URL: an https or http URL with a host, no user info, query or fragment, and any path. Its error reads after the setting's name.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App provides GitHub App authentication and webhook handling.
func NewApp ¶
NewApp creates a new App from the given configuration. Its transports and the clients of Client send every request under cfg.APIURL as NewClient resolves it.
func NewAppFromTransport ¶
func NewAppFromTransport(tr *ghinstallation.AppsTransport, webhookSecret string) (*App, error)
NewAppFromTransport creates a new App using a pre-configured AppsTransport. This is useful for testing with custom base URLs.
func (*App) AppsTransport ¶ added in v0.26.0
func (a *App) AppsTransport() *ghinstallation.AppsTransport
AppsTransport returns the transport authenticated as the App itself, with the App JWT, for the App's own endpoints such as GET /app.
func (*App) Client ¶ added in v0.27.0
func (a *App) Client(rt http.RoundTripper) *gh.Client
Client returns a go-github client over rt on the App's API base: the default client for the default base, else the bases NewClient resolved.
func (*App) InstallationTransport ¶ added in v0.26.0
func (a *App) InstallationTransport(installationID int64) *ghinstallation.Transport
InstallationTransport returns a transport authenticated as the given installation. It caches the installation token and mints a new one only when the cached one is due for refresh, so a process builds one and shares it. It requests its tokens under the App's API base.
type AppConfig ¶
type AppConfig struct {
AppID int64
PrivateKey []byte //nolint:gosec // intentional field name for PEM-encoded RSA private key
WebhookSecret string
// APIURL is the API base of the GitHub host (GITHUB_API_URL), "" or
// DefaultAPIURL for the default.
APIURL string
}
AppConfig holds the configuration for a GitHub App.