webhook

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLabelManagerAdapter

func NewLabelManagerAdapter(manager labels.LabelManager, client *github.Client) *labelManagerAdapter

NewLabelManagerAdapter creates a new label manager adapter.

func NewQualificationEngineAdapter

func NewQualificationEngineAdapter(engine *qualification.QualificationEngine) *qualificationEngineAdapter

NewQualificationEngineAdapter creates a new qualification engine adapter.

Types

type EventHandler

type EventHandler interface {
	// HandleEvent processes a GitHub webhook event.
	// Returns an error if processing fails and should return HTTP 500.
	HandleEvent(ctx context.Context, event *github.WebhookEvent) error

	// SupportedEventType returns the GitHub event type this handler supports.
	// Examples: "pull_request", "push", "issues"
	SupportedEventType() string
}

EventHandler defines the interface for handling specific GitHub webhook events. Each event type (pull_request, push, etc.) should have its own handler implementation.

type LabelManager

type LabelManager interface {
	// SyncLabels synchronizes PR labels between GitHub and CRD status
	// This method adapts the actual LabelManager's SyncToGitHub method
	SyncLabels(ctx context.Context, owner, repo string, prNumber int) error
}

LabelManager defines the interface for managing GitHub PR labels. This interface allows for mocking in tests and adapts the actual LabelManager.

type MockEventHandler

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

MockEventHandler is a test implementation of EventHandler for testing purposes.

func NewMockEventHandler

func NewMockEventHandler(eventType string, handleFunc func(ctx context.Context, event *github.WebhookEvent) error) *MockEventHandler

NewMockEventHandler creates a new mock event handler for testing.

func (*MockEventHandler) CallCount

func (m *MockEventHandler) CallCount() int

CallCount returns the number of times HandleEvent was called.

func (*MockEventHandler) HandleEvent

func (m *MockEventHandler) HandleEvent(ctx context.Context, event *github.WebhookEvent) error

HandleEvent implements EventHandler interface.

func (*MockEventHandler) LastEvent

func (m *MockEventHandler) LastEvent() *github.WebhookEvent

LastEvent returns the last event passed to HandleEvent.

func (*MockEventHandler) Reset

func (m *MockEventHandler) Reset()

Reset resets the mock handler state for reuse in tests.

func (*MockEventHandler) SupportedEventType

func (m *MockEventHandler) SupportedEventType() string

SupportedEventType implements EventHandler interface.

type PullRequestEventHandler

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

PullRequestEventHandler handles GitHub pull_request webhook events. It creates/updates PullRequestTracker CRDs and triggers qualification.

func NewPullRequestEventHandler

func NewPullRequestEventHandler(
	kubeClient client.Client,
	labelManager LabelManager,
	qualificationEngine QualificationEngine,
	log *logger.Logger,
) *PullRequestEventHandler

NewPullRequestEventHandler creates a new pull request event handler.

func (*PullRequestEventHandler) HandleEvent

func (h *PullRequestEventHandler) HandleEvent(ctx context.Context, event *github.WebhookEvent) error

HandleEvent processes a pull_request webhook event.

func (*PullRequestEventHandler) SupportedEventType

func (h *PullRequestEventHandler) SupportedEventType() string

SupportedEventType returns the event type this handler supports.

type QualificationEngine

type QualificationEngine interface {
	// QualifyPR performs qualification checks on a PR
	// This method adapts the actual validator's Validate method
	QualifyPR(ctx context.Context, pr github.PullRequest) (bool, string, error)
}

QualificationEngine defines the interface for PR qualification. This interface allows for mocking in tests and adapts the actual qualification system.

type Router

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

Router dispatches GitHub webhook events to appropriate handlers. It parses incoming webhook requests, validates signatures, and routes events.

func NewRouter

func NewRouter(secret string, log *logger.Logger) *Router

NewRouter creates a new webhook event router with the given secret. The secret is used for HMAC signature validation of webhook payloads.

func (*Router) GetRegisteredEventTypes

func (r *Router) GetRegisteredEventTypes() []string

GetRegisteredEventTypes returns a list of all registered event types. Useful for debugging and configuration validation.

func (*Router) HandlerCount

func (r *Router) HandlerCount() int

HandlerCount returns the number of registered handlers. Useful for testing and metrics.

func (*Router) RegisterHandler

func (r *Router) RegisterHandler(handler EventHandler)

RegisterHandler registers an event handler for a specific event type. If a handler for the event type already exists, it will be replaced.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler interface to handle webhook requests. This method parses webhook events, validates signatures, and routes to handlers.

func (*Router) UnregisterHandler

func (r *Router) UnregisterHandler(eventType string) bool

UnregisterHandler removes the handler for the specified event type. Returns true if a handler was removed, false if no handler was registered.

Jump to

Keyboard shortcuts

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