refactor(server): collapse type module into gitforge module
Some checks failed
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Has been cancelled

This commit is contained in:
Paul Campbell 2024-05-21 19:38:38 +01:00
parent 341dc97a51
commit df8ebc6af7
9 changed files with 24 additions and 27 deletions

View file

@ -20,7 +20,7 @@ pub async fn advance_next(
forge: gitforge::Forge, forge: gitforge::Forge,
repository: git::OpenRepository, repository: git::OpenRepository,
addr: Addr<super::RepoActor>, addr: Addr<super::RepoActor>,
message_token: super::MessageToken, message_token: gitforge::MessageToken,
) { ) {
let next_commit = find_next_commit_on_dev(next, dev_commit_history); let next_commit = find_next_commit_on_dev(next, dev_commit_history);
let Some(commit) = next_commit else { let Some(commit) = next_commit else {
@ -84,7 +84,7 @@ pub async fn advance_main(
forge: gitforge::Forge, forge: gitforge::Forge,
repository: git::OpenRepository, repository: git::OpenRepository,
addr: Addr<RepoActor>, addr: Addr<RepoActor>,
message_token: super::MessageToken, message_token: gitforge::MessageToken,
) { ) {
info!("Advancing main to next"); info!("Advancing main to next");
if let Err(err) = forge.branch_reset( if let Err(err) = forge.branch_reset(

View file

@ -13,7 +13,7 @@ use git_next_git::{self as git, Generation, RepoDetails};
use kxio::network::Network; use kxio::network::Network;
use tracing::{debug, info, warn, Instrument}; 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; use self::webhook::WebhookId;
@ -21,7 +21,7 @@ use self::webhook::WebhookId;
#[display("{}:{}:{}", generation, details.forge.forge_name(), details.repo_alias)] #[display("{}:{}:{}", generation, details.forge.forge_name(), details.repo_alias)]
pub struct RepoActor { pub struct RepoActor {
generation: Generation, generation: Generation,
message_token: MessageToken, message_token: gitforge::MessageToken,
details: RepoDetails, details: RepoDetails,
webhook: Webhook, webhook: Webhook,
webhook_id: Option<WebhookId>, // INFO: if [None] then no webhook is configured webhook_id: Option<WebhookId>, // INFO: if [None] then no webhook is configured
@ -49,7 +49,7 @@ impl RepoActor {
debug!(?forge, "new"); debug!(?forge, "new");
Self { Self {
generation, generation,
message_token: MessageToken::new(), message_token: gitforge::MessageToken::new(),
details, details,
webhook, webhook,
webhook_id: None, webhook_id: None,
@ -144,7 +144,7 @@ impl Handler<LoadedConfig> for RepoActor {
#[derive(derive_more::Constructor, Message)] #[derive(derive_more::Constructor, Message)]
#[rtype(result = "()")] #[rtype(result = "()")]
pub struct ValidateRepo { pub struct ValidateRepo {
message_token: MessageToken, message_token: gitforge::MessageToken,
} }
impl Handler<ValidateRepo> for RepoActor { impl Handler<ValidateRepo> for RepoActor {
type Result = (); type Result = ();

View file

@ -2,7 +2,7 @@ use actix::prelude::*;
use git_next_git as git; use git_next_git as git;
use tracing::{info, warn}; use tracing::{info, warn};
use crate::{actors::repo::ValidateRepo, gitforge, types::MessageToken}; use crate::{actors::repo::ValidateRepo, gitforge};
use super::AdvanceMainTo; use super::AdvanceMainTo;
@ -10,7 +10,7 @@ pub async fn check_next(
next: git::Commit, next: git::Commit,
addr: Addr<super::RepoActor>, addr: Addr<super::RepoActor>,
forge: gitforge::Forge, forge: gitforge::Forge,
message_token: MessageToken, message_token: gitforge::MessageToken,
) { ) {
// get the status - pass, fail, pending (all others map to fail, e.g. error) // get the status - pass, fail, pending (all others map to fail, e.g. error)
let status = forge.commit_status(&next).await; let status = forge.commit_status(&next).await;

View file

@ -13,8 +13,7 @@ use tracing::{error, info, warn};
use crate::{ use crate::{
actors::repo::{RepoActor, StartMonitoring, ValidateRepo}, actors::repo::{RepoActor, StartMonitoring, ValidateRepo},
gitforge::{self, forgejo::branch::ValidatedPositions}, gitforge,
types::MessageToken,
}; };
struct ForgeJo; struct ForgeJo;
@ -56,10 +55,10 @@ impl super::ForgeLike for ForgeJoEnv {
repository: git::OpenRepository, repository: git::OpenRepository,
repo_config: RepoConfig, repo_config: RepoConfig,
addr: Addr<RepoActor>, addr: Addr<RepoActor>,
message_token: MessageToken, message_token: gitforge::MessageToken,
) { ) {
match branch::validate_positions(self, &repository, repo_config).await { match branch::validate_positions(self, &repository, repo_config).await {
Ok(ValidatedPositions { Ok(branch::ValidatedPositions {
main, main,
next, next,
dev, dev,

View file

@ -2,7 +2,7 @@ use git::OpenRepository;
use git_next_config::{BranchName, GitDir, RepoConfig}; use git_next_config::{BranchName, GitDir, RepoConfig};
use git_next_git::{self as git, GitRef}; use git_next_git::{self as git, GitRef};
use crate::{actors::repo::RepoActor, gitforge, types::MessageToken}; use crate::{actors::repo::RepoActor, gitforge};
struct MockForge; struct MockForge;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -35,7 +35,7 @@ impl super::ForgeLike for MockForgeEnv {
_repository: OpenRepository, _repository: OpenRepository,
_repo_config: RepoConfig, _repo_config: RepoConfig,
_addr: actix::prelude::Addr<RepoActor>, _addr: actix::prelude::Addr<RepoActor>,
_message_token: MessageToken, _message_token: gitforge::MessageToken,
) { ) {
todo!() todo!()
} }

View file

@ -19,8 +19,6 @@ pub use types::*;
mod errors; mod errors;
pub use errors::*; pub use errors::*;
use crate::types::MessageToken;
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait ForgeLike { pub trait ForgeLike {
fn name(&self) -> String; fn name(&self) -> String;

View file

@ -13,3 +13,14 @@ pub struct CommitHistories {
pub next: Vec<git::Commit>, pub next: Vec<git::Commit>,
pub dev: Vec<git::Commit>, pub dev: Vec<git::Commit>,
} }
#[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)
}
}

View file

@ -1,7 +1,6 @@
mod actors; mod actors;
mod config; mod config;
pub mod gitforge; pub mod gitforge;
pub mod types;
use actix::prelude::*; use actix::prelude::*;

View file

@ -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)
}
}