github

package
v0.0.54 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package github is the ConnectorSource over one branch of a GitHub repository, read as a GitHub App installation: the branch head's recursive git tree, one object per file. Errors are coded for the client tier: a transport failure, a 5xx, a 429 or a rate limit is CodeUnavailable (retried); a missing repository, branch or installation and any other 4xx are CodeInvalidInput.

Index

Constants

View Source
const DefaultBaseURL = "https://api.github.com"

DefaultBaseURL is the GitHub REST API root; GitHub Enterprise Server sets its own.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppAuth

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

AppAuth is the TokenSource for one App installation: it signs an RS256 App JWT, exchanges it at POST /app/installations/{id}/access_tokens, and reuses the token until five minutes before it expires. Safe for concurrent use; concurrent callers share one exchange.

func NewAppAuth

func NewAppAuth(
	cfg AppAuthConfig,
	doer interfaces.HTTPDoer,
	now func() time.Time,
) (*AppAuth, error)

NewAppAuth returns the AppAuth for cfg, sending through doer and reading the clock with now. It does no I/O; an unparsable key or a non-positive id is CodeInvalidInput.

func (*AppAuth) Token

func (a *AppAuth) Token(ctx context.Context) (string, error)

Token returns the cached installation token, exchanging a fresh App JWT for a new one when none is cached or the cached one expires within five minutes.

type AppAuthConfig

type AppAuthConfig struct {
	// BaseURL is the REST API root; empty means DefaultBaseURL.
	BaseURL string

	// PrivateKeyPEM is the App's PEM-encoded RSA private key (PKCS#1 or PKCS#8).
	PrivateKeyPEM interfaces.Secret

	// AppID is the App's numeric id, the JWT issuer.
	AppID int64

	// InstallationID is the installation the tokens are minted for.
	InstallationID int64
}

AppAuthConfig names the GitHub App installation an AppAuth mints tokens for.

type Config

type Config struct {
	// BaseURL is the REST API root; empty means DefaultBaseURL.
	BaseURL string

	// Owner is the repository's owner login.
	Owner string

	// Repo is the repository's name.
	Repo string

	// Branch is the branch listed; empty means the repository's default branch.
	Branch string

	// IncludeGlobs keeps only the paths matching at least one pattern; empty keeps all.
	IncludeGlobs []string

	// ExcludeGlobs drops the paths matching any pattern, after IncludeGlobs.
	ExcludeGlobs []string
}

Config names the repository, branch and paths a Source lists.

type Source

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

Source is the ConnectorSource over one branch of a GitHub repository. The first page pins the branch head's commit, and every continuation token carries it, so a crawl lists one tree even when the branch moves mid-crawl. Each regular file is one object: Key is its path, ETag its blob SHA, Size its byte size and LastModified the pinned commit's committer date. Safe for concurrent use.

func NewSource

func NewSource(
	cfg *Config,
	tokens TokenSource,
	doer interfaces.HTTPDoer,
) (*Source, error)

NewSource returns the Source for cfg, authorizing each request with a token from tokens and sending it through doer. It does no I/O; a missing owner or repository is CodeInvalidInput.

func (*Source) ListPage

func (s *Source) ListPage(
	ctx context.Context,
	continuationToken string,
	limit int,
) ([]interfaces.StorageObject, string, error)

ListPage returns up to limit files after continuationToken's offset in the commit it pins; an empty token resolves the branch head and starts at the first file.

func (*Source) TestConnection

func (s *Source) TestConnection(ctx context.Context) (int, error)

TestConnection resolves the branch head and returns how many files a crawl of it would list.

type TokenSource

type TokenSource interface {
	// Token returns a token valid for at least a few more minutes, or a coded error.
	Token(ctx context.Context) (string, error)
}

TokenSource yields the installation access token every API request sends.

Jump to

Keyboard shortcuts

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