use std::sync::Arc;
use async_trait::async_trait;
use github_rest::model::{
apps::events::{AppAuthorizationEvent, InstallationEvent, InstallationRepositoriesEvent},
commits::events::{CommitCommentEvent, StatusEvent},
discussions::events::{DiscussionCommentEvent, DiscussionEvent},
issues::events::{IssueCommentEvent, IssueEvent, LabelEvent},
misc::events::{DeploymentEvent, DeploymentStatusEvent, MarketplacePurchaseEvent, MetaEvent, SponsorshipEvent},
organizations::events::{MembershipEvent, OrgBlockEvent, OrganizationEvent, TeamEvent},
pull_requests::events::{PullRequestEvent, PullRequestReviewCommentEvent, PullRequestReviewEvent},
releases::events::{CreateEvent, DeleteEvent, ReleaseEvent},
repositories::{
events::{
BranchProtectionRuleEvent, CodeScanningAlertEvent, DeployKeyEvent, ForkEvent, MemberEvent, MilestoneEvent,
PackageEvent, PingEvent, ProjectCardEvent, ProjectColumnEvent, ProjectEvent, PublicEvent, PushEvent,
RepositoryDispatchEvent, RepositoryEvent, RepositoryImportEvent, RepositoryVulnerabilityAlertEvent,
SecretScanningAlertEvent, StarEvent, TeamAddEvent, WatchEvent,
},
security_advisory::events::SecurityAdvisoryEvent,
wiki::events::GollumEvent,
workflows::events::{
CheckRunEvent, CheckSuiteEvent, PageBuildEvent, WorkflowDispatchEvent, WorkflowJobEvent, WorkflowRunEvent,
},
},
};
use crate::{client::GitHubClient, github::command::Command, Client};
#[cfg(feature = "secrets")]
use lazy_static::lazy_static;
#[cfg(feature = "secrets")]
lazy_static! {
static ref WEBHOOK_SECRET: String = std::env::var("WEBHOOK_SECRET").unwrap();
}
#[async_trait]
#[allow(unused_variables)]
pub trait EventHandler {
type Message: std::fmt::Debug + Send;
type GitHubClient: GitHubClient + Send + Sync;
#[cfg(feature = "native")]
fn listener_port(&self) -> u16 {
8080
}
#[cfg(feature = "native")]
fn route(&self) -> &'static str {
"payload"
}
#[cfg(feature = "secrets")]
fn listener_secret(&self) -> &'static [u8];
async fn message(&self, message: Self::Message) {}
async fn app_authorization_event(
&self,
github_client: Arc<Self::GitHubClient>,
app_authorization_event: AppAuthorizationEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn installation_event(
&self,
github_client: Arc<Self::GitHubClient>,
installation_event: InstallationEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn installation_repositories_event(
&self,
github_client: Arc<Self::GitHubClient>,
installation_repositories_event: InstallationRepositoriesEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn push_event(
&self,
github_client: Arc<Self::GitHubClient>,
push_event: PushEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn commit_comment_event(
&self,
github_client: Arc<Self::GitHubClient>,
commit_comment_event: CommitCommentEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn release_event(
&self,
github_client: Arc<Self::GitHubClient>,
release_event: ReleaseEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn repository_event(
&self,
github_client: Arc<Self::GitHubClient>,
repository_event: RepositoryEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn organization_event(
&self,
github_client: Arc<Self::GitHubClient>,
organization_event: OrganizationEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn team_event(
&self,
github_client: Arc<Self::GitHubClient>,
team_event: TeamEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn team_add_event(
&self,
github_client: Arc<Self::GitHubClient>,
team_add_event: TeamAddEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn project_event(
&self,
github_client: Arc<Self::GitHubClient>,
project_event: ProjectEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn project_card_event(
&self,
github_client: Arc<Self::GitHubClient>,
project_card_event: ProjectCardEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn project_column_event(
&self,
github_client: Arc<Self::GitHubClient>,
project_column_event: ProjectColumnEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn meta_event(
&self,
github_client: Arc<Self::GitHubClient>,
meta_event: MetaEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn package_event(
&self,
github_client: Arc<Self::GitHubClient>,
package_event: PackageEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn ping_event(
&self,
github_client: Arc<Self::GitHubClient>,
ping_event: PingEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn sponsorship_event(
&self,
github_client: Arc<Self::GitHubClient>,
sponsorship_event: SponsorshipEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn marketplace_purchase_event(
&self,
github_client: Arc<Self::GitHubClient>,
marketplace_purchase_event: MarketplacePurchaseEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn repository_dispatch_event(
&self,
github_client: Arc<Self::GitHubClient>,
repository_dispatch_event: RepositoryDispatchEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn repository_import_event(
&self,
github_client: Arc<Self::GitHubClient>,
repository_import_event: RepositoryImportEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn repository_vulnerability_alert(
&self,
github_client: Arc<Self::GitHubClient>,
repository_vulnerability_alert: RepositoryVulnerabilityAlertEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn secret_scanning_alert(
&self,
github_client: Arc<Self::GitHubClient>,
secret_scanning_alert: SecretScanningAlertEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn status_event(
&self,
github_client: Arc<Self::GitHubClient>,
status_event: StatusEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn label_event(
&self,
github_client: Arc<Self::GitHubClient>,
label_event: LabelEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn discussion_event(
&self,
github_client: Arc<Self::GitHubClient>,
discussion_event: DiscussionEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn discussion_comment_event(
&self,
github_client: Arc<Self::GitHubClient>,
discussion_comment_event: DiscussionCommentEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn branch_protection_rule_event(
&self,
github_client: Arc<Self::GitHubClient>,
branch_protection_rule_event: BranchProtectionRuleEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn check_suite_event(
&self,
github_client: Arc<Self::GitHubClient>,
check_suite_event: CheckSuiteEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn code_scanning_alert(
&self,
github_client: Arc<Self::GitHubClient>,
code_scanning_alert: CodeScanningAlertEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn deployment_event(
&self,
github_client: Arc<Self::GitHubClient>,
deployment_event: DeploymentEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn deployment_status_event(
&self,
github_client: Arc<Self::GitHubClient>,
deployment_status_event: DeploymentStatusEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn page_build_event(
&self,
github_client: Arc<Self::GitHubClient>,
page_build_event: PageBuildEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn workflow_dispatch_event(
&self,
github_client: Arc<Self::GitHubClient>,
workflow_dispatch_event: WorkflowDispatchEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn deploy_key_event(
&self,
github_client: Arc<Self::GitHubClient>,
deploy_key_event: DeployKeyEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn gollum_event(
&self,
github_client: Arc<Self::GitHubClient>,
gollum_event: GollumEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn membership_event(
&self,
github_client: Arc<Self::GitHubClient>,
membership_event: MembershipEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn org_block_event(
&self,
github_client: Arc<Self::GitHubClient>,
org_block_event: OrgBlockEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn member_event(
&self,
github_client: Arc<Self::GitHubClient>,
member_event: MemberEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn public_event(
&self,
github_client: Arc<Self::GitHubClient>,
public_event: PublicEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn milestone_event(
&self,
github_client: Arc<Self::GitHubClient>,
milestone_event: MilestoneEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn tag_created(
&self,
github_client: Arc<Self::GitHubClient>,
create_event: CreateEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn tag_deleted(
&self,
github_client: Arc<Self::GitHubClient>,
delete_event: DeleteEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn star_event(
&self,
github_client: Arc<Self::GitHubClient>,
star_event: StarEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn security_advisory_event(
&self,
github_client: Arc<Self::GitHubClient>,
security_advisory_event: SecurityAdvisoryEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn watch_event(
&self,
github_client: Arc<Self::GitHubClient>,
watch_event: WatchEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn repository_forked(
&self,
github_client: Arc<Self::GitHubClient>,
fork_event: ForkEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn pull_request_event(
&self,
github_client: Arc<Self::GitHubClient>,
pull_request_event: PullRequestEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn pull_request_review_event(
&self,
github_client: Arc<Self::GitHubClient>,
pull_request_review_event: PullRequestReviewEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn pull_request_review_comment_event(
&self,
github_client: Arc<Self::GitHubClient>,
pull_request_review_comment_event: PullRequestReviewCommentEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn workflow_run(
&self,
github_client: Arc<Self::GitHubClient>,
workflow_run: WorkflowRunEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn workflow_job(
&self,
github_client: Arc<Self::GitHubClient>,
workflow_job: WorkflowJobEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn check_run(
&self,
github_client: Arc<Self::GitHubClient>,
check_run: CheckRunEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn issue_event(
&self,
github_client: Arc<Self::GitHubClient>,
issue_event: IssueEvent,
) -> Command<Self::Message> {
Command::none()
}
async fn issue_comment_event(
&self,
github_client: Arc<Self::GitHubClient>,
issue_comment_event: IssueCommentEvent,
) -> Command<Self::Message> {
Command::none()
}
}
#[derive(Debug)]
pub struct DefaultEventHandler;
#[async_trait]
impl EventHandler for DefaultEventHandler {
type Message = ();
type GitHubClient = Client<Self>;
#[cfg(feature = "secrets")]
fn listener_secret(&self) -> &'static [u8] {
WEBHOOK_SECRET.as_bytes()
}
async fn message(&self, _message: Self::Message) {}
}
impl DefaultEventHandler {
pub fn new() -> Self {
Self
}
}
impl Default for DefaultEventHandler {
fn default() -> Self {
Self::new()
}
}