ghook

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ghook is a small GitHub webhook receiver that maps pull-request lifecycle events to pgbranch branches (branch-per-PR): opened/reopened → ensure branch pr-<number> exists, synchronize → ensure (and optionally reset), closed → destroy. It talks to branchd through internal/apiclient and, when a GitHub token is configured, posts a one-time connect-info comment on the PR.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	WebhookSecret string   // HMAC key for X-Hub-Signature-256 (required)
	Source        string   // pgbranch source to branch from (required)
	TTLSeconds    int      // branch TTL passed on create (0 = no TTL)
	ResetOnPush   bool     // synchronize resets the branch when true
	Repos         []string // "owner/name" allow-list; empty allows all
	ProxyHost     string   // host[:port] of the pgbranch proxy, for comments
}

Config is the static service configuration (see cmd/pgbranch-github for the GHOOK_* environment mapping).

type EnvConfig

type EnvConfig struct {
	Config
	Listen         string // GHOOK_LISTEN, default :8080
	PGBranchServer string // GHOOK_PGBRANCH_SERVER (required)
	PGBranchToken  string // GHOOK_PGBRANCH_TOKEN
	GitHubToken    string // GHOOK_GITHUB_TOKEN (empty = no PR comments)
	GitHubAPI      string // GHOOK_GITHUB_API, default https://api.github.com
}

EnvConfig is the full GHOOK_* environment configuration for the pgbranch-github binary: the service Config plus wiring (listen address, pgbranch server, GitHub credentials).

func LoadEnv

func LoadEnv(getenv func(string) string) (*EnvConfig, error)

LoadEnv builds the configuration from getenv (os.Getenv in production, a map lookup in tests) and validates required values.

type GitHub

type GitHub struct {
	BaseURL string // e.g. https://api.github.com (overridable for tests)
	Token   string
	HTTP    *http.Client
}

GitHub is a minimal REST client for the one thing this service does on GitHub: a single connect-info comment per pull request. No SDK dependency.

func (*GitHub) EnsureComment

func (g *GitHub) EnsureComment(ctx context.Context, repo string, number int, body string) error

EnsureComment posts body as an issue comment on repo#number unless a comment carrying the pgbranch marker already exists. Only the first page (100 comments) is checked — at worst a busy PR gets a duplicate comment.

type Service

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

func New

func New(cfg Config, pg *apiclient.Client, gh *GitHub, log *slog.Logger) *Service

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler returns the HTTP surface: POST /webhook and GET /healthz.

Jump to

Keyboard shortcuts

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