-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7e4c94
commit 98070a5
Showing
16 changed files
with
489 additions
and
200 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use octocrab::models::webhook_events::WebhookEventType; | ||
use thiserror::Error; | ||
|
||
use crate::embed_builder; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum RockdoveError { | ||
#[error("missing field in event: {event_type:?}::{field}")] | ||
MissingField { | ||
event_type: WebhookEventType, | ||
field: &'static str, | ||
}, | ||
|
||
#[error("invalid field in event: {event_type:?}::{field}")] | ||
InvalidField { | ||
event_type: WebhookEventType, | ||
field: &'static str, | ||
}, | ||
|
||
#[error(transparent)] | ||
EmbedBuilder(#[from] embed_builder::Error), | ||
} | ||
|
||
pub type RockdoveResult<T> = Result<T, RockdoveError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,60 @@ | ||
pub mod commit_comment; | ||
pub mod discussion; | ||
pub mod discussion_comment; | ||
pub mod issue_comment; | ||
pub mod issues; | ||
pub mod membership; | ||
pub mod pull_request; | ||
pub mod pull_request_review; | ||
pub mod release; | ||
pub mod repository; | ||
use octocrab::models::webhook_events::{WebhookEvent, WebhookEventPayload}; | ||
use tracing::info; | ||
|
||
use crate::{ | ||
embed_builder::EmbedBuilder, | ||
errors::{RockdoveError, RockdoveResult}, | ||
}; | ||
|
||
mod commit_comment; | ||
mod discussion; | ||
mod discussion_comment; | ||
mod issue_comment; | ||
mod issues; | ||
mod membership; | ||
mod pull_request; | ||
mod pull_request_review; | ||
mod release; | ||
mod repository; | ||
|
||
pub fn make_embed(event: WebhookEvent) -> RockdoveResult<Option<serde_json::Value>> { | ||
let sender = event | ||
.sender | ||
.clone() | ||
.ok_or_else(|| RockdoveError::MissingField { | ||
event_type: event.kind.clone(), | ||
field: "sender", | ||
})?; | ||
|
||
let Some(mut embed) = begin_embed(event)? else { | ||
info!("ignoring event"); | ||
return Ok(None); | ||
}; | ||
|
||
embed.author(sender); | ||
Ok(Some(embed.try_build()?)) | ||
} | ||
|
||
fn begin_embed(event: WebhookEvent) -> RockdoveResult<Option<EmbedBuilder>> { | ||
match event.specific.clone() { | ||
WebhookEventPayload::Repository(specifics) => repository::make_embed(event, &specifics), | ||
WebhookEventPayload::Discussion(specifics) => discussion::make_embed(event, &specifics), | ||
WebhookEventPayload::DiscussionComment(specifics) => { | ||
discussion_comment::make_embed(event, &specifics) | ||
} | ||
WebhookEventPayload::Issues(specifics) => issues::make_embed(event, &specifics), | ||
WebhookEventPayload::PullRequest(specifics) => pull_request::make_embed(event, &specifics), | ||
WebhookEventPayload::IssueComment(specifics) => { | ||
issue_comment::make_embed(event, &specifics) | ||
} | ||
WebhookEventPayload::CommitComment(specifics) => { | ||
commit_comment::make_embed(event, &specifics) | ||
} | ||
WebhookEventPayload::PullRequestReview(specifics) => { | ||
pull_request_review::make_embed(event, &specifics) | ||
} | ||
WebhookEventPayload::Release(specifics) => release::make_embed(event, &specifics), | ||
WebhookEventPayload::Membership(specifics) => membership::make_embed(event, &specifics), | ||
_ => Ok(None), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.