Compare commits
2 commits
a4008cbdcc
...
b1e5bf3788
Author | SHA1 | Date | |
---|---|---|---|
b1e5bf3788 | |||
5e9f9eb80f |
10 changed files with 61 additions and 120 deletions
|
@ -1,13 +1,2 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
// The name of a Branch
|
||||
crate::newtype!(BranchName is a String, derive_more::Display, Default);
|
||||
|
|
7
crates/config/src/forge_alias.rs
Normal file
7
crates/config/src/forge_alias.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
// 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)
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
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,22 +1,8 @@
|
|||
//
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Default,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Deserialize,
|
||||
derive_more::Deref,
|
||||
derive_more::From,
|
||||
)]
|
||||
pub struct GitDir(PathBuf);
|
||||
crate::newtype!(GitDir is a PathBuf, Default);
|
||||
impl GitDir {
|
||||
pub fn new(path: &std::path::Path) -> Self {
|
||||
Self(path.to_path_buf())
|
||||
}
|
||||
|
||||
pub const fn pathbuf(&self) -> &PathBuf {
|
||||
&self.0
|
||||
}
|
||||
|
@ -36,8 +22,3 @@ impl From<&GitDir> for PathBuf {
|
|||
value.to_path_buf()
|
||||
}
|
||||
}
|
||||
impl From<GitDir> for PathBuf {
|
||||
fn from(value: GitDir) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,2 @@
|
|||
/// 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())
|
||||
}
|
||||
}
|
||||
// The hostname of a forge
|
||||
crate::newtype!(Hostname is a String, derive_more::Display, Default);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
//
|
||||
|
||||
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;
|
||||
|
@ -25,9 +26,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,18 +1,22 @@
|
|||
//
|
||||
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 std::path::PathBuf;
|
||||
|
||||
use assert2::let_assert;
|
||||
|
||||
use crate::{
|
||||
tests::given, BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource, RepoPath,
|
||||
};
|
||||
|
||||
use super::super::server_repo_config::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_not_return_repo_config_when_no_branches() {
|
||||
|
@ -86,14 +90,11 @@ 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]
|
||||
|
@ -144,13 +145,7 @@ mod repo_config {
|
|||
}
|
||||
}
|
||||
mod forge_config {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use secrecy::ExposeSecret;
|
||||
|
||||
use crate::{
|
||||
tests::given, ForgeConfig, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User,
|
||||
};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_return_repos() {
|
||||
|
@ -246,14 +241,9 @@ mod forge_config {
|
|||
}
|
||||
}
|
||||
mod forge_details {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::*;
|
||||
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;
|
||||
|
@ -364,10 +354,9 @@ 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();
|
||||
|
@ -379,7 +368,7 @@ mod forge_name {
|
|||
}
|
||||
}
|
||||
mod forge_type {
|
||||
use crate::ForgeType;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_display_as_string() {
|
||||
|
@ -387,23 +376,22 @@ 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.pathbuf();
|
||||
let result = gitdir.unwrap();
|
||||
|
||||
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();
|
||||
|
||||
|
@ -415,7 +403,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() {
|
||||
|
@ -439,7 +427,7 @@ mod gitdir {
|
|||
}
|
||||
}
|
||||
mod repo_branches {
|
||||
use crate::{tests::given, BranchName, RepoBranches};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_return_main() {
|
||||
|
@ -470,15 +458,10 @@ mod repo_branches {
|
|||
}
|
||||
}
|
||||
mod server {
|
||||
use super::*;
|
||||
mod load {
|
||||
|
||||
use assert2::let_assert;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::{
|
||||
server::ServerConfig,
|
||||
tests::{given, TestResult},
|
||||
};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn load_should_parse_server_config() -> TestResult {
|
||||
|
@ -520,6 +503,8 @@ 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
|
||||
|
@ -567,8 +552,7 @@ token = "{forge_token}"
|
|||
}
|
||||
}
|
||||
mod registered_webhook {
|
||||
|
||||
use crate::{tests::given, RegisteredWebhook, WebhookAuth};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_return_id() {
|
||||
|
@ -588,11 +572,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();
|
||||
|
@ -643,7 +627,8 @@ mod webhook {
|
|||
}
|
||||
}
|
||||
mod push {
|
||||
use crate::{tests::given, webhook::push::Branch, BranchName};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_return_main_branch() {
|
||||
|
@ -715,18 +700,14 @@ 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().into_string();
|
||||
let next = a_branch_name().into_string();
|
||||
let dev = a_branch_name().into_string();
|
||||
let main = a_branch_name().unwrap();
|
||||
let next = a_branch_name().unwrap();
|
||||
let dev = a_branch_name().unwrap();
|
||||
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().into_string();
|
||||
let next = a_branch_name().into_string();
|
||||
let dev = a_branch_name().into_string();
|
||||
let main = a_branch_name().unwrap();
|
||||
let next = a_branch_name().unwrap();
|
||||
let dev = a_branch_name().unwrap();
|
||||
ServerRepoConfig::new(
|
||||
format!("{}/{}", a_name(), a_name()),
|
||||
main.clone(),
|
||||
|
|
Loading…
Reference in a new issue