github

package
v0.1.0-alpha.5 Latest Latest
Warning

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

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

Documentation

Overview

Package github implements push-to-deploy: a webhook endpoint that turns GitHub push events into builds, and GitHub App authentication for cloning private repos and posting commit statuses (spec F9, T-37).

Index

Constants

View Source
const (
	StatusPending = "pending"
	StatusSuccess = "success"
	StatusFailure = "failure"
)

CommitStatus states for SetCommitStatus.

Variables

This section is empty.

Functions

func SignPayload

func SignPayload(secret, body []byte) string

SignPayload returns the "sha256=<hex>" signature for a body (used by tests and the CLI setup helper).

Types

type App

type App struct {
	ProjectID          string
	AppID              string
	Repo               string // "owner/name"
	InstallationID     int64
	WebhookSecret      []byte // unsealed HMAC secret
	BranchEnvironments map[string]string
}

App is the resolved GitHub configuration for a repository.

type AppStore

type AppStore interface {
	AppByRepo(repo string) (*App, bool)
}

AppStore resolves a repo ("owner/name") to its configured app.

type Deduper

type Deduper interface {
	Seen(deliveryID string) bool
}

Deduper records processed delivery ids (with a TTL) so redelivered webhooks are not built twice. Seen returns true if the id was already recorded.

type Deployer

type Deployer interface {
	DeployGit(ctx context.Context, app *App, envName, branch, sha, cloneURL, token string) (deploymentID string, err error)
}

Deployer creates a build + deployment for a pushed commit.

type GitHubApp

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

GitHubApp authenticates as a GitHub App: it signs a short-lived JWT with the app private key, exchanges it for per-installation access tokens (cached until just before expiry), and posts commit statuses.

func NewGitHubApp

func NewGitHubApp(appID int64, pemKey []byte, opts ...Option) (*GitHubApp, error)

NewGitHubApp builds an app authenticator from a PEM-encoded RSA private key.

func (*GitHubApp) InstallationToken

func (g *GitHubApp) InstallationToken(ctx context.Context, installationID int64) (string, error)

InstallationToken returns a cached-or-fresh access token for an installation.

func (*GitHubApp) SetCommitStatus

func (g *GitHubApp) SetCommitStatus(ctx context.Context, token, repo, sha, state, targetURL, description string) error

SetCommitStatus posts a commit status (pending/success/failure) using an installation token.

type Option

type Option func(*GitHubApp)

Option configures a GitHubApp.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the GitHub API base (tests point it at httptest).

func WithClock

func WithClock(c clock.Clock) Option

WithClock overrides the clock (tests use a fake).

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient overrides the HTTP client.

type TokenSource

type TokenSource interface {
	InstallationToken(ctx context.Context, installationID int64) (string, error)
}

TokenSource mints GitHub App installation access tokens for cloning.

type Webhook

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

Webhook is the POST /v1/github/webhook handler.

func NewWebhook

func NewWebhook(apps AppStore, deployer Deployer, dedup Deduper, tokens TokenSource, log *slog.Logger) *Webhook

NewWebhook builds the webhook handler.

func (*Webhook) ServeHTTP

func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Webhook) Wait

func (h *Webhook) Wait()

Wait blocks until all async deploy jobs finish (used by tests).

Jump to

Keyboard shortcuts

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