Documentation
¶
Index ¶
- Constants
- func ArtifactPayload(eventType string, a Artifact) map[string]any
- func Emit(ctx context.Context, p Publisher, repoID, eventType string, ...)
- func IsSubscribableEvent(name string) bool
- func RepositoryPayload(eventType, name, format, repoType string) map[string]any
- func SubscribableEvents() []string
- type Artifact
- type Dispatcher
- type Publisher
Constants ¶
const ( EventArtifactUploaded = "artifact.uploaded" EventArtifactDeleted = "artifact.deleted" EventArtifactDownloaded = "artifact.downloaded" EventRepoCreated = "repository.created" EventRepoDeleted = "repository.deleted" )
Event types.
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 )
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
ArtifactPayload builds the JSON payload of an artifact.* event.
func Emit ¶ added in v0.2.0
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
IsSubscribableEvent reports whether name is an event webhooks can subscribe to.
func RepositoryPayload ¶ added in v0.2.0
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.