github

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package github handles GitHub push webhook payloads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Added    []string `json:"added"`
	Removed  []string `json:"removed"`
	Modified []string `json:"modified"`
}

type DedupeCache

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

Tracks recently seen GitHub delivery IDs to prevent a webhook from being processed more than once.

func NewDedupeCache

func NewDedupeCache(capacity int) *DedupeCache

Creates a cache that remembers the last capacity delivery IDs.

func (*DedupeCache) Seen

func (cache *DedupeCache) Seen(id string) bool

type Handler

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

An http.Handler that accepts GitHub push webhooks on any path it is registered under. It validates the HMAC-SHA256 signature, deduplicates deliveries, parses the push payload, and dispatches asynchronously to onPush.

func NewHandler

func NewHandler(
	appCtx context.Context,
	secretFile string,
	dedupe *DedupeCache,
	onPush func(context.Context, webhook.PushEvent),
	logger *slog.Logger,
) (*Handler, error)

func (*Handler) ServeHTTP

func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PushPayload

type PushPayload struct {
	Ref        string     `json:"ref"`
	After      string     `json:"after"`
	Repository Repository `json:"repository"`
	Commits    []Commit   `json:"commits"`
}

func ParsePushPayload

func ParsePushPayload(data []byte) (*PushPayload, error)

func (*PushPayload) Branch

func (payload *PushPayload) Branch() string

func (*PushPayload) ChangedFiles

func (payload *PushPayload) ChangedFiles() []string

type Repository

type Repository struct {
	FullName string `json:"full_name"`
}

Jump to

Keyboard shortcuts

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