webhook

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	EventArtifactUploaded   = "artifact.uploaded"
	EventArtifactDeleted    = "artifact.deleted"
	EventArtifactDownloaded = "artifact.downloaded"
	EventRepoCreated        = "repository.created"
	EventRepoDeleted        = "repository.deleted"
)

Event types.

View Source
const (
	// DefaultTimeoutSeconds is the per-delivery timeout of a new webhook.
	DefaultTimeoutSeconds = 30
	// MaxTimeoutSeconds is the largest accepted per-delivery timeout (the
	// dispatcher's HTTP clients enforce the same 30s ceiling).
	MaxTimeoutSeconds = 30
)
View Source
const EventWebhookTest = "webhook.test"

EventWebhookTest is only ever sent directly to one webhook (see DispatchTo); it cannot be subscribed to.

Variables

This section is empty.

Functions

func ArtifactPayload added in v0.2.0

func ArtifactPayload(eventType string, a Artifact) map[string]any

ArtifactPayload builds the JSON payload of an artifact.* event.

func Emit added in v0.2.0

func Emit(ctx context.Context, p Publisher, repoID, eventType string, payload map[string]any)

Emit publishes an event through p, if any. The event is detached from the request's cancellation (a client hanging up right after a successful upload must not lose the event) but bounded by emitTimeout. Failures are logged by the dispatcher and never surface to the caller: an event that cannot be recorded must not fail the operation that produced it.

func IsSubscribableEvent added in v0.2.0

func IsSubscribableEvent(name string) bool

IsSubscribableEvent reports whether name is an event webhooks can subscribe to.

func RepositoryPayload added in v0.2.0

func RepositoryPayload(eventType, name, format, repoType string) map[string]any

RepositoryPayload builds the JSON payload of a repository.* event.

func SubscribableEvents added in v0.2.0

func SubscribableEvents() []string

SubscribableEvents returns the event names a webhook may subscribe to.

Types

type Artifact added in v0.2.0

type Artifact struct {
	Repository string // repository name
	Format     string // repository format (npm, deb, ...)
	Name       string // package / artifact name
	Version    string // version, when the format has one
	Path       string // path or file name within the repository
	SHA256     string // content digest, when known
	Size       int64  // size in bytes, when known
}

Artifact describes the artifact an artifact.* event is about.

type Dispatcher

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

func NewDispatcher

func NewDispatcher(db database.Database, log *logger.Logger) *Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(ctx context.Context, repoID, eventType string, payload map[string]any)

Dispatch queues a webhook event for all matching webhooks. repoID can be empty for global events.

func (*Dispatcher) DispatchTo added in v0.2.0

func (d *Dispatcher) DispatchTo(ctx context.Context, wh *models.Webhook, eventType string, payload map[string]any) error

DispatchTo creates a delivery for exactly one webhook and queues it, regardless of the webhook's event subscriptions or enabled flag.

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start begins processing the delivery queue and retry loop.

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop gracefully shuts down the dispatcher. Safe to call more than once and without a prior Start. In-flight deliveries are cancelled after a grace period.

type Publisher added in v0.2.0

type Publisher interface {
	Dispatch(ctx context.Context, repoID, eventType string, payload map[string]any)
}

Publisher is the slice of *Dispatcher that request handlers use to announce events. Handlers hold it as an optional dependency: a nil Publisher (tests, webhooks not wired) turns every Emit into a no-op.

Jump to

Keyboard shortcuts

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