gh

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAppCredentials = errors.New("no GitHub App credentials")

ErrNoAppCredentials reports that App credentials were not supplied, so there is no app to ask about. Callers that only make sense under App auth test for it rather than matching on the message.

Functions

func AppClient added in v0.6.1

func AppClient(app config.AppConfig) (*github.Client, error)

AppClient returns a client authenticated as the GitHub App itself, for the endpoints that belong to the app rather than to one of its installations.

It never falls back to GITHUB_TOKEN: a personal access token authenticates a person, and a person has no app installations, so a PAT here would produce a confusing 401 rather than an answer. Callers get ErrNoAppCredentials and can say something useful instead.

func RespectRate

func RespectRate(ctx context.Context, c *github.Client) error

Types

type Client

type Client struct {
	REST *github.Client

	// AppID is the GitHub App this client authenticated as, and 0 under PAT
	// auth, where there is no app. It is the only honest answer to "which app
	// is gomgr?" — a config key or environment variable can name an app that
	// this run is not actually authenticated as — so anything resolving the
	// `app: self` bypass actor reads it from here rather than re-deriving it.
	AppID int64
	// GraphQLURL is the endpoint used by DoGraphQL. Empty means GitHub's public
	// GraphQL API. Tests may override it to point at a local server.
	GraphQLURL string
	// contains filtered or unexported fields
}

func NewClientFromEnv

func NewClientFromEnv(ctx context.Context, app config.AppConfig) (*Client, string, error)

func NewClientWithHTTP added in v0.4.2

func NewClientWithHTTP(rest *github.Client, httpClient *http.Client, graphQLURL string) *Client

NewClientWithHTTP builds a Client around an HTTP client the caller already has.

DoGraphQL needs that client and the field is unexported, so without this there is no way to construct a GraphQL-capable Client outside this package — which left the GraphQL paths untestable.

func (*Client) DoGraphQL added in v0.1.13

func (c *Client) DoGraphQL(ctx context.Context, query string, variables map[string]any, result any) error

DoGraphQL executes a GraphQL query or mutation

type Installation added in v0.6.1

type Installation struct {
	// Org is the account's login, lowercased, because every other org name in
	// gomgr is compared lowercased. Named Org because that is what it is for
	// every installation gomgr can act on — see IsOrg for the ones it cannot.
	Org string
	// ID is the installation ID, which is what the token endpoints want.
	ID int64
	// RepositorySelection is "all" or "selected". An app installed on a
	// selected subset can be installed on the org and still be unable to see
	// the repository a config names, so the two are not the same answer.
	RepositorySelection string
	// IsOrg reports whether this installation is on an organization rather
	// than a user account.
	//
	// An app can be installed on a personal account, and gomgr can never act on
	// one: auth resolves through GetOrganizationInstallation, which answers 404
	// for a user. Such an installation is still worth reporting — it is real,
	// and it carries the same permissions against that account's repositories —
	// but it must not be offered as somewhere a configuration could point.
	IsOrg bool
}

Installation is one account a GitHub App is installed on.

func ListInstallations added in v0.6.1

func ListInstallations(ctx context.Context, appClient *github.Client) ([]Installation, error)

ListInstallations returns every organization the authenticated GitHub App is installed on, sorted by org.

This answers to the app, not to one of its installations, so it needs a client from AppClient — an installation token cannot see its siblings, which is the whole reason this is worth a separate call.

It needs no enterprise scope. That matters: it is the one honest answer gomgr can give to "which organizations does this reach" without a credential that could also rewrite them.

Jump to

Keyboard shortcuts

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