webhook

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package webhook provides HTTP webhook server for receiving events from external systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Provider   string                 `json:"provider"`
	EventType  string                 `json:"event_type"`
	ExternalID string                 `json:"external_id"`
	TaskID     string                 `json:"task_id"`
	Status     planning.TaskStatus    `json:"status,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	Timestamp  time.Time              `json:"timestamp"`
}

Event represents a webhook event from an external system.

type EventProcessor

type EventProcessor interface {
	ProcessEvent(ctx context.Context, event *Event) error
}

EventProcessor handles incoming webhook events.

type GitHubHandler

type GitHubHandler struct{}

GitHubHandler handles GitHub webhooks.

func NewGitHubHandler

func NewGitHubHandler() *GitHubHandler

NewGitHubHandler creates a new GitHub webhook handler.

func (*GitHubHandler) ParseEvent

func (h *GitHubHandler) ParseEvent(r *http.Request) (*Event, error)

ParseEvent parses a GitHub webhook request into an Event.

func (*GitHubHandler) Provider

func (h *GitHubHandler) Provider() string

Provider returns the provider name.

func (*GitHubHandler) ValidateSignature

func (h *GitHubHandler) ValidateSignature(r *http.Request, secret string) bool

ValidateSignature validates the GitHub webhook signature.

type GitHubIssuePayload

type GitHubIssuePayload struct {
	Action string `json:"action"`
	Issue  struct {
		Number   int    `json:"number"`
		Title    string `json:"title"`
		Body     string `json:"body"`
		State    string `json:"state"`
		HTMLURL  string `json:"html_url"`
		Assignee *struct {
			Login string `json:"login"`
		} `json:"assignee"`
	} `json:"issue"`
	Repository struct {
		FullName string `json:"full_name"`
	} `json:"repository"`
}

GitHubIssuePayload represents a GitHub issue webhook payload.

type Handler

type Handler interface {
	// Provider returns the name of the provider (e.g., "github", "jira", "linear").
	Provider() string

	// ValidateSignature validates the webhook signature to ensure authenticity.
	ValidateSignature(r *http.Request, secret string) bool

	// ParseEvent parses the HTTP request into a webhook Event.
	ParseEvent(r *http.Request) (*Event, error)
}

Handler processes webhook events from a specific provider.

type JiraHandler

type JiraHandler struct{}

JiraHandler handles Jira webhooks.

func NewJiraHandler

func NewJiraHandler() *JiraHandler

NewJiraHandler creates a new Jira webhook handler.

func (*JiraHandler) ParseEvent

func (h *JiraHandler) ParseEvent(r *http.Request) (*Event, error)

ParseEvent parses a Jira webhook request into an Event.

func (*JiraHandler) Provider

func (h *JiraHandler) Provider() string

Provider returns the provider name.

func (*JiraHandler) ValidateSignature

func (h *JiraHandler) ValidateSignature(r *http.Request, secret string) bool

ValidateSignature validates the Jira webhook. Jira Cloud uses a shared secret that must be validated via the webhook URL itself. For Jira Server/Data Center, you might use IP whitelisting or other methods. This implementation trusts the configured secret as a simple token check.

type JiraIssuePayload

type JiraIssuePayload struct {
	WebhookEvent string `json:"webhookEvent"`
	Issue        struct {
		ID     string `json:"id"`
		Key    string `json:"key"`
		Self   string `json:"self"`
		Fields struct {
			Summary     string `json:"summary"`
			Description string `json:"description"`
			Status      struct {
				Name           string `json:"name"`
				StatusCategory struct {
					Key string `json:"key"`
				} `json:"statusCategory"`
			} `json:"status"`
			Assignee *struct {
				DisplayName string `json:"displayName"`
			} `json:"assignee"`
		} `json:"fields"`
	} `json:"issue"`
	Changelog *struct {
		Items []struct {
			Field      string `json:"field"`
			FromString string `json:"fromString"`
			ToString   string `json:"toString"`
		} `json:"items"`
	} `json:"changelog"`
}

JiraIssuePayload represents a Jira issue webhook payload.

type LinearHandler

type LinearHandler struct{}

LinearHandler handles Linear webhooks.

func NewLinearHandler

func NewLinearHandler() *LinearHandler

NewLinearHandler creates a new Linear webhook handler.

func (*LinearHandler) ParseEvent

func (h *LinearHandler) ParseEvent(r *http.Request) (*Event, error)

ParseEvent parses a Linear webhook request into an Event.

func (*LinearHandler) Provider

func (h *LinearHandler) Provider() string

Provider returns the provider name.

func (*LinearHandler) ValidateSignature

func (h *LinearHandler) ValidateSignature(r *http.Request, secret string) bool

ValidateSignature validates the Linear webhook signature. Linear uses HMAC-SHA256 with the webhook secret.

type LinearPayload

type LinearPayload struct {
	Action         string `json:"action"`
	Type           string `json:"type"`
	CreatedAt      string `json:"createdAt"`
	OrganizationID string `json:"organizationId"`
	Data           struct {
		ID          string `json:"id"`
		Identifier  string `json:"identifier"`
		Title       string `json:"title"`
		Description string `json:"description"`
		URL         string `json:"url"`
		State       struct {
			ID   string `json:"id"`
			Name string `json:"name"`
			Type string `json:"type"` // triage, backlog, unstarted, started, completed, canceled
		} `json:"state"`
		Assignee *struct {
			ID   string `json:"id"`
			Name string `json:"name"`
		} `json:"assignee"`
		Team struct {
			ID  string `json:"id"`
			Key string `json:"key"`
		} `json:"team"`
	} `json:"data"`
	UpdatedFrom *struct {
		StateID string `json:"stateId"`
	} `json:"updatedFrom"`
}

LinearPayload represents a Linear webhook payload.

type Server

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

Server is the HTTP webhook server.

func NewServer

func NewServer(addr string, processor EventProcessor) *Server

NewServer creates a new webhook server.

func (*Server) RecentEvents

func (s *Server) RecentEvents() []Event

RecentEvents returns recent webhook events (for debugging).

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(handler Handler)

RegisterHandler adds a webhook handler for a specific provider.

func (*Server) SetSecret

func (s *Server) SetSecret(provider, secret string)

SetSecret sets the webhook secret for a provider.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start() error

Start starts the webhook server.

Jump to

Keyboard shortcuts

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