From df8ebc6af7c5730e12d91ef740b506867b5097b6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 21 May 2024 19:38:38 +0100 Subject: [PATCH] refactor(server): collapse type module into gitforge module --- crates/server/src/actors/repo/branch.rs | 4 ++-- crates/server/src/actors/repo/mod.rs | 8 ++++---- crates/server/src/actors/repo/status.rs | 4 ++-- crates/server/src/gitforge/forgejo/mod.rs | 7 +++---- crates/server/src/gitforge/mock_forge.rs | 4 ++-- crates/server/src/gitforge/mod.rs | 2 -- crates/server/src/gitforge/types.rs | 11 +++++++++++ crates/server/src/lib.rs | 1 - crates/server/src/types.rs | 10 ---------- 9 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 crates/server/src/types.rs diff --git a/crates/server/src/actors/repo/branch.rs b/crates/server/src/actors/repo/branch.rs index 5c79eb54..b7e01d8e 100644 --- a/crates/server/src/actors/repo/branch.rs +++ b/crates/server/src/actors/repo/branch.rs @@ -20,7 +20,7 @@ pub async fn advance_next( forge: gitforge::Forge, repository: git::OpenRepository, addr: Addr, - message_token: super::MessageToken, + message_token: gitforge::MessageToken, ) { let next_commit = find_next_commit_on_dev(next, dev_commit_history); let Some(commit) = next_commit else { @@ -84,7 +84,7 @@ pub async fn advance_main( forge: gitforge::Forge, repository: git::OpenRepository, addr: Addr, - message_token: super::MessageToken, + message_token: gitforge::MessageToken, ) { info!("Advancing main to next"); if let Err(err) = forge.branch_reset( diff --git a/crates/server/src/actors/repo/mod.rs b/crates/server/src/actors/repo/mod.rs index 496817c6..68ba532c 100644 --- a/crates/server/src/actors/repo/mod.rs +++ b/crates/server/src/actors/repo/mod.rs @@ -13,7 +13,7 @@ use git_next_git::{self as git, Generation, RepoDetails}; use kxio::network::Network; use tracing::{debug, info, warn, Instrument}; -use crate::{actors::repo::webhook::WebhookAuth, config::Webhook, gitforge, types::MessageToken}; +use crate::{actors::repo::webhook::WebhookAuth, config::Webhook, gitforge}; use self::webhook::WebhookId; @@ -21,7 +21,7 @@ use self::webhook::WebhookId; #[display("{}:{}:{}", generation, details.forge.forge_name(), details.repo_alias)] pub struct RepoActor { generation: Generation, - message_token: MessageToken, + message_token: gitforge::MessageToken, details: RepoDetails, webhook: Webhook, webhook_id: Option, // INFO: if [None] then no webhook is configured @@ -49,7 +49,7 @@ impl RepoActor { debug!(?forge, "new"); Self { generation, - message_token: MessageToken::new(), + message_token: gitforge::MessageToken::new(), details, webhook, webhook_id: None, @@ -144,7 +144,7 @@ impl Handler for RepoActor { #[derive(derive_more::Constructor, Message)] #[rtype(result = "()")] pub struct ValidateRepo { - message_token: MessageToken, + message_token: gitforge::MessageToken, } impl Handler for RepoActor { type Result = (); diff --git a/crates/server/src/actors/repo/status.rs b/crates/server/src/actors/repo/status.rs index 9b2eb33a..c1439275 100644 --- a/crates/server/src/actors/repo/status.rs +++ b/crates/server/src/actors/repo/status.rs @@ -2,7 +2,7 @@ use actix::prelude::*; use git_next_git as git; use tracing::{info, warn}; -use crate::{actors::repo::ValidateRepo, gitforge, types::MessageToken}; +use crate::{actors::repo::ValidateRepo, gitforge}; use super::AdvanceMainTo; @@ -10,7 +10,7 @@ pub async fn check_next( next: git::Commit, addr: Addr, forge: gitforge::Forge, - message_token: MessageToken, + message_token: gitforge::MessageToken, ) { // get the status - pass, fail, pending (all others map to fail, e.g. error) let status = forge.commit_status(&next).await; diff --git a/crates/server/src/gitforge/forgejo/mod.rs b/crates/server/src/gitforge/forgejo/mod.rs index 21b0ca43..5d1de71b 100644 --- a/crates/server/src/gitforge/forgejo/mod.rs +++ b/crates/server/src/gitforge/forgejo/mod.rs @@ -13,8 +13,7 @@ use tracing::{error, info, warn}; use crate::{ actors::repo::{RepoActor, StartMonitoring, ValidateRepo}, - gitforge::{self, forgejo::branch::ValidatedPositions}, - types::MessageToken, + gitforge, }; struct ForgeJo; @@ -56,10 +55,10 @@ impl super::ForgeLike for ForgeJoEnv { repository: git::OpenRepository, repo_config: RepoConfig, addr: Addr, - message_token: MessageToken, + message_token: gitforge::MessageToken, ) { match branch::validate_positions(self, &repository, repo_config).await { - Ok(ValidatedPositions { + Ok(branch::ValidatedPositions { main, next, dev, diff --git a/crates/server/src/gitforge/mock_forge.rs b/crates/server/src/gitforge/mock_forge.rs index ce2014b2..d9f66687 100644 --- a/crates/server/src/gitforge/mock_forge.rs +++ b/crates/server/src/gitforge/mock_forge.rs @@ -2,7 +2,7 @@ use git::OpenRepository; use git_next_config::{BranchName, GitDir, RepoConfig}; use git_next_git::{self as git, GitRef}; -use crate::{actors::repo::RepoActor, gitforge, types::MessageToken}; +use crate::{actors::repo::RepoActor, gitforge}; struct MockForge; #[derive(Clone, Debug)] @@ -35,7 +35,7 @@ impl super::ForgeLike for MockForgeEnv { _repository: OpenRepository, _repo_config: RepoConfig, _addr: actix::prelude::Addr, - _message_token: MessageToken, + _message_token: gitforge::MessageToken, ) { todo!() } diff --git a/crates/server/src/gitforge/mod.rs b/crates/server/src/gitforge/mod.rs index 49fba9de..3786e3f2 100644 --- a/crates/server/src/gitforge/mod.rs +++ b/crates/server/src/gitforge/mod.rs @@ -19,8 +19,6 @@ pub use types::*; mod errors; pub use errors::*; -use crate::types::MessageToken; - #[async_trait::async_trait] pub trait ForgeLike { fn name(&self) -> String; diff --git a/crates/server/src/gitforge/types.rs b/crates/server/src/gitforge/types.rs index 6bb62e21..5ee31612 100644 --- a/crates/server/src/gitforge/types.rs +++ b/crates/server/src/gitforge/types.rs @@ -13,3 +13,14 @@ pub struct CommitHistories { pub next: Vec, pub dev: Vec, } + +#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Display)] +pub struct MessageToken(u32); +impl MessageToken { + pub fn new() -> Self { + Self::default() + } + pub const fn next(&self) -> Self { + Self(self.0 + 1) + } +} diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index 80f5a3c0..8a71abb0 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -1,7 +1,6 @@ mod actors; mod config; pub mod gitforge; -pub mod types; use actix::prelude::*; diff --git a/crates/server/src/types.rs b/crates/server/src/types.rs deleted file mode 100644 index 370ef115..00000000 --- a/crates/server/src/types.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Display)] -pub struct MessageToken(u32); -impl MessageToken { - pub fn new() -> Self { - Self::default() - } - pub const fn next(&self) -> Self { - Self(self.0 + 1) - } -}