webhook

package
v1.531.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSessionLimitError

func IsSessionLimitError(err error) bool

IsSessionLimitError checks whether an error represents a session limit being reached.

func SortTriggersByPriority

func SortTriggersByPriority(triggers []entities.WebhookTrigger) []entities.WebhookTrigger

SortTriggersByPriority returns a copy of triggers sorted by priority (lower number = higher priority).

Types

type CreateWebhookRequest

type CreateWebhookRequest struct {
	Name            string                        `json:"name"`
	Scope           entities.ResourceScope        `json:"scope,omitempty"`
	TeamID          string                        `json:"team_id,omitempty"`
	Type            entities.WebhookType          `json:"type"`
	Secret          string                        `json:"secret,omitempty"`
	SignatureHeader string                        `json:"signature_header,omitempty"`
	SignatureType   entities.WebhookSignatureType `json:"signature_type,omitempty"`
	SignaturePrefix string                        `json:"signature_prefix,omitempty"`
	GitHub          *GitHubConfigRequest          `json:"github,omitempty"`
	Triggers        []TriggerRequest              `json:"triggers"`
	SessionConfig   *SessionConfigRequest         `json:"session_config,omitempty"`
	MaxSessions     int                           `json:"max_sessions,omitempty"`
}

CreateWebhookRequest represents the request body for creating a webhook

type DeliveryRecordResponse

type DeliveryRecordResponse struct {
	ID             string `json:"id"`
	ReceivedAt     string `json:"received_at"`
	Status         string `json:"status"`
	MatchedTrigger string `json:"matched_trigger,omitempty"`
	SessionID      string `json:"session_id,omitempty"`
	Error          string `json:"error,omitempty"`
}

DeliveryRecordResponse represents a delivery record in responses

type DryRunResult

type DryRunResult struct {
	InitialMessage string
	Tags           map[string]string
	Environment    map[string]string
	Error          string
}

DryRunResult holds the computed configuration from a dry-run test.

type GitHubCommit

type GitHubCommit struct {
	ID       string              `json:"id"`
	Message  string              `json:"message"`
	Author   *GitHubCommitAuthor `json:"author,omitempty"`
	Added    []string            `json:"added,omitempty"`
	Removed  []string            `json:"removed,omitempty"`
	Modified []string            `json:"modified,omitempty"`
}

GitHubCommit represents a GitHub commit

type GitHubCommitAuthor

type GitHubCommitAuthor struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username,omitempty"`
}

GitHubCommitAuthor represents a commit author

type GitHubConditionsRequest

type GitHubConditionsRequest struct {
	Events       []string `json:"events,omitempty"`
	Actions      []string `json:"actions,omitempty"`
	Branches     []string `json:"branches,omitempty"`
	Repositories []string `json:"repositories,omitempty"`
	Labels       []string `json:"labels,omitempty"`
	Paths        []string `json:"paths,omitempty"`
	BaseBranches []string `json:"base_branches,omitempty"`
	Draft        *bool    `json:"draft,omitempty"`
	Sender       []string `json:"sender,omitempty"`
}

GitHubConditionsRequest represents GitHub-specific conditions in requests

type GitHubConditionsResponse

type GitHubConditionsResponse struct {
	Events       []string `json:"events,omitempty"`
	Actions      []string `json:"actions,omitempty"`
	Branches     []string `json:"branches,omitempty"`
	Repositories []string `json:"repositories,omitempty"`
	Labels       []string `json:"labels,omitempty"`
	Paths        []string `json:"paths,omitempty"`
	BaseBranches []string `json:"base_branches,omitempty"`
	Draft        *bool    `json:"draft,omitempty"`
	Sender       []string `json:"sender,omitempty"`
}

GitHubConditionsResponse represents GitHub-specific conditions in responses

type GitHubConfigRequest

type GitHubConfigRequest struct {
	EnterpriseURL       string   `json:"enterprise_url,omitempty"`
	AllowedEvents       []string `json:"allowed_events,omitempty"`
	AllowedRepositories []string `json:"allowed_repositories,omitempty"`
}

GitHubConfigRequest represents GitHub-specific configuration in requests

type GitHubConfigResponse

type GitHubConfigResponse struct {
	EnterpriseURL       string   `json:"enterprise_url,omitempty"`
	AllowedEvents       []string `json:"allowed_events,omitempty"`
	AllowedRepositories []string `json:"allowed_repositories,omitempty"`
}

GitHubConfigResponse represents GitHub-specific configuration in responses

type GitHubIssue

type GitHubIssue struct {
	Number  int           `json:"number"`
	Title   string        `json:"title"`
	Body    string        `json:"body,omitempty"`
	State   string        `json:"state"`
	HTMLURL string        `json:"html_url"`
	User    *GitHubUser   `json:"user,omitempty"`
	Labels  []GitHubLabel `json:"labels,omitempty"`
}

GitHubIssue represents a GitHub issue

type GitHubLabel

type GitHubLabel struct {
	Name  string `json:"name"`
	Color string `json:"color,omitempty"`
}

GitHubLabel represents a GitHub label

type GitHubPayload

type GitHubPayload struct {
	Action     string            `json:"action,omitempty"`
	Ref        string            `json:"ref,omitempty"`
	Repository *GitHubRepository `json:"repository,omitempty"`
	Sender     *GitHubUser       `json:"sender,omitempty"`

	// Pull request specific
	PullRequest *GitHubPullRequest `json:"pull_request,omitempty"`

	// Issue specific
	Issue *GitHubIssue `json:"issue,omitempty"`

	// Push specific
	Commits    []GitHubCommit `json:"commits,omitempty"`
	HeadCommit *GitHubCommit  `json:"head_commit,omitempty"`

	// Raw payload for template rendering
	Raw map[string]interface{} `json:"-"`
}

GitHubPayload represents relevant fields from a GitHub webhook payload

type GitHubPullRequest

type GitHubPullRequest struct {
	Number   int           `json:"number"`
	Title    string        `json:"title"`
	Body     string        `json:"body,omitempty"`
	State    string        `json:"state"`
	Draft    bool          `json:"draft"`
	HTMLURL  string        `json:"html_url"`
	User     *GitHubUser   `json:"user,omitempty"`
	Head     *GitHubRef    `json:"head,omitempty"`
	Base     *GitHubRef    `json:"base,omitempty"`
	Labels   []GitHubLabel `json:"labels,omitempty"`
	Merged   bool          `json:"merged"`
	MergedAt string        `json:"merged_at,omitempty"`
}

GitHubPullRequest represents a GitHub pull request

type GitHubRef

type GitHubRef struct {
	Ref  string            `json:"ref"`
	SHA  string            `json:"sha"`
	Repo *GitHubRepository `json:"repo,omitempty"`
}

GitHubRef represents a git reference

type GitHubRepository

type GitHubRepository struct {
	FullName      string      `json:"full_name"`
	Name          string      `json:"name"`
	Owner         *GitHubUser `json:"owner,omitempty"`
	DefaultBranch string      `json:"default_branch,omitempty"`
	HTMLURL       string      `json:"html_url,omitempty"`
	CloneURL      string      `json:"clone_url,omitempty"`
}

GitHubRepository represents a GitHub repository

type GitHubUser

type GitHubUser struct {
	Login     string `json:"login"`
	ID        int64  `json:"id"`
	AvatarURL string `json:"avatar_url,omitempty"`
	HTMLURL   string `json:"html_url,omitempty"`
}

GitHubUser represents a GitHub user

type Handlers

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

Handlers is an adapter that combines webhook controllers and implements app.CustomHandler interface

func NewHandlers

func NewHandlers(repo repositories.WebhookRepository, sessionManager repositories.SessionManager, baseURL string, memoryRepo repositories.MemoryRepository, sessionProfileRepo repositories.SessionProfileRepository) *Handlers

NewHandlers creates a new Handlers instance

func (*Handlers) GetName

func (h *Handlers) GetName() string

GetName returns the name of this handler for logging

func (*Handlers) RegisterRoutes

func (h *Handlers) RegisterRoutes(e *echo.Echo) error

RegisterRoutes registers webhook management routes

func (*Handlers) TriggerWebhook

func (h *Handlers) TriggerWebhook(ctx echo.Context) error

TriggerWebhook handles POST /webhooks/:id/trigger

type SessionConfigRequest

type SessionConfigRequest struct {
	Environment            map[string]string       `json:"environment,omitempty"`
	Tags                   map[string]string       `json:"tags,omitempty"`
	InitialMessageTemplate string                  `json:"initial_message_template,omitempty"`
	ReuseMessageTemplate   string                  `json:"reuse_message_template,omitempty"`
	Params                 *entities.SessionParams `json:"params,omitempty"`
	ReuseSession           bool                    `json:"reuse_session,omitempty"`
	MountPayload           bool                    `json:"mount_payload,omitempty"`
	SessionProfileID       string                  `json:"session_profile_id,omitempty"`
}

SessionConfigRequest represents session configuration in requests

type SessionConfigResponse

type SessionConfigResponse struct {
	Environment            map[string]string      `json:"environment,omitempty"`
	Tags                   map[string]string      `json:"tags,omitempty"`
	InitialMessageTemplate string                 `json:"initial_message_template,omitempty"`
	ReuseMessageTemplate   string                 `json:"reuse_message_template,omitempty"`
	Params                 *SessionParamsResponse `json:"params,omitempty"`
	ReuseSession           bool                   `json:"reuse_session,omitempty"`
	MountPayload           bool                   `json:"mount_payload,omitempty"`
	SessionProfileID       string                 `json:"session_profile_id,omitempty"`
}

SessionConfigResponse represents session configuration in responses

type SessionCreationParams

type SessionCreationParams struct {
	Webhook        *entities.Webhook
	Trigger        *entities.WebhookTrigger
	Payload        map[string]interface{}
	RawPayload     []byte
	Tags           map[string]string
	DefaultMessage string
	MountPayload   bool
}

SessionCreationParams holds all parameters needed to create a session from a webhook delivery.

type SessionParamsResponse

type SessionParamsResponse struct {
	GithubToken string `json:"github_token,omitempty"`
	AgentType   string `json:"agent_type,omitempty"`
	Oneshot     bool   `json:"oneshot,omitempty"`
	AuthProxy   *bool  `json:"auth_proxy,omitempty"`
}

SessionParamsResponse represents session params in responses

type TriggerConditionsRequest

type TriggerConditionsRequest struct {
	GitHub     *GitHubConditionsRequest `json:"github,omitempty"`
	GoTemplate string                   `json:"go_template,omitempty"`
}

TriggerConditionsRequest represents trigger conditions in requests

type TriggerConditionsResponse

type TriggerConditionsResponse struct {
	GitHub     *GitHubConditionsResponse `json:"github,omitempty"`
	GoTemplate string                    `json:"go_template,omitempty"`
}

TriggerConditionsResponse represents trigger conditions in responses

type TriggerMatchedTriggerInfo

type TriggerMatchedTriggerInfo struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

TriggerMatchedTriggerInfo contains information about a matched trigger

type TriggerRequest

type TriggerRequest struct {
	ID            string                   `json:"id,omitempty"`
	Name          string                   `json:"name"`
	Priority      int                      `json:"priority"`
	Enabled       bool                     `json:"enabled"`
	Conditions    TriggerConditionsRequest `json:"conditions"`
	SessionConfig *SessionConfigRequest    `json:"session_config,omitempty"`
	StopOnMatch   bool                     `json:"stop_on_match"`
}

TriggerRequest represents a trigger in requests

type TriggerResponse

type TriggerResponse struct {
	ID            string                    `json:"id"`
	Name          string                    `json:"name"`
	Priority      int                       `json:"priority"`
	Enabled       bool                      `json:"enabled"`
	Conditions    TriggerConditionsResponse `json:"conditions"`
	SessionConfig *SessionConfigResponse    `json:"session_config,omitempty"`
	StopOnMatch   bool                      `json:"stop_on_match"`
}

TriggerResponse represents a trigger in responses

type TriggerWebhookRequest

type TriggerWebhookRequest struct {
	Payload map[string]interface{} `json:"payload"`         // The test payload JSON
	Event   string                 `json:"event,omitempty"` // For GitHub webhooks: the event type (e.g., "push", "pull_request")
	DryRun  bool                   `json:"dry_run"`         // If true, only evaluate triggers without creating a session
}

TriggerWebhookRequest represents the request body for triggering a webhook with a test payload

type TriggerWebhookResponse

type TriggerWebhookResponse struct {
	Matched        bool                       `json:"matched"`                   // Whether any trigger matched
	MatchedTrigger *TriggerMatchedTriggerInfo `json:"matched_trigger,omitempty"` // Info about the matched trigger
	SessionID      string                     `json:"session_id,omitempty"`      // Set when dry_run=false and session was created
	SessionReused  bool                       `json:"session_reused,omitempty"`  // Whether an existing session was reused
	DryRun         bool                       `json:"dry_run"`                   // Echoes back the dry_run flag
	InitialMessage string                     `json:"initial_message,omitempty"` // The rendered initial message (in dry_run mode)
	Tags           map[string]string          `json:"tags,omitempty"`            // The computed tags (in dry_run mode)
	Environment    map[string]string          `json:"environment,omitempty"`     // The computed environment (in dry_run mode)
	Error          string                     `json:"error,omitempty"`           // Any error encountered during evaluation
}

TriggerWebhookResponse represents the response for a webhook trigger test

type UpdateWebhookRequest

type UpdateWebhookRequest struct {
	Name            *string                        `json:"name,omitempty"`
	Status          *entities.WebhookStatus        `json:"status,omitempty"`
	Secret          *string                        `json:"secret,omitempty"`
	SignatureHeader *string                        `json:"signature_header,omitempty"`
	SignatureType   *entities.WebhookSignatureType `json:"signature_type,omitempty"`
	SignaturePrefix *string                        `json:"signature_prefix,omitempty"`
	GitHub          *GitHubConfigRequest           `json:"github,omitempty"`
	Triggers        []TriggerRequest               `json:"triggers,omitempty"`
	SessionConfig   *SessionConfigRequest          `json:"session_config,omitempty"`
	MaxSessions     *int                           `json:"max_sessions,omitempty"`
}

UpdateWebhookRequest represents the request body for updating a webhook

type WebhookController

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

WebhookController handles webhook management HTTP requests

func NewWebhookController

func NewWebhookController(repo repositories.WebhookRepository) *WebhookController

NewWebhookController creates a new webhook controller

func (*WebhookController) CreateWebhook

func (c *WebhookController) CreateWebhook(ctx echo.Context) error

CreateWebhook handles POST /webhooks

func (*WebhookController) DeleteWebhook

func (c *WebhookController) DeleteWebhook(ctx echo.Context) error

DeleteWebhook handles DELETE /webhooks/:id

func (*WebhookController) GetName

func (c *WebhookController) GetName() string

GetName returns the name of this controller for logging

func (*WebhookController) GetWebhook

func (c *WebhookController) GetWebhook(ctx echo.Context) error

GetWebhook handles GET /webhooks/:id

func (*WebhookController) ListWebhooks

func (c *WebhookController) ListWebhooks(ctx echo.Context) error

ListWebhooks handles GET /webhooks

func (*WebhookController) RegenerateSecret

func (c *WebhookController) RegenerateSecret(ctx echo.Context) error

RegenerateSecret handles POST /webhooks/:id/regenerate-secret

func (*WebhookController) Repo

Repo returns the webhook repository for external access.

func (*WebhookController) SetBaseURL

func (c *WebhookController) SetBaseURL(baseURL string)

SetBaseURL sets the base URL for webhook URLs

func (*WebhookController) UpdateWebhook

func (c *WebhookController) UpdateWebhook(ctx echo.Context) error

UpdateWebhook handles PUT /webhooks/:id

func (*WebhookController) UserCanAccessWebhook

func (c *WebhookController) UserCanAccessWebhook(ctx echo.Context, webhook *entities.Webhook) bool

UserCanAccessWebhook checks if the current user can access the webhook.

type WebhookCustomController

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

WebhookCustomController handles custom webhook reception

func NewWebhookCustomController

func NewWebhookCustomController(
	repo repositories.WebhookRepository,
	sessionManager repositories.SessionManager,
	memoryRepo repositories.MemoryRepository,
	sessionProfileRepo repositories.SessionProfileRepository,
) *WebhookCustomController

NewWebhookCustomController creates a new custom webhook controller

func (*WebhookCustomController) BuildCustomTagsForTest

func (c *WebhookCustomController) BuildCustomTagsForTest(
	webhook *entities.Webhook,
	trigger *entities.WebhookTrigger,
) map[string]string

BuildCustomTagsForTest builds custom webhook metadata tags for a test payload.

func (*WebhookCustomController) BuildDefaultMessageForTest

func (c *WebhookCustomController) BuildDefaultMessageForTest(payload map[string]interface{}) string

BuildDefaultMessageForTest builds a default message for a test payload.

func (*WebhookCustomController) GetName

func (c *WebhookCustomController) GetName() string

GetName returns the name of this controller for logging

func (*WebhookCustomController) HandleCustomWebhook

func (c *WebhookCustomController) HandleCustomWebhook(ctx echo.Context) error

HandleCustomWebhook handles POST /hooks/custom/:id

func (*WebhookCustomController) MatchTriggersForTest

func (c *WebhookCustomController) MatchTriggersForTest(
	triggers []entities.WebhookTrigger,
	payload map[string]interface{},
) *entities.WebhookTrigger

MatchTriggersForTest evaluates triggers against a test payload.

func (*WebhookCustomController) SessionService

func (c *WebhookCustomController) SessionService() *WebhookSessionService

SessionService returns the session service for external access.

type WebhookGitHubController

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

WebhookGitHubController handles GitHub webhook reception

func NewWebhookGitHubController

func NewWebhookGitHubController(repo repositories.WebhookRepository, sessionManager repositories.SessionManager, memoryRepo repositories.MemoryRepository, sessionProfileRepo repositories.SessionProfileRepository) *WebhookGitHubController

NewWebhookGitHubController creates a new GitHub webhook controller

func (*WebhookGitHubController) BuildDefaultInitialMessageForTest

func (c *WebhookGitHubController) BuildDefaultInitialMessageForTest(event string, payload *GitHubPayload) string

BuildDefaultInitialMessageForTest builds a default initial message for a test payload.

func (*WebhookGitHubController) BuildGitHubTagsForTest

func (c *WebhookGitHubController) BuildGitHubTagsForTest(
	webhook *entities.Webhook,
	trigger *entities.WebhookTrigger,
	event string,
	payload *GitHubPayload,
) map[string]string

BuildGitHubTagsForTest builds GitHub-specific metadata tags for a test payload.

func (*WebhookGitHubController) GetName

func (c *WebhookGitHubController) GetName() string

GetName returns the name of this controller for logging

func (*WebhookGitHubController) HandleGitHubWebhook

func (c *WebhookGitHubController) HandleGitHubWebhook(ctx echo.Context) error

HandleGitHubWebhook handles POST /hooks/github/:id

func (*WebhookGitHubController) MatchTriggersForTest

func (c *WebhookGitHubController) MatchTriggersForTest(
	triggers []entities.WebhookTrigger,
	event string,
	payload *GitHubPayload,
) *entities.WebhookTrigger

MatchTriggersForTest evaluates triggers against a test payload. This reuses the same matching logic as HandleGitHubWebhook but without signature verification or HTTP context dependency.

func (*WebhookGitHubController) SessionService

func (c *WebhookGitHubController) SessionService() *WebhookSessionService

SessionService returns the session service for external access.

type WebhookResponse

type WebhookResponse struct {
	ID              string                        `json:"id"`
	Name            string                        `json:"name"`
	UserID          string                        `json:"user_id"`
	Scope           entities.ResourceScope        `json:"scope,omitempty"`
	TeamID          string                        `json:"team_id,omitempty"`
	Status          entities.WebhookStatus        `json:"status"`
	Type            entities.WebhookType          `json:"type"`
	Secret          string                        `json:"secret"`
	SignatureHeader string                        `json:"signature_header,omitempty"`
	SignatureType   entities.WebhookSignatureType `json:"signature_type,omitempty"`
	SignaturePrefix string                        `json:"signature_prefix,omitempty"`
	WebhookURL      string                        `json:"webhook_url"`
	GitHub          *GitHubConfigResponse         `json:"github,omitempty"`
	Triggers        []TriggerResponse             `json:"triggers"`
	SessionConfig   *SessionConfigResponse        `json:"session_config,omitempty"`
	MaxSessions     int                           `json:"max_sessions"`
	CreatedAt       string                        `json:"created_at"`
	UpdatedAt       string                        `json:"updated_at"`
	LastDelivery    *DeliveryRecordResponse       `json:"last_delivery,omitempty"`
	DeliveryCount   int64                         `json:"delivery_count"`
}

WebhookResponse represents the response for a webhook

type WebhookSessionService

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

WebhookSessionService encapsulates common logic shared between GitHub and Custom webhook controllers: session creation, session reuse, template rendering, trigger sorting, session limits, and delivery recording.

func NewWebhookSessionService

func NewWebhookSessionService(repo repositories.WebhookRepository, sessionManager repositories.SessionManager, memoryRepo repositories.MemoryRepository, sessionProfileRepo repositories.SessionProfileRepository) *WebhookSessionService

NewWebhookSessionService creates a new WebhookSessionService.

func (*WebhookSessionService) CreateSessionFromWebhook

func (s *WebhookSessionService) CreateSessionFromWebhook(ctx context.Context, params SessionCreationParams) (string, bool, error)

CreateSessionFromWebhook creates or reuses a session based on webhook and trigger configuration. Returns sessionID, sessionReused flag, and error.

The ctx parameter is a plain context.Context (not echo.Context) so that this method can be called from background goroutines or unit tests without an HTTP request.

func (*WebhookSessionService) DryRunSessionConfig

func (s *WebhookSessionService) DryRunSessionConfig(params SessionCreationParams) (*DryRunResult, error)

DryRunSessionConfig evaluates all template rendering and config merging without creating a session. Returns the computed configuration.

func (*WebhookSessionService) RecordDelivery

func (s *WebhookSessionService) RecordDelivery(ctx context.Context, webhookID, deliveryID string, status entities.DeliveryStatus, trigger *entities.WebhookTrigger, sessionID string, sessionReused bool, deliveryErr error)

RecordDelivery records a webhook delivery event.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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