octofer 0.1.0

A framework for building GitHub Apps in Rust
Documentation
//! Project event handlers
//!
//! This module provides implementations for registering handlers for GitHub project
//! (classic and v2) webhook events.

use std::sync::Arc;

use octocrab::models::webhook_events::WebhookEventType;

use crate::{Context, Octofer, SerdeToString};

impl Octofer {
    /// Register a handler for project (classic) events
    pub async fn on_project<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::Project.to_string(), handler, extra)
            .await;
        self
    }

    /// Register a handler for project card events
    pub async fn on_project_card<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::ProjectCard.to_string(), handler, extra)
            .await;
        self
    }

    /// Register a handler for project column events
    pub async fn on_project_column<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::ProjectColumn.to_string(), handler, extra)
            .await;
        self
    }

    /// Register a handler for projects v2 events
    pub async fn on_projects_v2<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::ProjectsV2.to_string(), handler, extra)
            .await;
        self
    }

    /// Register a handler for projects v2 item events
    pub async fn on_projects_v2_item<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::ProjectsV2Item.to_string(), handler, extra)
            .await;
        self
    }
}