diff --git a/crates/git/src/commit.rs b/crates/git/src/commit.rs index 1347b4e..59693e1 100644 --- a/crates/git/src/commit.rs +++ b/crates/git/src/commit.rs @@ -18,3 +18,17 @@ pub struct Sha(String); #[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)] pub struct Message(String); + +#[derive(Debug)] +pub enum Status { + Pass, + Fail, + Pending, +} + +#[derive(Clone, Debug)] +pub struct Histories { + pub main: Vec, + pub next: Vec, + pub dev: Vec, +} diff --git a/crates/gitforge/src/forgejo/branch/validate_positions.rs b/crates/gitforge/src/forgejo/branch/validate_positions.rs index ae8cde0..6b92c45 100644 --- a/crates/gitforge/src/forgejo/branch/validate_positions.rs +++ b/crates/gitforge/src/forgejo/branch/validate_positions.rs @@ -3,7 +3,7 @@ use git_next_git::{self as git, RepoDetails}; use kxio::network; use tracing::{debug, error, info, warn}; -use crate::{forgejo::ForgeJoEnv, validation, CommitHistories, ForgeLike as _}; +use crate::{forgejo::ForgeJoEnv, validation, ForgeLike as _}; pub async fn validate_positions( forge: &ForgeJoEnv, @@ -148,7 +148,7 @@ async fn get_commit_histories( repo_details: &RepoDetails, repo_config: &RepoConfig, net: &network::Network, -) -> Result { +) -> Result { let main = (get_commit_history(repo_details, &repo_config.branches().main(), vec![], net).await)?; let main_head = main[0].clone(); @@ -173,7 +173,7 @@ async fn get_commit_histories( dev = dev.len(), "Commit histories" ); - let histories = CommitHistories { main, next, dev }; + let histories = git::commit::Histories { main, next, dev }; Ok(histories) } diff --git a/crates/gitforge/src/forgejo/mod.rs b/crates/gitforge/src/forgejo/mod.rs index a37a14b..b27e556 100644 --- a/crates/gitforge/src/forgejo/mod.rs +++ b/crates/gitforge/src/forgejo/mod.rs @@ -7,7 +7,7 @@ use git_next_git::{self as git, GitRef, RepoDetails, Repository}; use kxio::network::{self, Network}; use tracing::{error, info, warn}; -use crate::{validation, CommitStatus}; +use crate::validation; struct ForgeJo; #[derive(Clone, Debug)] @@ -62,7 +62,7 @@ impl super::ForgeLike for ForgeJoEnv { repository.push(&self.repo_details, branch_name, to_commit, force) } - async fn commit_status(&self, commit: &git::Commit) -> CommitStatus { + async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status { let repo_details = &self.repo_details; let hostname = &repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; @@ -87,21 +87,21 @@ impl super::ForgeLike for ForgeJoEnv { Ok(response) => { match response.response_body() { Some(status) => match status.state { - CommitStatusState::Success => CommitStatus::Pass, - CommitStatusState::Pending => CommitStatus::Pending, - CommitStatusState::Failure => CommitStatus::Fail, - CommitStatusState::Error => CommitStatus::Fail, - CommitStatusState::Blank => CommitStatus::Pending, + CommitStatusState::Success => git::commit::Status::Pass, + CommitStatusState::Pending => git::commit::Status::Pending, + CommitStatusState::Failure => git::commit::Status::Fail, + CommitStatusState::Error => git::commit::Status::Fail, + CommitStatusState::Blank => git::commit::Status::Pending, }, None => { warn!("No status found for commit"); - CommitStatus::Pending // assume issue is transient and allow retry + git::commit::Status::Pending // assume issue is transient and allow retry } } } Err(e) => { error!(?e, "Failed to get commit status"); - CommitStatus::Pending // assume issue is transient and allow retry + git::commit::Status::Pending // assume issue is transient and allow retry } } } diff --git a/crates/gitforge/src/lib.rs b/crates/gitforge/src/lib.rs index d07d931..55d5a86 100644 --- a/crates/gitforge/src/lib.rs +++ b/crates/gitforge/src/lib.rs @@ -13,9 +13,6 @@ mod github; mod mock_forge; -mod types; -pub use types::*; - #[async_trait::async_trait] pub trait ForgeLike { fn name(&self) -> String; @@ -48,7 +45,7 @@ pub trait ForgeLike { ) -> git::push::Result; /// Checks the results of any (e.g. CI) status checks for the commit. - async fn commit_status(&self, commit: &git::Commit) -> CommitStatus; + async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status; /// Clones a repo to disk. fn repo_clone(&self, gitdir: GitDir) -> Result; diff --git a/crates/gitforge/src/mock_forge.rs b/crates/gitforge/src/mock_forge.rs index b324cb5..c809049 100644 --- a/crates/gitforge/src/mock_forge.rs +++ b/crates/gitforge/src/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::{branch, file, validation, CommitStatus}; +use crate::{branch, file, validation}; struct MockForge; #[derive(Clone, Debug)] @@ -48,7 +48,7 @@ impl super::ForgeLike for MockForgeEnv { todo!() } - async fn commit_status(&self, _commit: &git::Commit) -> CommitStatus { + async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status { todo!() } diff --git a/crates/gitforge/src/types.rs b/crates/gitforge/src/types.rs deleted file mode 100644 index 5ee3161..0000000 --- a/crates/gitforge/src/types.rs +++ /dev/null @@ -1,26 +0,0 @@ -use git_next_git as git; - -#[derive(Debug)] -pub enum CommitStatus { - Pass, - Fail, - Pending, -} - -#[derive(Clone, Debug)] -pub struct CommitHistories { - pub main: Vec, - 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/repo-actor/src/branch.rs b/crates/repo-actor/src/branch.rs index eaf561f..d63d011 100644 --- a/crates/repo-actor/src/branch.rs +++ b/crates/repo-actor/src/branch.rs @@ -6,7 +6,7 @@ use git_next_config::RepoConfig; use git_next_git as git; use tracing::{info, warn}; -use crate::{gitforge, ValidateRepo}; +use crate::{gitforge, MessageToken, ValidateRepo}; // advance next to the next commit towards the head of the dev branch #[tracing::instrument(fields(next), skip_all)] @@ -17,7 +17,7 @@ pub async fn advance_next( forge: gitforge::Forge, repository: git::OpenRepository, addr: Addr, - message_token: gitforge::MessageToken, + message_token: MessageToken, ) { let next_commit = find_next_commit_on_dev(next, dev_commit_history); let Some(commit) = next_commit else { diff --git a/crates/repo-actor/src/lib.rs b/crates/repo-actor/src/lib.rs index e8210f4..22bce3d 100644 --- a/crates/repo-actor/src/lib.rs +++ b/crates/repo-actor/src/lib.rs @@ -27,7 +27,7 @@ use self::webhook::WebhookId; #[display("{}:{}:{}", generation, details.forge.forge_name(), details.repo_alias)] pub struct RepoActor { generation: Generation, - message_token: gitforge::MessageToken, + message_token: MessageToken, details: RepoDetails, webhook: Webhook, webhook_id: Option, // INFO: if [None] then no webhook is configured @@ -55,7 +55,7 @@ impl RepoActor { debug!(?forge, "new"); Self { generation, - message_token: gitforge::MessageToken::new(), + message_token: MessageToken::new(), details, webhook, webhook_id: None, @@ -150,7 +150,7 @@ impl Handler for RepoActor { #[derive(derive_more::Constructor, Message)] #[rtype(result = "()")] pub struct ValidateRepo { - message_token: gitforge::MessageToken, + message_token: MessageToken, } impl Handler for RepoActor { type Result = (); @@ -305,3 +305,14 @@ impl Handler for RepoActor { .wait(ctx); } } + +#[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/repo-actor/src/status.rs b/crates/repo-actor/src/status.rs index eec0269..95e00b4 100644 --- a/crates/repo-actor/src/status.rs +++ b/crates/repo-actor/src/status.rs @@ -2,31 +2,30 @@ use actix::prelude::*; use git_next_git as git; -use git_next_gitforge::{CommitStatus, Forge, MessageToken}; use tracing::{info, warn}; -use crate::ValidateRepo; +use crate::{MessageToken, ValidateRepo}; use super::AdvanceMainTo; pub async fn check_next( next: git::Commit, addr: Addr, - forge: Forge, + forge: git_next_gitforge::Forge, message_token: MessageToken, ) { // get the status - pass, fail, pending (all others map to fail, e.g. error) let status = forge.commit_status(&next).await; info!(?status, "Checking next branch"); match status { - CommitStatus::Pass => { + git::commit::Status::Pass => { addr.do_send(AdvanceMainTo(next)); } - CommitStatus::Pending => { + git::commit::Status::Pending => { tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; addr.do_send(ValidateRepo { message_token }); } - CommitStatus::Fail => { + git::commit::Status::Fail => { warn!("Checks have failed"); } }