1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Webhook handler trait and types for application-provided processing logic.
//!
//! This module defines the interface that applications implement to process
//! GitHub webhook events. Handlers receive normalized EventEnvelope instances
//! and can perform async processing without blocking webhook HTTP responses.
//!
//! # Fire-and-Forget Pattern
//!
//! Handlers execute asynchronously after the HTTP response is sent to GitHub.
//! This ensures GitHub receives a response within the 10-second timeout while
//! allowing handlers to perform longer-running operations.
//!
//! # Examples
//!
//! ```rust,no_run
//! use github_bot_sdk::webhook::WebhookHandler;
//! use github_bot_sdk::events::EventEnvelope;
//! use async_trait::async_trait;
//!
//! struct MyHandler;
//!
//! #[async_trait]
//! impl WebhookHandler for MyHandler {
//! async fn handle_event(&self, envelope: &EventEnvelope) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! println!("Processing event: {}", envelope.event_id);
//! // Perform async processing here
//! Ok(())
//! }
//! }
//! ```
use crateEventEnvelope;
use async_trait;
use Error;
/// Application-provided webhook event handler.
///
/// Implementations of this trait define custom processing logic for GitHub
/// webhook events. Handlers are invoked asynchronously after the HTTP response
/// is sent, allowing long-running operations without blocking GitHub's webhook
/// delivery.
///
/// # Error Handling
///
/// Handler errors are logged but do not affect the HTTP response to GitHub.
/// Failed handler executions should implement their own retry/recovery logic
/// if needed.
///
/// # Concurrency
///
/// Multiple handlers can be registered and will execute concurrently for each
/// webhook event. Handlers must be `Send + Sync` to support concurrent execution.
///
/// # Examples
///
/// ```rust,no_run
/// use github_bot_sdk::webhook::WebhookHandler;
/// use github_bot_sdk::events::EventEnvelope;
/// use async_trait::async_trait;
///
/// struct PullRequestHandler;
///
/// #[async_trait]
/// impl WebhookHandler for PullRequestHandler {
/// async fn handle_event(&self, envelope: &EventEnvelope) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
/// if envelope.event_type == "pull_request" {
/// println!("Processing PR event for {}", envelope.repository.full_name);
/// // Add PR processing logic
/// }
/// Ok(())
/// }
/// }
/// ```