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_config::BranchName;
|
||||||
use git_next_git::RepoDetails;
|
use git_next_git as git;
|
||||||
use kxio::network::{self, Network};
|
use kxio::network::{self, Network};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
pub async fn get_all(
|
pub async fn get_all(
|
||||||
repo_details: &RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
net: &Network,
|
net: &Network,
|
||||||
) -> Result<Vec<BranchName>, crate::branch::Error> {
|
) -> Result<Vec<BranchName>, crate::branch::Error> {
|
||||||
let hostname = &repo_details.forge.hostname();
|
let hostname = &repo_details.forge.hostname();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use git_next_config::{BranchName, RepoConfig};
|
use git_next_config::{BranchName, RepoConfig};
|
||||||
use git_next_git::{self as git, RepoDetails};
|
use git_next_git as git;
|
||||||
use kxio::network;
|
use kxio::network;
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ pub async fn validate_positions(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_commit_histories(
|
async fn get_commit_histories(
|
||||||
repo_details: &RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
repo_config: &RepoConfig,
|
repo_config: &RepoConfig,
|
||||||
net: &network::Network,
|
net: &network::Network,
|
||||||
) -> Result<git::commit::Histories, network::NetworkError> {
|
) -> Result<git::commit::Histories, network::NetworkError> {
|
||||||
|
@ -179,7 +179,7 @@ async fn get_commit_histories(
|
||||||
|
|
||||||
#[tracing::instrument(fields(%branch_name),skip_all)]
|
#[tracing::instrument(fields(%branch_name),skip_all)]
|
||||||
async fn get_commit_history(
|
async fn get_commit_history(
|
||||||
repo_details: &RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
branch_name: &BranchName,
|
branch_name: &BranchName,
|
||||||
find_commits: Vec<git::Commit>,
|
find_commits: Vec<git::Commit>,
|
||||||
net: &kxio::network::Network,
|
net: &kxio::network::Network,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use git_next_config::BranchName;
|
use git_next_config::BranchName;
|
||||||
use git_next_git::RepoDetails;
|
use git_next_git as git;
|
||||||
use kxio::network::{self, Network};
|
use kxio::network::{self, Network};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
|
|
||||||
pub(super) async fn contents_get(
|
pub(super) async fn contents_get(
|
||||||
repo_details: &RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
net: &Network,
|
net: &Network,
|
||||||
branch: &BranchName,
|
branch: &BranchName,
|
||||||
file_path: &str,
|
file_path: &str,
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod file;
|
||||||
|
|
||||||
use git::OpenRepository;
|
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, RepoDetails, Repository};
|
use git_next_git as git;
|
||||||
use kxio::network::{self, Network};
|
use kxio::network::{self, Network};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
|
@ -12,12 +12,16 @@ use crate::validation;
|
||||||
struct ForgeJo;
|
struct ForgeJo;
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ForgeJoEnv {
|
pub struct ForgeJoEnv {
|
||||||
repo_details: RepoDetails,
|
repo_details: git::RepoDetails,
|
||||||
net: Network,
|
net: Network,
|
||||||
repo: Repository,
|
repo: git::Repository,
|
||||||
}
|
}
|
||||||
impl ForgeJoEnv {
|
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 {
|
Self {
|
||||||
repo_details,
|
repo_details,
|
||||||
net,
|
net,
|
||||||
|
@ -55,7 +59,7 @@ impl super::ForgeLike for ForgeJoEnv {
|
||||||
&self,
|
&self,
|
||||||
repository: &git::OpenRepository,
|
repository: &git::OpenRepository,
|
||||||
branch_name: BranchName,
|
branch_name: BranchName,
|
||||||
to_commit: GitRef,
|
to_commit: git::GitRef,
|
||||||
force: git::push::Force,
|
force: git::push::Force,
|
||||||
) -> git::push::Result {
|
) -> git::push::Result {
|
||||||
repository.fetch()?;
|
repository.fetch()?;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use git::OpenRepository;
|
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, RepoDetails};
|
use git_next_git as git;
|
||||||
use kxio::network::Network;
|
use kxio::network::Network;
|
||||||
|
|
||||||
#[cfg(feature = "forgejo")]
|
#[cfg(feature = "forgejo")]
|
||||||
|
@ -40,7 +40,7 @@ pub trait ForgeLike {
|
||||||
&self,
|
&self,
|
||||||
repository: &OpenRepository,
|
repository: &OpenRepository,
|
||||||
branch_name: BranchName,
|
branch_name: BranchName,
|
||||||
to_commit: GitRef,
|
to_commit: git::GitRef,
|
||||||
force: git::push::Force,
|
force: git::push::Force,
|
||||||
) -> git::push::Result;
|
) -> git::push::Result;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ impl Forge {
|
||||||
}
|
}
|
||||||
#[cfg(feature = "forgejo")]
|
#[cfg(feature = "forgejo")]
|
||||||
pub const fn new_forgejo(
|
pub const fn new_forgejo(
|
||||||
repo_details: RepoDetails,
|
repo_details: git::RepoDetails,
|
||||||
net: Network,
|
net: Network,
|
||||||
repo: git::Repository,
|
repo: git::Repository,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use git::OpenRepository;
|
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 as git;
|
||||||
|
|
||||||
use crate::{branch, file, validation};
|
use crate::{branch, file, validation};
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ impl super::ForgeLike for MockForgeEnv {
|
||||||
&self,
|
&self,
|
||||||
_repository: &OpenRepository,
|
_repository: &OpenRepository,
|
||||||
_branch_name: BranchName,
|
_branch_name: BranchName,
|
||||||
_to_commit: GitRef,
|
_to_commit: git::GitRef,
|
||||||
_force: git::push::Force,
|
_force: git::push::Force,
|
||||||
) -> git::push::Result {
|
) -> git::push::Result {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
|
@ -4,7 +4,7 @@ use assert2::let_assert;
|
||||||
use git_next_config::{self as config, ForgeType, RepoConfigSource};
|
use git_next_config::{self as config, ForgeType, RepoConfigSource};
|
||||||
use kxio::network::{MockNetwork, StatusCode};
|
use kxio::network::{MockNetwork, StatusCode};
|
||||||
|
|
||||||
use git_next_git::{self as git, Generation};
|
use git_next_git as git;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ fn test_name() {
|
||||||
let (repo, _reality) = git::repository::mock();
|
let (repo, _reality) = git::repository::mock();
|
||||||
let repo_details = git::common::repo_details(
|
let repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
Generation::new(),
|
git::Generation::new(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
Some(config::common::repo_config(1, RepoConfigSource::Repo)),
|
Some(config::common::repo_config(1, RepoConfigSource::Repo)),
|
||||||
GitDir::new(fs.base()),
|
GitDir::new(fs.base()),
|
||||||
|
@ -45,7 +45,7 @@ async fn test_branches_get() {
|
||||||
|
|
||||||
let repo_details = git::common::repo_details(
|
let repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
Generation::new(),
|
git::Generation::new(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
Some(config::common::repo_config(1, RepoConfigSource::Repo)),
|
Some(config::common::repo_config(1, RepoConfigSource::Repo)),
|
||||||
GitDir::new(fs.base()),
|
GitDir::new(fs.base()),
|
||||||
|
|
|
@ -13,7 +13,7 @@ use actix::prelude::*;
|
||||||
use git::OpenRepository;
|
use git::OpenRepository;
|
||||||
use git_next_config::{server::Webhook, ForgeType, RepoConfig, RepoConfigSource};
|
use git_next_config::{server::Webhook, ForgeType, RepoConfig, RepoConfigSource};
|
||||||
use git_next_forge as forge;
|
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 kxio::network::Network;
|
||||||
use tracing::{debug, info, warn, Instrument};
|
use tracing::{debug, info, warn, Instrument};
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ use self::webhook::WebhookId;
|
||||||
#[derive(Debug, derive_more::Display)]
|
#[derive(Debug, derive_more::Display)]
|
||||||
#[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: git::Generation,
|
||||||
message_token: MessageToken,
|
message_token: MessageToken,
|
||||||
details: RepoDetails,
|
details: git::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
|
||||||
webhook_auth: Option<WebhookAuth>, // 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 {
|
impl RepoActor {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
details: RepoDetails,
|
details: git::RepoDetails,
|
||||||
webhook: Webhook,
|
webhook: Webhook,
|
||||||
generation: Generation,
|
generation: git::Generation,
|
||||||
net: Network,
|
net: Network,
|
||||||
repo: git::Repository,
|
repo: git::Repository,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use git_next_config::{
|
||||||
server::{Webhook, WebhookUrl},
|
server::{Webhook, WebhookUrl},
|
||||||
BranchName, RepoAlias, RepoBranches,
|
BranchName, RepoAlias, RepoBranches,
|
||||||
};
|
};
|
||||||
use git_next_git::{self as git, RepoDetails};
|
use git_next_git as git;
|
||||||
use kxio::network::{self, json};
|
use kxio::network::{self, json};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
use ulid::DecodeError;
|
use ulid::DecodeError;
|
||||||
|
@ -36,7 +36,11 @@ impl WebhookAuth {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(%webhook_id))]
|
#[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 hostname = &repo_details.forge.hostname();
|
||||||
let repo_path = repo_details.repo_path;
|
let repo_path = repo_details.repo_path;
|
||||||
use secrecy::ExposeSecret;
|
use secrecy::ExposeSecret;
|
||||||
|
@ -62,7 +66,7 @@ pub async fn unregister(webhook_id: WebhookId, repo_details: RepoDetails, net: n
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn register(
|
pub async fn register(
|
||||||
repo_details: RepoDetails,
|
repo_details: git::RepoDetails,
|
||||||
webhook: Webhook,
|
webhook: Webhook,
|
||||||
addr: actix::prelude::Addr<super::RepoActor>,
|
addr: actix::prelude::Addr<super::RepoActor>,
|
||||||
net: network::Network,
|
net: network::Network,
|
||||||
|
@ -121,7 +125,7 @@ pub async fn register(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_existing_webhooks(
|
async fn find_existing_webhooks(
|
||||||
repo_details: &RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
webhook_url: &WebhookUrl,
|
webhook_url: &WebhookUrl,
|
||||||
net: &network::Network,
|
net: &network::Network,
|
||||||
) -> Vec<WebhookId> {
|
) -> Vec<WebhookId> {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use git_next_config::{
|
||||||
self as config, ForgeType, GitDir, Hostname, RepoBranches, RepoConfig, RepoConfigSource,
|
self as config, ForgeType, GitDir, Hostname, RepoBranches, RepoConfig, RepoConfigSource,
|
||||||
RepoPath,
|
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>>;
|
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_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
Generation::new(),
|
git::Generation::new(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
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_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
Generation::new(),
|
git::Generation::new(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
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_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::common::repo_details(
|
||||||
1,
|
1,
|
||||||
Generation::new(),
|
git::Generation::new(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
config::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
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]
|
#[test]
|
||||||
fn git_remote_to_string_is_as_expected() {
|
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();
|
let as_string = git_remote.to_string();
|
||||||
|
|
||||||
assert_eq!(as_string, "foo:bar");
|
assert_eq!(as_string, "foo:bar");
|
||||||
|
|
Loading…
Reference in a new issue