github

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 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 provides GitHub App authentication, webhooks, and API client.

Index

Constants

View Source
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

View Source
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

func NewClient(apiURL string) (*gh.Client, error)

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

func ParseBaseURL(raw string) (*url.URL, error)

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

func ParseWebURL(raw string) (string, error)

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

func ValidateAPIURL(raw string) error

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

func NewApp(cfg AppConfig) (*App, error)

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.

func (*App) ValidateWebhook

func (a *App) ValidateWebhook(r *http.Request) ([]byte, error)

ValidateWebhook validates the webhook signature and returns the raw payload.

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.

Jump to

Keyboard shortcuts

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