Documentation
¶
Index ¶
- Variables
- func ValidateGitHubSignature(payload []byte, signature string, secret string) error
- func ValidateGitLabToken(token string, secret string) error
- func ValidateRepository(owner, repo string, allowedRepos []string) error
- func ValidateWebhookEvent(event *WebhookEvent) error
- type Comment
- type GitHubPullRequestPayload
- type GitHubWebhookPayload
- type GitLabWebhookPayload
- type PRInfo
- type PRWebhookEvent
- type PullRequest
- type Repository
- type Server
- type User
- type WebhookEvent
- type WebhookJob
- type WebhookMetricsRecorder
- type Worker
Constants ¶
This section is empty.
Variables ¶
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 ¶
ValidateGitHubSignature validates the GitHub webhook signature
func ValidateGitLabToken ¶
ValidateGitLabToken validates the GitLab webhook token
func ValidateRepository ¶
ValidateRepository checks if the repository is allowed
func ValidateWebhookEvent ¶
func ValidateWebhookEvent(event *WebhookEvent) error
ValidateWebhookEvent performs basic validation on the webhook event
Types ¶
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 ¶
PullRequest represents pull request information
type Repository ¶
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
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
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.