pub struct EventProcessor { /* private fields */ }Expand description
Processes raw GitHub webhooks into normalized event envelopes.
The event processor handles:
- Signature validation (optional)
- JSON parsing and validation
- Entity extraction and classification
- Session ID generation for ordering
- Metadata population
§Examples
use github_bot_sdk::events::{EventProcessor, ProcessorConfig};
let config = ProcessorConfig::default();
let processor = EventProcessor::new(config);
let envelope = processor.process_webhook(
"pull_request",
b"{\"action\":\"opened\",\"number\":1}",
Some("delivery-123"),
).await?;
println!("Processed event: {}", envelope.event_id);Implementations§
Source§impl EventProcessor
impl EventProcessor
Sourcepub fn new(config: ProcessorConfig) -> Self
pub fn new(config: ProcessorConfig) -> Self
Create a new event processor with the given configuration.
Sourcepub async fn process_webhook(
&self,
event_type: &str,
payload: &[u8],
delivery_id: Option<&str>,
) -> Result<EventEnvelope, EventError>
pub async fn process_webhook( &self, event_type: &str, payload: &[u8], delivery_id: Option<&str>, ) -> Result<EventEnvelope, EventError>
Process a raw webhook into a normalized event envelope.
§Arguments
event_type- GitHub event type (from X-GitHub-Event header)payload- Raw webhook payload bytesdelivery_id- GitHub delivery ID (from X-GitHub-Delivery header)
§Returns
A normalized EventEnvelope or an error if processing fails.
§Errors
Returns EventError if:
- Payload exceeds maximum size
- Payload is not valid JSON
- Required fields are missing
- Event type is unsupported
Sourcepub fn extract_entity_info(
&self,
event_type: &str,
payload: &Value,
) -> Result<(EntityType, Option<String>), EventError>
pub fn extract_entity_info( &self, event_type: &str, payload: &Value, ) -> Result<(EntityType, Option<String>), EventError>
Extract entity information from the payload.
Determines the primary entity type and ID for session correlation.
Sourcepub fn generate_session_id(
&self,
entity_type: &EntityType,
entity_id: &Option<String>,
repository: &Repository,
) -> Option<String>
pub fn generate_session_id( &self, entity_type: &EntityType, entity_id: &Option<String>, repository: &Repository, ) -> Option<String>
Generate a session ID for ordered processing.
Uses the configured strategy to create session IDs that group related events together for sequential processing.
Auto Trait Implementations§
impl Freeze for EventProcessor
impl RefUnwindSafe for EventProcessor
impl Send for EventProcessor
impl Sync for EventProcessor
impl Unpin for EventProcessor
impl UnsafeUnpin for EventProcessor
impl UnwindSafe for EventProcessor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more