webhook

package
v0.0.0-...-b41f85f Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// WebhookRequestsTotal counts total webhook requests received
	WebhookRequestsTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "pr_cli_webhook_requests_total",
			Help: "Total number of webhook requests received",
		},
		[]string{"platform", "event_type", "status"},
	)

	// WebhookProcessingDuration tracks webhook processing duration
	WebhookProcessingDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "pr_cli_webhook_processing_duration_seconds",
			Help:    "Webhook processing duration in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"platform", "command"},
	)

	// CommandExecutionTotal counts total commands executed
	CommandExecutionTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "pr_cli_command_execution_total",
			Help: "Total number of commands executed",
		},
		[]string{"platform", "command", "status"},
	)

	// QueueSize tracks current job queue size
	QueueSize = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "pr_cli_queue_size",
			Help: "Current size of the webhook job queue",
		},
	)

	// ActiveWorkers tracks number of active workers
	ActiveWorkers = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "pr_cli_active_workers",
			Help: "Number of active worker goroutines",
		},
	)

	// PREventProcessingTotal counts pull_request events processed
	PREventProcessingTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "pr_cli_pr_event_total",
			Help: "Total number of pull_request events processed",
		},
		[]string{"platform", "action", "status"},
	)

	// WorkflowDispatchTotal counts workflow dispatch triggers
	WorkflowDispatchTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "pr_cli_workflow_dispatch_total",
			Help: "Total number of workflow dispatch triggers",
		},
		[]string{"platform", "workflow", "status"},
	)
)

Functions

func ValidateGitHubSignature

func ValidateGitHubSignature(payload []byte, signature string, secret string) error

ValidateGitHubSignature validates the GitHub webhook signature

func ValidateGitLabToken

func ValidateGitLabToken(token string, secret string) error

ValidateGitLabToken validates the GitLab webhook token

func ValidateRepository

func ValidateRepository(owner, repo string, allowedRepos []string) error

ValidateRepository checks if the repository is allowed

func ValidateWebhookEvent

func ValidateWebhookEvent(event *WebhookEvent) error

ValidateWebhookEvent performs basic validation on the webhook event

Types

type Comment

type Comment struct {
	ID   int64
	Body string
	User string
}

Comment represents a comment

type GitHubPullRequestPayload

type GitHubPullRequestPayload struct {
	Action      string `json:"action"`
	Number      int    `json:"number"`
	PullRequest struct {
		Number int    `json:"number"`
		State  string `json:"state"`
		Title  string `json:"title"`
		Draft  bool   `json:"draft"`
		User   struct {
			Login string `json:"login"`
		} `json:"user"`
		Head struct {
			Ref string `json:"ref"`
			SHA string `json:"sha"`
		} `json:"head"`
		Base struct {
			Ref string `json:"ref"`
		} `json:"base"`
	} `json:"pull_request"`
	Repository struct {
		Name  string `json:"name"`
		Owner struct {
			Login string `json:"login"`
		} `json:"owner"`
		HTMLURL string `json:"html_url"`
	} `json:"repository"`
	Sender struct {
		Login string `json:"login"`
	} `json:"sender"`
}

GitHubPullRequestPayload represents GitHub pull_request webhook payload structure

type GitHubWebhookPayload

type GitHubWebhookPayload struct {
	Action string `json:"action"`
	Issue  struct {
		Number      int    `json:"number"`
		State       string `json:"state"`
		PullRequest *struct {
		} `json:"pull_request,omitempty"` // This field exists only for PRs
		User struct {
			Login string `json:"login"`
		} `json:"user"`
	} `json:"issue"`
	Comment struct {
		ID   int64  `json:"id"`
		Body string `json:"body"`
		User struct {
			Login string `json:"login"`
		} `json:"user"`
	} `json:"comment"`
	Repository struct {
		Name  string `json:"name"`
		Owner struct {
			Login string `json:"login"`
		} `json:"owner"`
		HTMLURL string `json:"html_url"`
	} `json:"repository"`
	Sender struct {
		Login string `json:"login"`
	} `json:"sender"`
}

GitHubWebhookPayload represents GitHub webhook payload structure

type GitLabWebhookPayload

type GitLabWebhookPayload struct {
	ObjectKind       string `json:"object_kind"`
	ObjectAttributes struct {
		Action       string `json:"action"`
		Note         string `json:"note"`
		NoteableType string `json:"noteable_type"`
		ID           int64  `json:"id"`
	} `json:"object_attributes"`
	MergeRequest struct {
		IID    int    `json:"iid"`
		State  string `json:"state"`
		Author struct {
			Username string `json:"username"`
		} `json:"author"`
	} `json:"merge_request"`
	Project struct {
		Name      string `json:"name"`
		Namespace string `json:"namespace"`
		WebURL    string `json:"web_url"`
	} `json:"project"`
	User struct {
		Username string `json:"username"`
	} `json:"user"`
}

GitLabWebhookPayload represents GitLab webhook payload structure

type PRInfo

type PRInfo struct {
	Number  int
	State   string
	Title   string
	Draft   bool
	Author  string
	HeadRef string
	HeadSHA string
	BaseRef string
}

PRInfo represents pull request information from pull_request event

type PRWebhookEvent

type PRWebhookEvent struct {
	EventID     string
	Platform    string
	Action      string
	Repository  Repository
	PullRequest PRInfo
	Sender      User
}

PRWebhookEvent represents a parsed pull_request webhook event

func ParseGitHubPullRequestWebhook

func ParseGitHubPullRequestWebhook(payload []byte, allowedActions []string) (*PRWebhookEvent, error)

ParseGitHubPullRequestWebhook parses a GitHub pull_request webhook payload

type PullRequest

type PullRequest struct {
	Number int
	State  string
	Author string
}

PullRequest represents pull request information

type Repository

type Repository struct {
	Owner string
	Name  string
	URL   string
}

Repository represents repository information

type Server

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

Server represents the webhook HTTP server

func NewServer

func NewServer(cfg *config.WebhookConfig, logger *logrus.Logger) *Server

NewServer creates a new webhook server

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server

func (*Server) Start

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

Start starts the webhook server

type User

type User struct {
	Login string
}

User represents a user

type WebhookEvent

type WebhookEvent struct {
	EventID     string
	Platform    string
	Action      string
	Repository  Repository
	PullRequest PullRequest
	Comment     Comment
	Sender      User
}

WebhookEvent represents a parsed webhook event

func ParseGitHubWebhook

func ParseGitHubWebhook(payload []byte, eventType string) (*WebhookEvent, error)

ParseGitHubWebhook parses a GitHub webhook payload

func ParseGitLabWebhook

func ParseGitLabWebhook(payload []byte, eventType string) (*WebhookEvent, error)

ParseGitLabWebhook parses a GitLab webhook payload

func (*WebhookEvent) IsCommandComment

func (e *WebhookEvent) IsCommandComment() bool

IsCommandComment checks if the comment body contains a command

func (*WebhookEvent) ToConfig

func (e *WebhookEvent) ToConfig(baseConfig *config.Config) *config.Config

ToConfig converts a WebhookEvent to a Config for PR handler

type WebhookJob

type WebhookJob struct {
	Event     *WebhookEvent
	Timestamp time.Time
}

WebhookJob represents a webhook processing job

type WebhookMetricsRecorder

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

WebhookMetricsRecorder implements the MetricsRecorder interface for webhook execution.

func NewWebhookMetricsRecorder

func NewWebhookMetricsRecorder(platform string) *WebhookMetricsRecorder

NewWebhookMetricsRecorder creates a new WebhookMetricsRecorder.

func (*WebhookMetricsRecorder) RecordCommandExecution

func (r *WebhookMetricsRecorder) RecordCommandExecution(platform, command, status string)

RecordCommandExecution records a command execution metric.

func (*WebhookMetricsRecorder) RecordProcessingDuration

func (r *WebhookMetricsRecorder) RecordProcessingDuration(platform, command string, duration time.Duration)

RecordProcessingDuration records the processing duration for a command.

type Worker

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

Worker processes webhook jobs from a queue

Jump to

Keyboard shortcuts

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