git-next/crates/repo-actor/src/messages.rs

71 lines
2.1 KiB
Rust
Raw Normal View History

//
use config::newtype;
use derive_more::Display;
use git_next_config as config;
use git_next_git as git;
#[macro_export]
macro_rules! message {
($name:ident wraps $value:ty) => {
git_next_config::newtype!($name is a $value);
impl actix::prelude::Message for $name {
type Result = ();
}
};
($name:ident) => {
git_next_config::newtype!($name);
impl actix::prelude::Message for $name {
type Result = ();
}
};
($name:ident wraps $value:ty => $result:ty) => {
git_next_config::newtype!($name is a $value);
impl actix::prelude::Message for $name {
type Result = $result;
}
};
($name:ident => $result:ty) => {
git_next_config::newtype!($name);
impl actix::prelude::Message for $name {
type Result = $result;
}
};
}
message!(LoadConfigFromRepo);
message!(CloneRepo);
message!(ReceiveRepoConfig wraps config::RepoConfig);
message!(ValidateRepo wraps MessageToken);
message!(WebhookRegistered wraps (config::WebhookId, config::WebhookAuth));
impl WebhookRegistered {
pub const fn webhook_id(&self) -> &config::WebhookId {
&self.0 .0
}
pub const fn webhook_auth(&self) -> &config::WebhookAuth {
&self.0 .1
}
}
impl From<config::RegisteredWebhook> for WebhookRegistered {
fn from(value: config::RegisteredWebhook) -> Self {
let webhook_id = value.id().clone();
let webhook_auth = value.auth().clone();
Self::from((webhook_id, webhook_auth))
}
}
newtype!(MessageToken is a u32, Copy, Default, Display);
impl MessageToken {
pub const fn next(&self) -> Self {
Self(self.0 + 1)
}
}
message!(RegisterWebhook);
message!(CheckCIStatus wraps git::Commit); // next commit
message!(ReceiveCIStatus wraps (git::Commit, git::forge::commit::Status)); // commit and it's status
message!(AdvanceNext wraps (git::Commit, Vec<git::Commit>)); // next commit and the dev commit history
message!(AdvanceMain wraps git::Commit); // next commit
message!(WebhookNotification wraps config::webhook::forge_notification::ForgeNotification);