Help us shape the future of Go! Take the 2026 Go Developer Survey

webhook

package
v0.4.0-beta.12 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package webhook turns git host deliveries into deploy events. Every host is a Provider: it checks the delivery against the deployment's secret and reports what happened (a push to a branch, or a pull request opening, updating or closing) in one shape the agent acts on.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = errors.New("webhook signature or token is invalid")
	ErrUnsupported  = errors.New("webhook event type is not supported")
)

Functions

func NormalizeRepo

func NormalizeRepo(ref string) string

NormalizeRepo reduces a repository address to host/path.

Types

type Event

type Event struct {
	Kind     EventKind
	RepoURLs []string
	Branch   string
	Revision string
	PR       int
}

Event is a delivery reduced to what a deploy needs. RepoURLs lists every address the host gave for the repository, so it can be matched against the one the deployment was created from.

func (*Event) MatchesRepo

func (e *Event) MatchesRepo(ref string) bool

MatchesRepo reports whether any of the event's repository addresses names the same repository as ref, ignoring scheme, credentials, case and a trailing .git. An event with no addresses matches, since the generic hook is bound to one deployment and carries none.

type EventKind

type EventKind string
const (
	EventPush     EventKind = "push"
	EventPROpened EventKind = "pr_opened"
	EventPRSynced EventKind = "pr_synced"
	EventPRClosed EventKind = "pr_closed"
	// EventIgnored is a valid delivery the agent has nothing to do for, such
	// as a tag push, a branch deletion or a label change on a pull request.
	EventIgnored EventKind = "ignored"
)

type Generic

type Generic struct{}

Generic is a deploy hook any CI system can call: X-FlatRun-Token carries the secret and an optional JSON body names the branch or revision to deploy.

func (Generic) Name

func (Generic) Name() string

func (Generic) Parse

func (Generic) Parse(_ http.Header, body []byte) (*Event, error)

func (Generic) Verify

func (Generic) Verify(h http.Header, _ []byte, secret string) error

type GitHub

type GitHub struct{}

GitHub verifies X-Hub-Signature-256 (HMAC-SHA256 of the body with the hook secret) and handles push and pull_request deliveries.

func (GitHub) Name

func (GitHub) Name() string

func (GitHub) Parse

func (GitHub) Parse(h http.Header, body []byte) (*Event, error)

func (GitHub) Verify

func (GitHub) Verify(h http.Header, body []byte, secret string) error

type GitLab

type GitLab struct{}

GitLab compares X-Gitlab-Token with the hook secret and handles push and merge request deliveries.

func (GitLab) Name

func (GitLab) Name() string

func (GitLab) Parse

func (GitLab) Parse(h http.Header, body []byte) (*Event, error)

func (GitLab) Verify

func (GitLab) Verify(h http.Header, _ []byte, secret string) error

type Provider

type Provider interface {
	Name() string
	Verify(h http.Header, body []byte, secret string) error
	Parse(h http.Header, body []byte) (*Event, error)
}

type Registry

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

func DefaultRegistry

func DefaultRegistry() *Registry

func NewRegistry

func NewRegistry(providers ...Provider) *Registry

func (*Registry) Get

func (r *Registry) Get(name string) (Provider, bool)

Jump to

Keyboard shortcuts

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