Compare commits
1 commit
b1e5bf3788
...
a4008cbdcc
Author | SHA1 | Date | |
---|---|---|---|
a4008cbdcc |
10 changed files with 120 additions and 61 deletions
|
@ -1,2 +1,13 @@
|
|||
// The name of a Branch
|
||||
crate::newtype!(BranchName is a String, derive_more::Display, Default);
|
||||
use derive_more::Display;
|
||||
|
||||
/// The name of a Branch
|
||||
#[derive(Clone, Default, Debug, Hash, PartialEq, Eq, Display, PartialOrd, Ord)]
|
||||
pub struct BranchName(String);
|
||||
impl BranchName {
|
||||
pub fn new(str: impl Into<String>) -> Self {
|
||||
Self(str.into())
|
||||
}
|
||||
pub fn into_string(self) -> String {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// The name of a Forge to connect to
|
||||
crate::newtype!(ForgeAlias is a String, derive_more::Display, Default);
|
||||
impl From<&ForgeAlias> for std::path::PathBuf {
|
||||
fn from(value: &ForgeAlias) -> Self {
|
||||
Self::from(&value.0)
|
||||
}
|
||||
}
|
12
crates/config/src/forge_name.rs
Normal file
12
crates/config/src/forge_name.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use derive_more::{AsRef, Constructor, Display};
|
||||
|
||||
/// The name of a Forge to connect to
|
||||
#[derive(Clone, Default, Debug, Hash, PartialEq, Eq, Constructor, Display, AsRef)]
|
||||
pub struct ForgeAlias(String);
|
||||
impl From<&ForgeAlias> for PathBuf {
|
||||
fn from(value: &ForgeAlias) -> Self {
|
||||
Self::from(&value.0)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,22 @@
|
|||
//
|
||||
use std::path::PathBuf;
|
||||
|
||||
crate::newtype!(GitDir is a PathBuf, Default);
|
||||
#[derive(
|
||||
Clone,
|
||||
Default,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Deserialize,
|
||||
derive_more::Deref,
|
||||
derive_more::From,
|
||||
)]
|
||||
pub struct GitDir(PathBuf);
|
||||
impl GitDir {
|
||||
pub fn new(path: &std::path::Path) -> Self {
|
||||
Self(path.to_path_buf())
|
||||
}
|
||||
|
||||
pub const fn pathbuf(&self) -> &PathBuf {
|
||||
&self.0
|
||||
}
|
||||
|
@ -22,3 +36,8 @@ impl From<&GitDir> for PathBuf {
|
|||
value.to_path_buf()
|
||||
}
|
||||
}
|
||||
impl From<GitDir> for PathBuf {
|
||||
fn from(value: GitDir) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
// The hostname of a forge
|
||||
crate::newtype!(Hostname is a String, derive_more::Display, Default);
|
||||
/// The hostname of a forge
|
||||
#[derive(Clone, Default, Debug, PartialEq, Eq, derive_more::Display)]
|
||||
pub struct Hostname(String);
|
||||
impl Hostname {
|
||||
pub fn new(str: impl Into<String>) -> Self {
|
||||
Self(str.into())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
//
|
||||
|
||||
mod api_token;
|
||||
mod branch_name;
|
||||
pub mod common;
|
||||
mod forge_alias;
|
||||
mod forge_config;
|
||||
mod forge_details;
|
||||
mod forge_name;
|
||||
mod forge_type;
|
||||
pub mod git_dir;
|
||||
mod host_name;
|
||||
|
@ -26,9 +25,9 @@ mod tests;
|
|||
|
||||
pub use api_token::ApiToken;
|
||||
pub use branch_name::BranchName;
|
||||
pub use forge_alias::ForgeAlias;
|
||||
pub use forge_config::ForgeConfig;
|
||||
pub use forge_details::ForgeDetails;
|
||||
pub use forge_name::ForgeAlias;
|
||||
pub use forge_type::ForgeType;
|
||||
pub use git_dir::GitDir;
|
||||
pub use host_name::Hostname;
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
//
|
||||
use super::*;
|
||||
|
||||
use assert2::let_assert;
|
||||
use secrecy::ExposeSecret;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::server::Http;
|
||||
use crate::server::ServerConfig;
|
||||
use crate::server::ServerStorage;
|
||||
use crate::server::Webhook;
|
||||
use crate::webhook::push::Branch;
|
||||
|
||||
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
|
||||
type TestResult = Result<()>;
|
||||
|
||||
mod server_repo_config {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use assert2::let_assert;
|
||||
|
||||
use crate::{
|
||||
tests::given, BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource, RepoPath,
|
||||
};
|
||||
|
||||
use super::super::server_repo_config::*;
|
||||
|
||||
#[test]
|
||||
fn should_not_return_repo_config_when_no_branches() {
|
||||
|
@ -90,11 +86,14 @@ mod server_repo_config {
|
|||
|
||||
assert_eq!(
|
||||
src.gitdir(),
|
||||
Some(GitDir::new(PathBuf::default().join(gitdir)))
|
||||
Some(GitDir::new(&PathBuf::default().join(gitdir)))
|
||||
);
|
||||
}
|
||||
}
|
||||
mod repo_config {
|
||||
use crate::{RepoBranches, RepoConfigSource};
|
||||
|
||||
use super::super::repo_config::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
@ -145,7 +144,13 @@ mod repo_config {
|
|||
}
|
||||
}
|
||||
mod forge_config {
|
||||
use super::*;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use secrecy::ExposeSecret;
|
||||
|
||||
use crate::{
|
||||
tests::given, ForgeConfig, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn should_return_repos() {
|
||||
|
@ -241,9 +246,14 @@ mod forge_config {
|
|||
}
|
||||
}
|
||||
mod forge_details {
|
||||
use super::*;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use secrecy::ExposeSecret;
|
||||
|
||||
use crate::{
|
||||
tests::given, ApiToken, ForgeAlias, ForgeConfig, ForgeDetails, ForgeType, Hostname, User,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn should_return_forge_alias() {
|
||||
let forge_type = ForgeType::MockForge;
|
||||
|
@ -354,9 +364,10 @@ mod forge_details {
|
|||
}
|
||||
}
|
||||
mod forge_name {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::{tests::given, ForgeAlias};
|
||||
|
||||
#[test]
|
||||
fn should_convert_to_pathbuf() {
|
||||
let name = given::a_name();
|
||||
|
@ -368,7 +379,7 @@ mod forge_name {
|
|||
}
|
||||
}
|
||||
mod forge_type {
|
||||
use super::*;
|
||||
use crate::ForgeType;
|
||||
|
||||
#[test]
|
||||
fn should_display_as_string() {
|
||||
|
@ -376,22 +387,23 @@ mod forge_type {
|
|||
}
|
||||
}
|
||||
mod gitdir {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::{tests::given, GitDir};
|
||||
|
||||
#[test]
|
||||
fn should_return_pathbuf() {
|
||||
let pathbuf = PathBuf::default().join(given::a_name());
|
||||
let gitdir = GitDir::new(&pathbuf);
|
||||
|
||||
let result = gitdir.unwrap();
|
||||
let result = gitdir.pathbuf();
|
||||
|
||||
assert_eq!(result, pathbuf);
|
||||
assert_eq!(result, &pathbuf);
|
||||
}
|
||||
#[test]
|
||||
fn should_display() {
|
||||
let pathbuf = PathBuf::default().join("foo");
|
||||
let gitdir = GitDir::new(pathbuf);
|
||||
let gitdir = GitDir::new(&pathbuf);
|
||||
|
||||
let result = gitdir.to_string();
|
||||
|
||||
|
@ -403,7 +415,7 @@ mod gitdir {
|
|||
let pathbuf = PathBuf::default().join(path.clone());
|
||||
let gitdir: GitDir = path.as_str().into();
|
||||
|
||||
assert_eq!(gitdir, GitDir::new(pathbuf));
|
||||
assert_eq!(gitdir, GitDir::new(&pathbuf));
|
||||
}
|
||||
#[test]
|
||||
fn should_convert_to_pathbuf_from_ref() {
|
||||
|
@ -427,7 +439,7 @@ mod gitdir {
|
|||
}
|
||||
}
|
||||
mod repo_branches {
|
||||
use super::*;
|
||||
use crate::{tests::given, BranchName, RepoBranches};
|
||||
|
||||
#[test]
|
||||
fn should_return_main() {
|
||||
|
@ -458,10 +470,15 @@ mod repo_branches {
|
|||
}
|
||||
}
|
||||
mod server {
|
||||
use super::*;
|
||||
mod load {
|
||||
|
||||
use super::*;
|
||||
use assert2::let_assert;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::{
|
||||
server::ServerConfig,
|
||||
tests::{given, TestResult},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn load_should_parse_server_config() -> TestResult {
|
||||
|
@ -503,8 +520,6 @@ mod server {
|
|||
let branch = server_repo_config.branch();
|
||||
let gitdir = server_repo_config
|
||||
.gitdir()
|
||||
.map(|gitdir| gitdir.unwrap())
|
||||
.map(|pathbuf| pathbuf.display().to_string())
|
||||
.map(|gitdir| format!(r#", gitdir = "{gitdir}" "#))
|
||||
.unwrap_or_default();
|
||||
let repo_server_config = server_repo_config
|
||||
|
@ -552,7 +567,8 @@ token = "{forge_token}"
|
|||
}
|
||||
}
|
||||
mod registered_webhook {
|
||||
use super::*;
|
||||
|
||||
use crate::{tests::given, RegisteredWebhook, WebhookAuth};
|
||||
|
||||
#[test]
|
||||
fn should_return_id() {
|
||||
|
@ -572,11 +588,11 @@ mod registered_webhook {
|
|||
}
|
||||
}
|
||||
mod webhook {
|
||||
use super::*;
|
||||
mod message {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{tests::given, WebhookMessage};
|
||||
|
||||
#[test]
|
||||
fn should_return_forge_alias() {
|
||||
let forge_alias = given::a_forge_alias();
|
||||
|
@ -627,8 +643,7 @@ mod webhook {
|
|||
}
|
||||
}
|
||||
mod push {
|
||||
|
||||
use super::*;
|
||||
use crate::{tests::given, webhook::push::Branch, BranchName};
|
||||
|
||||
#[test]
|
||||
fn should_return_main_branch() {
|
||||
|
@ -700,14 +715,18 @@ mod push {
|
|||
}
|
||||
}
|
||||
mod given {
|
||||
|
||||
use super::*;
|
||||
use rand::Rng as _;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use rand::Rng as _;
|
||||
|
||||
use crate::{
|
||||
server::{Http, ServerConfig, ServerStorage, Webhook},
|
||||
ForgeAlias, ForgeConfig, ForgeType, RepoAlias, RepoBranches, ServerRepoConfig, WebhookId,
|
||||
};
|
||||
|
||||
pub fn a_name() -> String {
|
||||
use rand::Rng;
|
||||
use std::iter;
|
||||
|
|
|
@ -733,7 +733,7 @@ mod forgejo {
|
|||
pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> config::GitDir {
|
||||
let dir_name = a_name();
|
||||
let dir = fs.base().join(dir_name);
|
||||
config::GitDir::new(dir)
|
||||
config::GitDir::new(&dir)
|
||||
}
|
||||
|
||||
pub fn a_forge_config() -> config::ForgeConfig {
|
||||
|
@ -747,9 +747,9 @@ mod forgejo {
|
|||
}
|
||||
|
||||
pub fn a_server_repo_config() -> config::ServerRepoConfig {
|
||||
let main = a_branch_name().unwrap();
|
||||
let next = a_branch_name().unwrap();
|
||||
let dev = a_branch_name().unwrap();
|
||||
let main = a_branch_name().into_string();
|
||||
let next = a_branch_name().into_string();
|
||||
let dev = a_branch_name().into_string();
|
||||
config::ServerRepoConfig::new(
|
||||
format!("{}/{}", a_name(), a_name()),
|
||||
main.clone(),
|
||||
|
|
|
@ -92,7 +92,7 @@ mod server_repo_config {
|
|||
|
||||
assert_eq!(
|
||||
src.gitdir(),
|
||||
Some(config::GitDir::new(PathBuf::default().join(gitdir)))
|
||||
Some(config::GitDir::new(&PathBuf::default().join(gitdir)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ pub mod given {
|
|||
pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> GitDir {
|
||||
let dir_name = a_name();
|
||||
let dir = fs.base().join(dir_name);
|
||||
GitDir::new(dir)
|
||||
GitDir::new(&dir)
|
||||
}
|
||||
|
||||
pub fn a_forge_config() -> ForgeConfig {
|
||||
|
@ -280,9 +280,9 @@ pub mod given {
|
|||
}
|
||||
|
||||
pub fn a_server_repo_config() -> ServerRepoConfig {
|
||||
let main = a_branch_name().unwrap();
|
||||
let next = a_branch_name().unwrap();
|
||||
let dev = a_branch_name().unwrap();
|
||||
let main = a_branch_name().into_string();
|
||||
let next = a_branch_name().into_string();
|
||||
let dev = a_branch_name().into_string();
|
||||
ServerRepoConfig::new(
|
||||
format!("{}/{}", a_name(), a_name()),
|
||||
main.clone(),
|
||||
|
|
Loading…
Reference in a new issue