use std::sync::Arc;
use octocrab::models::webhook_events::WebhookEventType;
use crate::{Context, Octofer, SerdeToString};
impl Octofer {
pub async fn on_label<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Label.to_string(), handler, extra)
.await;
self
}
pub async fn on_milestone<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Milestone.to_string(), handler, extra)
.await;
self
}
pub async fn on_watch<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Watch.to_string(), handler, extra)
.await;
self
}
pub async fn on_star<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Star.to_string(), handler, extra)
.await;
self
}
pub async fn on_ping<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Ping.to_string(), handler, extra)
.await;
self
}
pub async fn on_meta<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Meta.to_string(), handler, extra)
.await;
self
}
pub async fn on_page_build<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::PageBuild.to_string(), handler, extra)
.await;
self
}
pub async fn on_schedule<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Schedule.to_string(), handler, extra)
.await;
self
}
pub async fn on_sponsorship<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::Sponsorship.to_string(), handler, extra)
.await;
self
}
pub async fn on_marketplace_purchase<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(
WebhookEventType::MarketplacePurchase.to_string(),
handler,
extra,
)
.await;
self
}
pub async fn on_merge_group<F, Fut, E>(&mut self, handler: F, extra: Arc<E>) -> &Self
where
F: Fn(Context, Arc<E>) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
E: Send + Sync + 'static,
{
self.server
.on(WebhookEventType::MergeGroup.to_string(), handler, extra)
.await;
self
}
}