From 639223fcaa1d570fa1ddf315f8a688c16f1a1cea Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 23 May 2024 16:19:28 +0100 Subject: [PATCH] refactor: improve consistency of use of git types --- crates/forge/src/forgejo/branch/get_all.rs | 4 ++-- .../forge/src/forgejo/branch/validate_positions.rs | 6 +++--- crates/forge/src/forgejo/file.rs | 4 ++-- crates/forge/src/forgejo/mod.rs | 14 +++++++++----- crates/forge/src/lib.rs | 6 +++--- crates/forge/src/mock_forge.rs | 4 ++-- crates/forge/src/tests/forgejo.rs | 6 +++--- crates/repo-actor/src/lib.rs | 10 +++++----- crates/repo-actor/src/webhook.rs | 12 ++++++++---- crates/server/src/config/tests.rs | 10 +++++----- 10 files changed, 42 insertions(+), 34 deletions(-) diff --git a/crates/forge/src/forgejo/branch/get_all.rs b/crates/forge/src/forgejo/branch/get_all.rs index 4ac166eb..4778da1e 100644 --- a/crates/forge/src/forgejo/branch/get_all.rs +++ b/crates/forge/src/forgejo/branch/get_all.rs @@ -1,10 +1,10 @@ use git_next_config::BranchName; -use git_next_git::RepoDetails; +use git_next_git as git; use kxio::network::{self, Network}; use tracing::error; pub async fn get_all( - repo_details: &RepoDetails, + repo_details: &git::RepoDetails, net: &Network, ) -> Result, crate::branch::Error> { let hostname = &repo_details.forge.hostname(); diff --git a/crates/forge/src/forgejo/branch/validate_positions.rs b/crates/forge/src/forgejo/branch/validate_positions.rs index 6b92c458..15eba925 100644 --- a/crates/forge/src/forgejo/branch/validate_positions.rs +++ b/crates/forge/src/forgejo/branch/validate_positions.rs @@ -1,5 +1,5 @@ use git_next_config::{BranchName, RepoConfig}; -use git_next_git::{self as git, RepoDetails}; +use git_next_git as git; use kxio::network; use tracing::{debug, error, info, warn}; @@ -145,7 +145,7 @@ pub async fn validate_positions( } async fn get_commit_histories( - repo_details: &RepoDetails, + repo_details: &git::RepoDetails, repo_config: &RepoConfig, net: &network::Network, ) -> Result { @@ -179,7 +179,7 @@ async fn get_commit_histories( #[tracing::instrument(fields(%branch_name),skip_all)] async fn get_commit_history( - repo_details: &RepoDetails, + repo_details: &git::RepoDetails, branch_name: &BranchName, find_commits: Vec, net: &kxio::network::Network, diff --git a/crates/forge/src/forgejo/file.rs b/crates/forge/src/forgejo/file.rs index 623d0176..173595be 100644 --- a/crates/forge/src/forgejo/file.rs +++ b/crates/forge/src/forgejo/file.rs @@ -1,10 +1,10 @@ use git_next_config::BranchName; -use git_next_git::RepoDetails; +use git_next_git as git; use kxio::network::{self, Network}; use tracing::{error, warn}; pub(super) async fn contents_get( - repo_details: &RepoDetails, + repo_details: &git::RepoDetails, net: &Network, branch: &BranchName, file_path: &str, diff --git a/crates/forge/src/forgejo/mod.rs b/crates/forge/src/forgejo/mod.rs index b27e556b..5fe958f1 100644 --- a/crates/forge/src/forgejo/mod.rs +++ b/crates/forge/src/forgejo/mod.rs @@ -3,7 +3,7 @@ mod file; use git::OpenRepository; use git_next_config::{BranchName, GitDir, RepoConfig}; -use git_next_git::{self as git, GitRef, RepoDetails, Repository}; +use git_next_git as git; use kxio::network::{self, Network}; use tracing::{error, info, warn}; @@ -12,12 +12,16 @@ use crate::validation; struct ForgeJo; #[derive(Clone, Debug)] pub struct ForgeJoEnv { - repo_details: RepoDetails, + repo_details: git::RepoDetails, net: Network, - repo: Repository, + repo: git::Repository, } impl ForgeJoEnv { - pub(super) const fn new(repo_details: RepoDetails, net: Network, repo: Repository) -> Self { + pub(super) const fn new( + repo_details: git::RepoDetails, + net: Network, + repo: git::Repository, + ) -> Self { Self { repo_details, net, @@ -55,7 +59,7 @@ impl super::ForgeLike for ForgeJoEnv { &self, repository: &git::OpenRepository, branch_name: BranchName, - to_commit: GitRef, + to_commit: git::GitRef, force: git::push::Force, ) -> git::push::Result { repository.fetch()?; diff --git a/crates/forge/src/lib.rs b/crates/forge/src/lib.rs index 55d5a862..0718b19f 100644 --- a/crates/forge/src/lib.rs +++ b/crates/forge/src/lib.rs @@ -2,7 +2,7 @@ use git::OpenRepository; use git_next_config::{BranchName, GitDir, RepoConfig}; -use git_next_git::{self as git, GitRef, RepoDetails}; +use git_next_git as git; use kxio::network::Network; #[cfg(feature = "forgejo")] @@ -40,7 +40,7 @@ pub trait ForgeLike { &self, repository: &OpenRepository, branch_name: BranchName, - to_commit: GitRef, + to_commit: git::GitRef, force: git::push::Force, ) -> git::push::Result; @@ -66,7 +66,7 @@ impl Forge { } #[cfg(feature = "forgejo")] pub const fn new_forgejo( - repo_details: RepoDetails, + repo_details: git::RepoDetails, net: Network, repo: git::Repository, ) -> Self { diff --git a/crates/forge/src/mock_forge.rs b/crates/forge/src/mock_forge.rs index d9dd243d..81a81d71 100644 --- a/crates/forge/src/mock_forge.rs +++ b/crates/forge/src/mock_forge.rs @@ -3,7 +3,7 @@ use git::OpenRepository; use git_next_config::{BranchName, GitDir, RepoConfig}; -use git_next_git::{self as git, GitRef}; +use git_next_git as git; use crate::{branch, file, validation}; @@ -45,7 +45,7 @@ impl super::ForgeLike for MockForgeEnv { &self, _repository: &OpenRepository, _branch_name: BranchName, - _to_commit: GitRef, + _to_commit: git::GitRef, _force: git::push::Force, ) -> git::push::Result { todo!() diff --git a/crates/forge/src/tests/forgejo.rs b/crates/forge/src/tests/forgejo.rs index 58fc720c..1b7d1bb6 100644 --- a/crates/forge/src/tests/forgejo.rs +++ b/crates/forge/src/tests/forgejo.rs @@ -4,7 +4,7 @@ use assert2::let_assert; use git_next_config::{self as config, ForgeType, RepoConfigSource}; use kxio::network::{MockNetwork, StatusCode}; -use git_next_git::{self as git, Generation}; +use git_next_git as git; use super::*; @@ -17,7 +17,7 @@ fn test_name() { let (repo, _reality) = git::repository::mock(); let repo_details = git::common::repo_details( 1, - Generation::new(), + git::Generation::new(), config::common::forge_details(1, ForgeType::MockForge), Some(config::common::repo_config(1, RepoConfigSource::Repo)), GitDir::new(fs.base()), @@ -45,7 +45,7 @@ async fn test_branches_get() { let repo_details = git::common::repo_details( 1, - Generation::new(), + git::Generation::new(), config::common::forge_details(1, ForgeType::MockForge), Some(config::common::repo_config(1, RepoConfigSource::Repo)), GitDir::new(fs.base()), diff --git a/crates/repo-actor/src/lib.rs b/crates/repo-actor/src/lib.rs index ec5eb9aa..8ee4b795 100644 --- a/crates/repo-actor/src/lib.rs +++ b/crates/repo-actor/src/lib.rs @@ -13,7 +13,7 @@ use actix::prelude::*; use git::OpenRepository; use git_next_config::{server::Webhook, ForgeType, RepoConfig, RepoConfigSource}; use git_next_forge as forge; -use git_next_git::{self as git, Generation, RepoDetails}; +use git_next_git as git; use kxio::network::Network; use tracing::{debug, info, warn, Instrument}; @@ -26,9 +26,9 @@ use self::webhook::WebhookId; #[derive(Debug, derive_more::Display)] #[display("{}:{}:{}", generation, details.forge.forge_name(), details.repo_alias)] pub struct RepoActor { - generation: Generation, + generation: git::Generation, message_token: MessageToken, - details: RepoDetails, + details: git::RepoDetails, webhook: Webhook, webhook_id: Option, // INFO: if [None] then no webhook is configured webhook_auth: Option, // INFO: if [None] then no webhook is configured @@ -41,9 +41,9 @@ pub struct RepoActor { } impl RepoActor { pub fn new( - details: RepoDetails, + details: git::RepoDetails, webhook: Webhook, - generation: Generation, + generation: git::Generation, net: Network, repo: git::Repository, ) -> Self { diff --git a/crates/repo-actor/src/webhook.rs b/crates/repo-actor/src/webhook.rs index 431a2a8b..f6229683 100644 --- a/crates/repo-actor/src/webhook.rs +++ b/crates/repo-actor/src/webhook.rs @@ -3,7 +3,7 @@ use git_next_config::{ server::{Webhook, WebhookUrl}, BranchName, RepoAlias, RepoBranches, }; -use git_next_git::{self as git, RepoDetails}; +use git_next_git as git; use kxio::network::{self, json}; use tracing::{info, warn}; use ulid::DecodeError; @@ -36,7 +36,11 @@ impl WebhookAuth { } #[tracing::instrument(skip_all, fields(%webhook_id))] -pub async fn unregister(webhook_id: WebhookId, repo_details: RepoDetails, net: network::Network) { +pub async fn unregister( + webhook_id: WebhookId, + repo_details: git::RepoDetails, + net: network::Network, +) { let hostname = &repo_details.forge.hostname(); let repo_path = repo_details.repo_path; use secrecy::ExposeSecret; @@ -62,7 +66,7 @@ pub async fn unregister(webhook_id: WebhookId, repo_details: RepoDetails, net: n #[tracing::instrument(skip_all)] pub async fn register( - repo_details: RepoDetails, + repo_details: git::RepoDetails, webhook: Webhook, addr: actix::prelude::Addr, net: network::Network, @@ -121,7 +125,7 @@ pub async fn register( } async fn find_existing_webhooks( - repo_details: &RepoDetails, + repo_details: &git::RepoDetails, webhook_url: &WebhookUrl, net: &network::Network, ) -> Vec { diff --git a/crates/server/src/config/tests.rs b/crates/server/src/config/tests.rs index 5d82ea91..e2e6d0d4 100644 --- a/crates/server/src/config/tests.rs +++ b/crates/server/src/config/tests.rs @@ -5,7 +5,7 @@ use git_next_config::{ self as config, ForgeType, GitDir, Hostname, RepoBranches, RepoConfig, RepoConfigSource, RepoPath, }; -use git_next_git::{self as git, Generation, GitRemote}; +use git_next_git as git; type Result = core::result::Result>; @@ -50,7 +50,7 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> { let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let mut repo_details = git::common::repo_details( 1, - Generation::new(), + git::Generation::new(), config::common::forge_details(1, ForgeType::MockForge), None, GitDir::new(root), // Server GitDir - should be ignored @@ -81,7 +81,7 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> { let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let mut repo_details = git::common::repo_details( 1, - Generation::new(), + git::Generation::new(), config::common::forge_details(1, ForgeType::MockForge), None, GitDir::new(root), // Server GitDir - should be ignored @@ -103,7 +103,7 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> { let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let mut repo_details = git::common::repo_details( 1, - Generation::new(), + git::Generation::new(), config::common::forge_details(1, ForgeType::MockForge), None, GitDir::new(root), // Server GitDir - should be ignored @@ -118,7 +118,7 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> { #[test] fn git_remote_to_string_is_as_expected() { - let git_remote = GitRemote::new(Hostname::new("foo"), RepoPath::new("bar".to_string())); + let git_remote = git::GitRemote::new(Hostname::new("foo"), RepoPath::new("bar".to_string())); let as_string = git_remote.to_string(); assert_eq!(as_string, "foo:bar");