forked from kemitix/git-next
refactor: improve consistency of use of git types
This commit is contained in:
parent
f2af849d0b
commit
639223fcaa
10 changed files with 42 additions and 34 deletions
|
@ -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<Vec<BranchName>, crate::branch::Error> {
|
||||
let hostname = &repo_details.forge.hostname();
|
||||
|
|
|
@ -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<git::commit::Histories, network::NetworkError> {
|
||||
|
@ -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<git::Commit>,
|
||||
net: &kxio::network::Network,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()?;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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!()
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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<WebhookId>, // INFO: if [None] then no webhook is configured
|
||||
webhook_auth: Option<WebhookAuth>, // 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 {
|
||||
|
|
|
@ -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<super::RepoActor>,
|
||||
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<WebhookId> {
|
||||
|
|
|
@ -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<T> = core::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue