chore(deps): update kxio to v1.1.0
This commit is contained in:
parent
ff6e61b0ee
commit
e357da4346
7 changed files with 49 additions and 36 deletions
|
@ -27,10 +27,7 @@ gix = "0.62"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
|
||||||
# fs/network
|
# fs/network
|
||||||
kxio = { version = "1.0", features = [
|
kxio = { version = "1.1" }
|
||||||
"fs",
|
|
||||||
"network",
|
|
||||||
] } # { git = "https://git.kemitix.net/kemitix/kxio.git", branch = "main" }
|
|
||||||
|
|
||||||
# fs
|
# fs
|
||||||
tempfile = "3.10"
|
tempfile = "3.10"
|
||||||
|
@ -52,6 +49,7 @@ ulid = "1.1"
|
||||||
warp = "0.3"
|
warp = "0.3"
|
||||||
|
|
||||||
# error handling
|
# error handling
|
||||||
|
derive_more = { version = "1.0.0-beta.6", features = ["from", "display"] }
|
||||||
terrors = "0.3"
|
terrors = "0.3"
|
||||||
|
|
||||||
# Actors
|
# Actors
|
||||||
|
|
12
src/init.rs
12
src/init.rs
|
@ -1,17 +1,21 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::filesystem::FileSystem;
|
use kxio::fs::FileSystem;
|
||||||
|
|
||||||
pub fn run(fs: FileSystem) {
|
pub fn run(fs: FileSystem) {
|
||||||
let file_name = ".git-next.toml";
|
let file_name = ".git-next.toml";
|
||||||
let path = PathBuf::from(file_name);
|
let pathbuf = PathBuf::from(file_name);
|
||||||
if fs.file_exists(&path) {
|
let Ok(exists) = fs.path_exists(&pathbuf) else {
|
||||||
|
eprintln!("Could not check if file exist: {}", file_name);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if exists {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"The configuration file already exists at {} - not overwritting it.",
|
"The configuration file already exists at {} - not overwritting it.",
|
||||||
file_name
|
file_name
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
match fs.write_file(file_name, include_str!("../default.toml")) {
|
match fs.file_write(&pathbuf, include_str!("../default.toml")) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("Created a default configuration file at {}", file_name);
|
println!("Created a default configuration file at {}", file_name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
mod init;
|
mod init;
|
||||||
mod server;
|
mod server;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use kxio::{filesystem, network::Network};
|
use kxio::{fs, network::Network};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
|
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
|
||||||
|
@ -24,7 +26,7 @@ enum Server {
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let fs = filesystem::FileSystem::new_real(None);
|
let fs = fs::new(PathBuf::default());
|
||||||
let net = Network::new_real();
|
let net = Network::new_real();
|
||||||
let commands = Commands::parse();
|
let commands = Commands::parse();
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,15 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use terrors::OneOf;
|
|
||||||
|
|
||||||
use crate::filesystem::FileSystem;
|
use kxio::fs::FileSystem;
|
||||||
|
|
||||||
|
#[derive(Debug, derive_more::From, derive_more::Display)]
|
||||||
|
pub enum Error {
|
||||||
|
Io(std::io::Error),
|
||||||
|
KxIoFs(kxio::fs::Error),
|
||||||
|
TomlDe(toml::de::Error),
|
||||||
|
}
|
||||||
|
|
||||||
/// Mapped from the `git-next-server.toml` file
|
/// Mapped from the `git-next-server.toml` file
|
||||||
#[derive(Debug, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Deserialize)]
|
||||||
|
@ -20,9 +26,9 @@ pub struct ServerConfig {
|
||||||
forge: HashMap<String, ForgeConfig>,
|
forge: HashMap<String, ForgeConfig>,
|
||||||
}
|
}
|
||||||
impl ServerConfig {
|
impl ServerConfig {
|
||||||
pub(crate) fn load(fs: &FileSystem) -> Result<Self, OneOf<(std::io::Error, toml::de::Error)>> {
|
pub(crate) fn load(fs: &FileSystem) -> Result<Self, Error> {
|
||||||
let str = fs.read_file("git-next-server.toml").map_err(OneOf::new)?;
|
let str = fs.file_read_to_string(&fs.base().join("git-next-server.toml"))?;
|
||||||
toml::from_str(&str).map_err(OneOf::new)
|
toml::from_str(&str).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn forges(&self) -> impl Iterator<Item = (ForgeName, &ForgeConfig)> {
|
pub(crate) fn forges(&self) -> impl Iterator<Item = (ForgeName, &ForgeConfig)> {
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
use assert2::let_assert;
|
use assert2::let_assert;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use crate::{
|
use crate::{server::gitforge::tests::common /* server::gitforge::tests::common */};
|
||||||
filesystem::FileSystem,
|
|
||||||
server::gitforge::tests::common, /* server::gitforge::tests::common */
|
use kxio::fs;
|
||||||
};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn load_should_parse_server_config() -> Result<(), OneOf<(std::io::Error, toml::de::Error)>> {
|
fn load_should_parse_server_config() -> Result<(), crate::server::config::Error> {
|
||||||
let fs = FileSystem::new_temp().map_err(OneOf::new)?;
|
let fs = fs::temp()?;
|
||||||
fs.write_file(
|
fs.file_write(
|
||||||
"git-next-server.toml",
|
&fs.base().join("git-next-server.toml"),
|
||||||
r#"
|
r#"
|
||||||
[webhook]
|
[webhook]
|
||||||
url = "http://localhost:9909/webhook"
|
url = "http://localhost:9909/webhook"
|
||||||
|
@ -38,8 +37,8 @@ fn load_should_parse_server_config() -> Result<(), OneOf<(std::io::Error, toml::
|
||||||
dev = "sam-dev"
|
dev = "sam-dev"
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.map_err(OneOf::new)?;
|
?;
|
||||||
let config = ServerConfig::load(&fs)?;
|
let_assert!(Ok(config) = ServerConfig::load(&fs));
|
||||||
let expected = ServerConfig {
|
let expected = ServerConfig {
|
||||||
webhook: Webhook {
|
webhook: Webhook {
|
||||||
url: "http://localhost:9909/webhook".to_string(),
|
url: "http://localhost:9909/webhook".to_string(),
|
||||||
|
@ -112,7 +111,7 @@ fn load_should_parse_server_config() -> Result<(), OneOf<(std::io::Error, toml::
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_repo_config_load() -> Result<(), OneOf<(toml::de::Error,)>> {
|
fn test_repo_config_load() -> Result<(), crate::server::config::Error> {
|
||||||
let toml = r#"
|
let toml = r#"
|
||||||
[branches]
|
[branches]
|
||||||
main = "main"
|
main = "main"
|
||||||
|
@ -191,8 +190,8 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<(), RepoValidationEr
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn gitdir_validate_should_fail_a_non_git_dir() {
|
fn gitdir_validate_should_fail_a_non_git_dir() {
|
||||||
let_assert!(Ok(fs) = kxio::filesystem::FileSystem::new_temp());
|
let_assert!(Ok(fs) = kxio::fs::temp());
|
||||||
let cwd = fs.cwd();
|
let cwd = fs.base();
|
||||||
let repo_details = common::repo_details(
|
let repo_details = common::repo_details(
|
||||||
1,
|
1,
|
||||||
common::forge_details(1, ForgeType::MockForge),
|
common::forge_details(1, ForgeType::MockForge),
|
||||||
|
|
|
@ -8,7 +8,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_name() {
|
fn test_name() {
|
||||||
let Ok(fs) = kxio::filesystem::FileSystem::new_temp() else {
|
let Ok(fs) = kxio::fs::temp() else {
|
||||||
panic!("fs")
|
panic!("fs")
|
||||||
};
|
};
|
||||||
let net = Network::new_mock();
|
let net = Network::new_mock();
|
||||||
|
@ -16,7 +16,7 @@ fn test_name() {
|
||||||
1,
|
1,
|
||||||
common::forge_details(1, ForgeType::MockForge),
|
common::forge_details(1, ForgeType::MockForge),
|
||||||
Some(common::repo_config(1)),
|
Some(common::repo_config(1)),
|
||||||
GitDir::new(fs.cwd()),
|
GitDir::new(fs.base()),
|
||||||
);
|
);
|
||||||
let forge = Forge::new_forgejo(repo_details, net);
|
let forge = Forge::new_forgejo(repo_details, net);
|
||||||
assert_eq!(forge.name(), "forgejo");
|
assert_eq!(forge.name(), "forgejo");
|
||||||
|
@ -24,7 +24,7 @@ fn test_name() {
|
||||||
|
|
||||||
#[test_log::test(tokio::test)]
|
#[test_log::test(tokio::test)]
|
||||||
async fn test_branches_get() {
|
async fn test_branches_get() {
|
||||||
let Ok(fs) = kxio::filesystem::FileSystem::new_temp() else {
|
let Ok(fs) = kxio::fs::temp() else {
|
||||||
panic!("fs")
|
panic!("fs")
|
||||||
};
|
};
|
||||||
let mut net = MockNetwork::new();
|
let mut net = MockNetwork::new();
|
||||||
|
@ -42,7 +42,7 @@ async fn test_branches_get() {
|
||||||
1,
|
1,
|
||||||
common::forge_details(1, ForgeType::MockForge),
|
common::forge_details(1, ForgeType::MockForge),
|
||||||
Some(common::repo_config(1)),
|
Some(common::repo_config(1)),
|
||||||
GitDir::new(fs.cwd()),
|
GitDir::new(fs.base()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let forge = Forge::new_forgejo(repo_details, net.clone());
|
let forge = Forge::new_forgejo(repo_details, net.clone());
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::path::PathBuf;
|
||||||
use tracing::{error, info, level_filters::LevelFilter};
|
use tracing::{error, info, level_filters::LevelFilter};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
filesystem::FileSystem,
|
fs::FileSystem,
|
||||||
server::{
|
server::{
|
||||||
actors::webhook,
|
actors::webhook,
|
||||||
config::{ForgeConfig, ForgeName, RepoAlias, ServerStorage, Webhook},
|
config::{ForgeConfig, ForgeName, RepoAlias, ServerStorage, Webhook},
|
||||||
|
@ -23,14 +23,18 @@ use self::{actors::repo::RepoActor, config::ServerRepoConfig};
|
||||||
|
|
||||||
pub fn init(fs: FileSystem) {
|
pub fn init(fs: FileSystem) {
|
||||||
let file_name = "git-next-server.toml";
|
let file_name = "git-next-server.toml";
|
||||||
let path = PathBuf::from(file_name);
|
let pathbuf = PathBuf::from(file_name);
|
||||||
if fs.file_exists(&path) {
|
let Ok(exists) = fs.path_exists(&pathbuf) else {
|
||||||
|
eprintln!("Could not check if file exist: {}", file_name);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if exists {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"The configuration file already exists at {} - not overwritting it.",
|
"The configuration file already exists at {} - not overwritting it.",
|
||||||
file_name
|
file_name
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
match fs.write_file(file_name, include_str!("../../server-default.toml")) {
|
match fs.file_write(&pathbuf, include_str!("../../server-default.toml")) {
|
||||||
Ok(_) => println!("Created a default configuration file at {}", file_name),
|
Ok(_) => println!("Created a default configuration file at {}", file_name),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to write to the configuration file: {}", e)
|
eprintln!("Failed to write to the configuration file: {}", e)
|
||||||
|
|
Loading…
Reference in a new issue