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