Expand description
GitHub webhook event types and processing.
This module provides type-safe event parsing, validation, and normalization for GitHub webhook events. It bridges the gap between raw GitHub webhook payloads and the bot processing system.
§Overview
The events module defines:
- Event envelope types for normalized event representation
- Typed event structures for different GitHub event types
- Event processing pipeline for webhook conversion
- Session management for ordered event processing
§Examples
§Processing a Webhook Event
use github_bot_sdk::events::{EventProcessor, ProcessorConfig};
let config = ProcessorConfig::default();
let processor = EventProcessor::new(config);
// Process incoming webhook
let payload_bytes = b"{\"action\": \"opened\", \"repository\": {}}";
let envelope = processor.process_webhook(
"pull_request",
payload_bytes,
Some("12345-67890-abcdef"),
).await?;
println!("Event ID: {}", envelope.event_id);
println!("Repository: {}", envelope.repository.full_name);§Typed Event Handling
match envelope.event_type.as_str() {
"pull_request" => {
let pr_event = envelope.payload.parse_pull_request()?;
println!("PR #{} was {}", pr_event.number, pr_event.action);
}
"issues" => {
let issue_event = envelope.payload.parse_issue()?;
println!("Issue #{} was {}", issue_event.issue.number, issue_event.action);
}
_ => println!("Unhandled event type"),
}Re-exports§
pub use processor::EventProcessor;pub use processor::ProcessorConfig;pub use processor::SessionIdStrategy;pub use session::SessionManager;pub use github_events::*;
Modules§
- github_
events - GitHub-specific event structures and types.
- processor
- Event processor for converting raw webhooks to normalized events.
- session
- Session management for ordered event processing.
Structs§
- Event
Envelope - Primary event container that wraps all GitHub events in a normalized format.
- EventId
- Unique identifier for events, ensuring idempotency and deduplication.
- Event
Metadata - Additional metadata about event processing and routing.
- Event
Payload - Container for the actual GitHub webhook payload data.
- Trace
Context - Distributed tracing context for event correlation.
Enums§
- Entity
Type - Classifies the primary entity involved in the event for session correlation.
- Event
Source - Source of an event.