Compare commits
2 Commits
bac9314f30
...
635f98bf8a
Author | SHA1 | Date | |
---|---|---|---|
|
635f98bf8a | ||
d969f799b0 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.2.0] - 2024-09-12
|
||||
|
||||
### Added
|
||||
- add config
|
||||
|
||||
### Docs
|
||||
- add readme
|
||||
|
||||
### Other
|
||||
- move config out
|
||||
- remove unused libraries
|
||||
|
||||
## [0.1.0] - 2024-09-12
|
||||
|
||||
### Added
|
||||
|
@ -3,7 +3,7 @@ members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
gitnow = { path = "crates/gitnow" }
|
||||
|
0
crates/gitnow/src/config.rs
Normal file
0
crates/gitnow/src/config.rs
Normal file
@ -33,150 +33,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
mod config {
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub providers: Providers,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Providers {
|
||||
#[serde(default)]
|
||||
pub github: Vec<GitHub>,
|
||||
#[serde(default)]
|
||||
pub gitea: Vec<Gitea>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GitHub {
|
||||
#[serde(default)]
|
||||
pub users: Vec<GitHubUser>,
|
||||
#[serde(default)]
|
||||
pub organisations: Vec<GitHubOrganisation>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GitHubUser(String);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GitHubOrganisation(String);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Gitea {
|
||||
#[serde(default)]
|
||||
pub users: Vec<GiteaUser>,
|
||||
#[serde(default)]
|
||||
pub organisations: Vec<GiteaOrganisation>,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GiteaUser(String);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct GiteaOrganisation(String);
|
||||
|
||||
impl Config {
|
||||
pub async fn from_file(file_path: &Path) -> anyhow::Result<Config> {
|
||||
let file_content = tokio::fs::read_to_string(file_path).await?;
|
||||
|
||||
Self::from_string(&file_content)
|
||||
}
|
||||
|
||||
pub fn from_string(content: &str) -> anyhow::Result<Config> {
|
||||
toml::from_str(content).context("failed to deserialize config file")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_can_parse_config() -> anyhow::Result<()> {
|
||||
let content = r#"
|
||||
[[providers.github]]
|
||||
users = ["kjuulh"]
|
||||
organisations = ["lunarway"]
|
||||
|
||||
[[providers.github]]
|
||||
users = ["other"]
|
||||
organisations = ["org"]
|
||||
|
||||
[[providers.gitea]]
|
||||
users = ["kjuulh"]
|
||||
organisations = ["lunarway"]
|
||||
|
||||
[[providers.gitea]]
|
||||
users = ["other"]
|
||||
organisations = ["org"]
|
||||
|
||||
[[providers.gitea]]
|
||||
"#;
|
||||
|
||||
let config = Config::from_string(content)?;
|
||||
|
||||
assert_eq!(
|
||||
Config {
|
||||
providers: Providers {
|
||||
github: vec![
|
||||
GitHub {
|
||||
users: vec![GitHubUser("kjuulh".into())],
|
||||
organisations: vec![GitHubOrganisation("lunarway".into())]
|
||||
},
|
||||
GitHub {
|
||||
users: vec![GitHubUser("other".into())],
|
||||
organisations: vec![GitHubOrganisation("org".into())]
|
||||
}
|
||||
],
|
||||
gitea: vec![
|
||||
Gitea {
|
||||
users: vec![GiteaUser("kjuulh".into())],
|
||||
organisations: vec![GiteaOrganisation("lunarway".into())]
|
||||
},
|
||||
Gitea {
|
||||
users: vec![GiteaUser("other".into())],
|
||||
organisations: vec![GiteaOrganisation("org".into())]
|
||||
},
|
||||
Gitea {
|
||||
users: vec![],
|
||||
organisations: vec![]
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
config
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_parse_empty_config() -> anyhow::Result<()> {
|
||||
let content = r#"
|
||||
# empty file
|
||||
"#;
|
||||
|
||||
let config = Config::from_string(content)?;
|
||||
|
||||
assert_eq!(
|
||||
Config {
|
||||
providers: Providers {
|
||||
github: vec![],
|
||||
gitea: vec![]
|
||||
}
|
||||
},
|
||||
config
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
mod config;
|
||||
|
||||
mod git_provider {
|
||||
use async_trait::async_trait;
|
||||
|
Loading…
Reference in New Issue
Block a user