Compare commits
1 commit
022e6bcbb0
...
58b047cdb5
Author | SHA1 | Date | |
---|---|---|---|
58b047cdb5 |
12 changed files with 27 additions and 61 deletions
|
@ -41,7 +41,7 @@ type Result<T> = core::result::Result<T, Error>;
|
|||
)]
|
||||
pub struct ServerConfig {
|
||||
http: Http,
|
||||
webhook: InboundWebhook,
|
||||
webhook: Webhook,
|
||||
notifications: Notification,
|
||||
storage: ServerStorage,
|
||||
pub forge: BTreeMap<String, ForgeConfig>,
|
||||
|
@ -69,7 +69,7 @@ impl ServerConfig {
|
|||
&self.notifications
|
||||
}
|
||||
|
||||
pub const fn webhook(&self) -> &InboundWebhook {
|
||||
pub const fn webhook(&self) -> &Webhook {
|
||||
&self.webhook
|
||||
}
|
||||
|
||||
|
@ -118,10 +118,10 @@ impl Http {
|
|||
serde::Deserialize,
|
||||
derive_more::Constructor,
|
||||
)]
|
||||
pub struct InboundWebhook {
|
||||
pub struct Webhook {
|
||||
url: String,
|
||||
}
|
||||
impl InboundWebhook {
|
||||
impl Webhook {
|
||||
pub fn url(&self, forge_alias: &ForgeAlias, repo_alias: &RepoAlias) -> WebhookUrl {
|
||||
let base_url = &self.url;
|
||||
WebhookUrl(format!("{base_url}/{forge_alias}/{repo_alias}"))
|
||||
|
@ -189,7 +189,7 @@ pub enum NotificationType {
|
|||
)]
|
||||
pub struct Notification {
|
||||
r#type: NotificationType,
|
||||
webhook: Option<OutboundWebhook>,
|
||||
webhook: Option<Webhook>,
|
||||
}
|
||||
impl Notification {
|
||||
pub const fn none() -> Self {
|
||||
|
@ -198,7 +198,7 @@ impl Notification {
|
|||
webhook: None,
|
||||
}
|
||||
}
|
||||
pub const fn webhook(webhook: OutboundWebhook) -> Self {
|
||||
pub const fn webhook(webhook: Webhook) -> Self {
|
||||
Self {
|
||||
r#type: NotificationType::Webhook,
|
||||
webhook: Some(webhook),
|
||||
|
@ -214,19 +214,3 @@ impl Default for Notification {
|
|||
Self::none()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
derive_more::From,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
derive_more::AsRef,
|
||||
serde::Deserialize,
|
||||
derive_more::Constructor,
|
||||
)]
|
||||
pub struct OutboundWebhook {
|
||||
url: String,
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ use std::collections::BTreeMap;
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::server::Http;
|
||||
use crate::server::InboundWebhook;
|
||||
use crate::server::ServerConfig;
|
||||
use crate::server::ServerStorage;
|
||||
use crate::server::Webhook;
|
||||
use crate::webhook::push::Branch;
|
||||
|
||||
mod url;
|
||||
|
@ -695,7 +695,7 @@ mod push {
|
|||
}
|
||||
mod given {
|
||||
|
||||
use crate::server::{Notification, OutboundWebhook};
|
||||
use crate::server::Notification;
|
||||
|
||||
use super::*;
|
||||
use rand::Rng as _;
|
||||
|
@ -719,7 +719,7 @@ mod given {
|
|||
pub fn a_server_config() -> ServerConfig {
|
||||
ServerConfig::new(
|
||||
an_http(),
|
||||
an_inbound_webhook(),
|
||||
a_webhook(),
|
||||
a_notification_config(),
|
||||
a_server_storage(),
|
||||
some_forge_configs(),
|
||||
|
@ -741,17 +741,14 @@ mod given {
|
|||
pub fn a_port() -> u16 {
|
||||
rand::thread_rng().gen()
|
||||
}
|
||||
pub fn an_inbound_webhook() -> InboundWebhook {
|
||||
InboundWebhook::new(a_name())
|
||||
}
|
||||
pub fn an_outbound_webhook() -> OutboundWebhook {
|
||||
OutboundWebhook::new(a_name())
|
||||
pub fn a_webhook() -> Webhook {
|
||||
Webhook::new(a_name())
|
||||
}
|
||||
pub fn a_server_storage() -> ServerStorage {
|
||||
ServerStorage::new(a_name().into())
|
||||
}
|
||||
pub fn a_notification_config() -> Notification {
|
||||
Notification::webhook(an_outbound_webhook())
|
||||
Notification::webhook(a_webhook())
|
||||
}
|
||||
pub fn some_forge_configs() -> BTreeMap<String, ForgeConfig> {
|
||||
[(a_name(), a_forge_config())].into()
|
||||
|
|
|
@ -703,7 +703,7 @@ mod forgejo {
|
|||
forge_alias: &config::ForgeAlias,
|
||||
repo_alias: &config::RepoAlias,
|
||||
) -> git_next_config::server::WebhookUrl {
|
||||
config::server::InboundWebhook::new(a_name()).url(forge_alias, repo_alias)
|
||||
config::server::Webhook::new(a_name()).url(forge_alias, repo_alias)
|
||||
}
|
||||
|
||||
pub fn any_webhook_url() -> git_next_config::server::WebhookUrl {
|
||||
|
|
|
@ -510,7 +510,7 @@ mod github {
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use git_next_config::{server::InboundWebhook, WebhookId};
|
||||
use git_next_config::{server::Webhook, WebhookId};
|
||||
use kxio::network::{MockNetwork, StatusCode};
|
||||
use rand::RngCore;
|
||||
use serde_json::json;
|
||||
|
@ -648,7 +648,7 @@ mod github {
|
|||
forge_alias: &ForgeAlias,
|
||||
repo_alias: &RepoAlias,
|
||||
) -> git_next_config::server::WebhookUrl {
|
||||
InboundWebhook::new(a_name()).url(forge_alias, repo_alias)
|
||||
Webhook::new(a_name()).url(forge_alias, repo_alias)
|
||||
}
|
||||
pub fn any_webhook_url() -> git_next_config::server::WebhookUrl {
|
||||
given::a_webhook_url(&given::a_forge_alias(), &given::a_repo_alias())
|
||||
|
|
|
@ -37,7 +37,7 @@ pub struct RepoActor {
|
|||
generation: git::Generation,
|
||||
message_token: messages::MessageToken,
|
||||
repo_details: git::RepoDetails,
|
||||
webhook: config::server::InboundWebhook,
|
||||
webhook: config::server::Webhook,
|
||||
webhook_id: Option<config::WebhookId>, // INFO: if [None] then no webhook is configured
|
||||
webhook_auth: Option<config::WebhookAuth>, // INFO: if [None] then no webhook is configured
|
||||
last_main_commit: Option<git::Commit>,
|
||||
|
@ -53,7 +53,7 @@ impl RepoActor {
|
|||
pub fn new(
|
||||
repo_details: git::RepoDetails,
|
||||
forge: Box<dyn git::ForgeLike>,
|
||||
webhook: config::server::InboundWebhook,
|
||||
webhook: config::server::Webhook,
|
||||
generation: git::Generation,
|
||||
net: Network,
|
||||
repository_factory: Box<dyn git::repository::RepositoryFactory>,
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn a_webhook_url(
|
|||
forge_alias: &ForgeAlias,
|
||||
repo_alias: &RepoAlias,
|
||||
) -> git_next_config::server::WebhookUrl {
|
||||
config::server::InboundWebhook::new(a_name()).url(forge_alias, repo_alias)
|
||||
config::server::Webhook::new(a_name()).url(forge_alias, repo_alias)
|
||||
}
|
||||
|
||||
pub fn a_name() -> String {
|
||||
|
@ -179,8 +179,8 @@ pub fn a_message_token() -> MessageToken {
|
|||
MessageToken::default()
|
||||
}
|
||||
|
||||
pub fn a_webhook(url: &WebhookUrl) -> InboundWebhook {
|
||||
InboundWebhook::new(url.clone().into())
|
||||
pub fn a_webhook(url: &WebhookUrl) -> Webhook {
|
||||
Webhook::new(url.clone().into())
|
||||
}
|
||||
|
||||
pub fn a_forge() -> Box<MockForgeLike> {
|
||||
|
|
|
@ -7,7 +7,7 @@ use actor::{
|
|||
};
|
||||
use assert2::let_assert;
|
||||
use config::{
|
||||
server::{InboundWebhook, WebhookUrl},
|
||||
server::{Webhook, WebhookUrl},
|
||||
webhook::forge_notification::Body,
|
||||
BranchName, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, RegisteredWebhook,
|
||||
RepoAlias, RepoBranches, RepoConfig, ServerRepoConfig, WebhookAuth, WebhookId,
|
||||
|
@ -82,7 +82,7 @@ pub struct RepoActorView {
|
|||
pub generation: git::Generation,
|
||||
pub message_token: MessageToken,
|
||||
pub repo_details: git::RepoDetails,
|
||||
pub webhook: config::server::InboundWebhook,
|
||||
pub webhook: config::server::Webhook,
|
||||
pub webhook_id: Option<config::WebhookId>, // INFO: if [None] then no webhook is configured
|
||||
pub webhook_auth: Option<config::WebhookAuth>, // INFO: if [None] then no webhook is configured
|
||||
pub last_main_commit: Option<git::Commit>,
|
||||
|
|
|
@ -7,7 +7,7 @@ pub mod messages;
|
|||
|
||||
use actix::prelude::*;
|
||||
use git_next_config as config;
|
||||
use git_next_config::server::{InboundWebhook, ServerConfig, ServerStorage};
|
||||
use git_next_config::server::{ServerConfig, ServerStorage, Webhook};
|
||||
use git_next_config::{ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig};
|
||||
use git_next_git::{Generation, RepoDetails};
|
||||
use git_next_repo_actor::{messages::CloneRepo, RepoActor};
|
||||
|
@ -104,7 +104,7 @@ impl Server {
|
|||
forge_config: &ForgeConfig,
|
||||
forge_name: ForgeAlias,
|
||||
server_storage: &ServerStorage,
|
||||
webhook: &InboundWebhook,
|
||||
webhook: &Webhook,
|
||||
) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> {
|
||||
let span =
|
||||
tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config);
|
||||
|
@ -129,7 +129,7 @@ impl Server {
|
|||
forge_name: ForgeAlias,
|
||||
forge_config: ForgeConfig,
|
||||
server_storage: &ServerStorage,
|
||||
webhook: &InboundWebhook,
|
||||
webhook: &Webhook,
|
||||
) -> impl Fn((RepoAlias, &ServerRepoConfig)) -> (ForgeAlias, RepoAlias, RepoActor) {
|
||||
let server_storage = server_storage.clone();
|
||||
let webhook = webhook.clone();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//
|
||||
use crate::{tests::given, ReceiveServerConfig, Server};
|
||||
use actix::prelude::*;
|
||||
use git_next_config::server::{Http, InboundWebhook, Notification, ServerConfig, ServerStorage};
|
||||
use git_next_config::server::{Http, Notification, ServerConfig, ServerStorage, Webhook};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
sync::{Arc, RwLock},
|
||||
|
@ -21,7 +21,7 @@ async fn when_webhook_url_has_trailing_slash_should_not_send() {
|
|||
|
||||
// collaborators
|
||||
let http = Http::new("0.0.0.0".to_string(), 80);
|
||||
let webhook = InboundWebhook::new("http://localhost/".to_string()); // With trailing slash
|
||||
let webhook = Webhook::new("http://localhost/".to_string()); // With trailing slash
|
||||
let notifications = Notification::none();
|
||||
let server_storage = ServerStorage::new((fs.base()).to_path_buf());
|
||||
let repos = BTreeMap::default();
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
mod notify_user;
|
||||
mod shutdown_webhook;
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
//
|
||||
use actix::prelude::*;
|
||||
|
||||
use crate::{messages::NotifyUser, WebhookActor};
|
||||
|
||||
impl Handler<NotifyUser> for WebhookActor {
|
||||
type Result = ();
|
||||
|
||||
fn handle(&mut self, _msg: NotifyUser, _ctx: &mut Self::Context) -> Self::Result {
|
||||
// TODO: (#95) should notify user
|
||||
}
|
||||
}
|
|
@ -2,5 +2,3 @@
|
|||
use git_next_actor_macros::message;
|
||||
|
||||
message!(ShutdownWebhook: "Request to shutdown the Webhook actor");
|
||||
|
||||
message!(NotifyUser: String: "Request to send the message payload to the notification webhook");
|
||||
|
|
Loading…
Reference in a new issue