githubapp

package
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package githubapp is a thin GitHub App API client covering the manifest conversion, installation, and repository discovery flows. It wraps go-github for the REST calls and ghinstallation for the App-JWT / installation-token auth model, which differs from the rest of the git client (that uses a static token or basic auth).

Package githubapp is a generated GoMock package.

Index

Constants

View Source
const (
	PermContents     = "contents"
	PermMetadata     = "metadata"
	PermPullRequests = "pull_requests"
	PermIssues       = "issues"
	PermLevelRead    = "read"
	PermLevelWrite   = "write"
)

GitHub App permission scopes and access levels requested by the manifest.

View Source
const CloneUsername = "x-access-token"

CloneUsername is the username GitHub expects alongside an installation token for git-over-HTTPS operations.

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

DefaultAPIBaseURL is the public GitHub API endpoint.

Variables

View Source
var ErrCommentNotFound = errors.New("comment not found")

ErrCommentNotFound reports that the target comment no longer exists (e.g. a human deleted it); callers re-create instead of failing.

Functions

This section is empty.

Types

type AppCredentials

type AppCredentials struct {
	AppID         int64  // numeric GitHub App ID
	Slug          string // URL slug, e.g. "stackdome-ci"
	PEM           string // RSA private key (PEM) used to sign app JWTs
	WebhookSecret string // secret for verifying webhook payload signatures
	ClientID      string // OAuth client ID
	ClientSecret  string // OAuth client secret
}

AppCredentials are the app-level credentials produced by the manifest flow. Every field is a secret; the PEM in particular is the app's RSA private key used to sign app JWTs.

type AppHookAttributes

type AppHookAttributes struct {
	URL string `json:"url"`
}

AppHookAttributes configures where GitHub delivers the app's webhooks.

type AppManifest

type AppManifest struct {
	Name               string            `json:"name"`
	URL                string            `json:"url"`
	RedirectURL        string            `json:"redirect_url"`
	SetupURL           string            `json:"setup_url"`
	Public             bool              `json:"public"`
	HookAttributes     AppHookAttributes `json:"hook_attributes"`
	DefaultPermissions map[string]string `json:"default_permissions"`
	DefaultEvents      []string          `json:"default_events"`
}

AppManifest is the GitHub App creation manifest the browser POSTs to github.com/settings/apps/new. GitHub has no SDK type for this input (go-github only converts the resulting code), so it is defined here alongside the other GitHub App wire types. The hub-specific URLs are filled in by the caller.

type Client

type Client interface {
	// ConvertManifestCode exchanges the temporary code from the manifest
	// redirect for the newly created app's credentials.
	ConvertManifestCode(ctx context.Context, code string) (*AppCredentials, error)
	// ListInstallations lists every installation of the app (app JWT auth),
	// following pagination.
	ListInstallations(ctx context.Context, creds *AppCredentials) ([]Installation, error)
	// GetInstallation fetches one installation of the app by its GitHub id.
	GetInstallation(ctx context.Context, creds *AppCredentials, installationID int64) (*Installation, error)
	// DeleteInstallation uninstalls the app from the installation's account.
	DeleteInstallation(ctx context.Context, creds *AppCredentials, installationID int64) error
	// MintInstallationToken creates a short-lived installation access token.
	MintInstallationToken(ctx context.Context, creds *AppCredentials, installationID int64) (*Token, error)
	// ListInstallationRepos lists one page of repositories the installation
	// can access.
	ListInstallationRepos(ctx context.Context, creds *AppCredentials, installationID int64, page int) (*RepoPage, error)
	// GetRepo fetches repository details through the installation.
	GetRepo(ctx context.Context, creds *AppCredentials, installationID int64, owner, repo string) (*Repo, error)
	// ListBranches lists branch names through the installation.
	ListBranches(ctx context.Context, creds *AppCredentials, installationID int64, owner, repo string) ([]string, error)
}

func NewClient

func NewClient(spec ClientSpec) Client

NewClient returns a GitHub App client. Because credentials are supplied per call rather than stored, a single instance is safe to share across orgs and goroutines.

type ClientSpec

type ClientSpec struct {
	// BaseURL is optional; it defaults to the public GitHub API. Set it to a
	// GitHub Enterprise or test-server URL to point the client elsewhere.
	BaseURL string
	// HTTPClient is optional. Its Transport is used as the base round-tripper
	// beneath the app-JWT / installation-token auth transports, and its Timeout
	// (when set) overrides the 30s default.
	HTTPClient *http.Client
}

ClientSpec configures a Client.

type Installation

type Installation struct {
	ID                  int64
	AccountLogin        string // account (user or org) the app is installed on
	AccountType         string // "User" or "Organization"
	RepositorySelection string // "all" or "selected"
	Suspended           bool   // true when the installation is suspended and cannot be used
}

Installation is a GitHub App installation on a user or org account.

type MockPullRequestCommenter

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

MockPullRequestCommenter is a mock of PullRequestCommenter interface.

func NewMockPullRequestCommenter

func NewMockPullRequestCommenter(ctrl *gomock.Controller) *MockPullRequestCommenter

NewMockPullRequestCommenter creates a new mock instance.

func (*MockPullRequestCommenter) CreateComment

func (m *MockPullRequestCommenter) CreateComment(ctx context.Context, token, owner, repo string, prNumber int, body string) (int64, error)

CreateComment mocks base method.

func (*MockPullRequestCommenter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPullRequestCommenter) EditComment

func (m *MockPullRequestCommenter) EditComment(ctx context.Context, token, owner, repo string, commentID int64, body string) error

EditComment mocks base method.

type MockPullRequestCommenterMockRecorder

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

MockPullRequestCommenterMockRecorder is the mock recorder for MockPullRequestCommenter.

func (*MockPullRequestCommenterMockRecorder) CreateComment

func (mr *MockPullRequestCommenterMockRecorder) CreateComment(ctx, token, owner, repo, prNumber, body any) *gomock.Call

CreateComment indicates an expected call of CreateComment.

func (*MockPullRequestCommenterMockRecorder) EditComment

func (mr *MockPullRequestCommenterMockRecorder) EditComment(ctx, token, owner, repo, commentID, body any) *gomock.Call

EditComment indicates an expected call of EditComment.

type PullRequestCommenter

type PullRequestCommenter interface {
	CreateComment(ctx context.Context, token, owner, repo string, prNumber int, body string) (int64, error)
	EditComment(ctx context.Context, token, owner, repo string, commentID int64, body string) error
}

PullRequestCommenter posts and edits PR conversation comments using an installation token minted per call.

type PullRequestCommenterSpec

type PullRequestCommenterSpec struct {
	// BaseURL overrides the GitHub API base URL (tests); empty uses api.github.com.
	BaseURL string
}

type Repo

type Repo struct {
	FullName      string // "owner/name"
	CloneURL      string // HTTPS clone URL
	DefaultBranch string
	Private       bool
	PushedAt      *time.Time // last push time; nil if never pushed
	OwnerLogin    string
}

Repo is a repository visible to an installation.

type RepoPage

type RepoPage struct {
	Repos      []Repo
	Page       int
	TotalCount int
	HasNext    bool
}

RepoPage is one page of installation repositories. TotalCount is GitHub's unfiltered total for the installation, so when a query filter is applied len(Repos) may be smaller — even zero — while HasNext is still true.

type Token

type Token struct {
	Value     string
	ExpiresAt time.Time
}

Token is a minted installation access token. Installation tokens are short-lived (~1h), so ExpiresAt is what drives refresh scheduling.

Jump to

Keyboard shortcuts

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