{"modulePath":"github.com/AlaudaDevops/toolbox/pr-cli","version":"v0.0.0-20261019083812-38d5e0ad0d24","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package webhook\n\n## Variables\n\n```go\nvar (\n\t// WebhookRequestsTotal counts total webhook requests received\n\tWebhookRequestsTotal = promauto.NewCounterVec(\n\t\tprometheus.CounterOpts{\n\t\t\tName: \"pr_cli_webhook_requests_total\",\n\t\t\tHelp: \"Total number of webhook requests received\",\n\t\t},\n\t\t[]string{\"platform\", \"event_type\", \"status\"},\n\t)\n\n\t// WebhookProcessingDuration tracks webhook processing duration\n\tWebhookProcessingDuration = promauto.NewHistogramVec(\n\t\tprometheus.HistogramOpts{\n\t\t\tName:    \"pr_cli_webhook_processing_duration_seconds\",\n\t\t\tHelp:    \"Webhook processing duration in seconds\",\n\t\t\tBuckets: prometheus.DefBuckets,\n\t\t},\n\t\t[]string{\"platform\", \"command\"},\n\t)\n\n\t// CommandExecutionTotal counts total commands executed\n\tCommandExecutionTotal = promauto.NewCounterVec(\n\t\tprometheus.CounterOpts{\n\t\t\tName: \"pr_cli_command_execution_total\",\n\t\t\tHelp: \"Total number of commands executed\",\n\t\t},\n\t\t[]string{\"platform\", \"command\", \"status\"},\n\t)\n\n\t// QueueSize tracks current job queue size\n\tQueueSize = promauto.NewGauge(\n\t\tprometheus.GaugeOpts{\n\t\t\tName: \"pr_cli_queue_size\",\n\t\t\tHelp: \"Current size of the webhook job queue\",\n\t\t},\n\t)\n\n\t// ActiveWorkers tracks number of active workers\n\tActiveWorkers = promauto.NewGauge(\n\t\tprometheus.GaugeOpts{\n\t\t\tName: \"pr_cli_active_workers\",\n\t\t\tHelp: \"Number of active worker goroutines\",\n\t\t},\n\t)\n\n\t// PREventProcessingTotal counts pull_request events processed\n\tPREventProcessingTotal = promauto.NewCounterVec(\n\t\tprometheus.CounterOpts{\n\t\t\tName: \"pr_cli_pr_event_total\",\n\t\t\tHelp: \"Total number of pull_request events processed\",\n\t\t},\n\t\t[]string{\"platform\", \"action\", \"status\"},\n\t)\n\n\t// WorkflowDispatchTotal counts workflow dispatch triggers\n\tWorkflowDispatchTotal = promauto.NewCounterVec(\n\t\tprometheus.CounterOpts{\n\t\t\tName: \"pr_cli_workflow_dispatch_total\",\n\t\t\tHelp: \"Total number of workflow dispatch triggers\",\n\t\t},\n\t\t[]string{\"platform\", \"workflow\", \"status\"},\n\t)\n)\n```\n\n## Functions\n\n```go\nfunc ValidateGitHubSignature(payload []byte, signature string, secret string) error\n```\nValidateGitHubSignature validates the GitHub webhook signature\n\n```go\nfunc ValidateGitLabToken(token string, secret string) error\n```\nValidateGitLabToken validates the GitLab webhook token\n\n```go\nfunc ValidateRepository(owner, repo string, allowedRepos []string) error\n```\nValidateRepository checks if the repository is allowed\n\n```go\nfunc ValidateWebhookEvent(event *WebhookEvent) error\n```\nValidateWebhookEvent performs basic validation on the webhook event\n\n## Types\n\n```go\ntype Comment struct {\n\tID   int64\n\tBody string\n\tUser string\n}\n```\nComment represents a comment\n\n```go\ntype GitHubPullRequestPayload struct {\n\tAction      string `json:\"action\"`\n\tNumber      int    `json:\"number\"`\n\tPullRequest struct {\n\t\tNumber int    `json:\"number\"`\n\t\tState  string `json:\"state\"`\n\t\tTitle  string `json:\"title\"`\n\t\tDraft  bool   `json:\"draft\"`\n\t\tUser   struct {\n\t\t\tLogin string `json:\"login\"`\n\t\t} `json:\"user\"`\n\t\tHead struct {\n\t\t\tRef string `json:\"ref\"`\n\t\t\tSHA string `json:\"sha\"`\n\t\t} `json:\"head\"`\n\t\tBase struct {\n\t\t\tRef string `json:\"ref\"`\n\t\t} `json:\"base\"`\n\t} `json:\"pull_request\"`\n\tRepository struct {\n\t\tName  string `json:\"name\"`\n\t\tOwner struct {\n\t\t\tLogin string `json:\"login\"`\n\t\t} `json:\"owner\"`\n\t\tHTMLURL string `json:\"html_url\"`\n\t} `json:\"repository\"`\n\tSender struct {\n\t\tLogin string `json:\"login\"`\n\t} `json:\"sender\"`\n}\n```\nGitHubPullRequestPayload represents GitHub pull\\_request webhook payload structure\n\n```go\ntype GitHubWebhookPayload struct {\n\tAction string `json:\"action\"`\n\tIssue  struct {\n\t\tNumber      int    `json:\"number\"`\n\t\tState       string `json:\"state\"`\n\t\tPullRequest *struct {\n\t\t} `json:\"pull_request,omitempty\"` // This field exists only for PRs\n\t\tUser struct {\n\t\t\tLogin string `json:\"login\"`\n\t\t} `json:\"user\"`\n\t} `json:\"issue\"`\n\tComment struct {\n\t\tID   int64  `json:\"id\"`\n\t\tBody string `json:\"body\"`\n\t\tUser struct {\n\t\t\tLogin string `json:\"login\"`\n\t\t} `json:\"user\"`\n\t} `json:\"comment\"`\n\tRepository struct {\n\t\tName  string `json:\"name\"`\n\t\tOwner struct {\n\t\t\tLogin string `json:\"login\"`\n\t\t} `json:\"owner\"`\n\t\tHTMLURL string `json:\"html_url\"`\n\t} `json:\"repository\"`\n\tSender struct {\n\t\tLogin string `json:\"login\"`\n\t} `json:\"sender\"`\n}\n```\nGitHubWebhookPayload represents GitHub webhook payload structure\n\n```go\ntype GitLabWebhookPayload struct {\n\tObjectKind       string `json:\"object_kind\"`\n\tObjectAttributes struct {\n\t\tAction       string `json:\"action\"`\n\t\tNote         string `json:\"note\"`\n\t\tNoteableType string `json:\"noteable_type\"`\n\t\tID           int64  `json:\"id\"`\n\t} `json:\"object_attributes\"`\n\tMergeRequest struct {\n\t\tIID    int    `json:\"iid\"`\n\t\tState  string `json:\"state\"`\n\t\tAuthor struct {\n\t\t\tUsername string `json:\"username\"`\n\t\t} `json:\"author\"`\n\t} `json:\"merge_request\"`\n\tProject struct {\n\t\tName      string `json:\"name\"`\n\t\tNamespace string `json:\"namespace\"`\n\t\tWebURL    string `json:\"web_url\"`\n\t} `json:\"project\"`\n\tUser struct {\n\t\tUsername string `json:\"username\"`\n\t} `json:\"user\"`\n}\n```\nGitLabWebhookPayload represents GitLab webhook payload structure\n\n```go\ntype PRInfo struct {\n\tNumber  int\n\tState   string\n\tTitle   string\n\tDraft   bool\n\tAuthor  string\n\tHeadRef string\n\tHeadSHA string\n\tBaseRef string\n}\n```\nPRInfo represents pull request information from pull\\_request event\n\n```go\ntype PRWebhookEvent struct {\n\tEventID     string\n\tPlatform    string\n\tAction      string\n\tRepository  Repository\n\tPullRequest PRInfo\n\tSender      User\n}\n```\nPRWebhookEvent represents a parsed pull\\_request webhook event\n\n```go\nfunc ParseGitHubPullRequestWebhook(payload []byte, allowedActions []string) (*PRWebhookEvent, error)\n```\nParseGitHubPullRequestWebhook parses a GitHub pull\\_request webhook payload\n\n```go\ntype PullRequest struct {\n\tNumber int\n\tState  string\n\tAuthor string\n}\n```\nPullRequest represents pull request information\n\n```go\ntype Repository struct {\n\tOwner string\n\tName  string\n\tURL   string\n}\n```\nRepository represents repository information\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer represents the webhook HTTP server\n\n```go\nfunc NewServer(cfg *config.WebhookConfig, logger *logrus.Logger) *Server\n```\nNewServer creates a new webhook server\n\n```go\nfunc (s *Server) Shutdown(ctx context.Context) error\n```\nShutdown gracefully shuts down the server\n\n```go\nfunc (s *Server) Start(ctx context.Context) error\n```\nStart starts the webhook server\n\n```go\ntype User struct {\n\tLogin string\n}\n```\nUser represents a user\n\n```go\ntype WebhookEvent struct {\n\tEventID     string\n\tPlatform    string\n\tAction      string\n\tRepository  Repository\n\tPullRequest PullRequest\n\tComment     Comment\n\tSender      User\n}\n```\nWebhookEvent represents a parsed webhook event\n\n```go\nfunc ParseGitHubWebhook(payload []byte, eventType string) (*WebhookEvent, error)\n```\nParseGitHubWebhook parses a GitHub webhook payload\n\n```go\nfunc ParseGitLabWebhook(payload []byte, eventType string) (*WebhookEvent, error)\n```\nParseGitLabWebhook parses a GitLab webhook payload\n\n```go\nfunc (e *WebhookEvent) IsCommandComment() bool\n```\nIsCommandComment checks if the comment body contains a command\n\n```go\nfunc (e *WebhookEvent) ToConfig(baseConfig *config.Config) *config.Config\n```\nToConfig converts a WebhookEvent to a Config for PR handler\n\n```go\ntype WebhookJob struct {\n\tEvent     *WebhookEvent\n\tTimestamp time.Time\n}\n```\nWebhookJob represents a webhook processing job\n\n```go\ntype WebhookMetricsRecorder struct {\n\t// contains filtered or unexported fields\n}\n```\nWebhookMetricsRecorder implements the MetricsRecorder interface for webhook execution.\n\n```go\nfunc NewWebhookMetricsRecorder(platform string) *WebhookMetricsRecorder\n```\nNewWebhookMetricsRecorder creates a new WebhookMetricsRecorder.\n\n```go\nfunc (r *WebhookMetricsRecorder) RecordCommandExecution(platform, command, status string)\n```\nRecordCommandExecution records a command execution metric.\n\n```go\nfunc (r *WebhookMetricsRecorder) RecordProcessingDuration(platform, command string, duration time.Duration)\n```\nRecordProcessingDuration records the processing duration for a command.\n\n```go\ntype Worker struct {\n\t// contains filtered or unexported fields\n}\n```\nWorker processes webhook jobs from a queue\n\n","path":"github.com/AlaudaDevops/toolbox/pr-cli/pkg/webhook","name":"webhook","synopsis":"","isRedistributable":true}
