Cargo.toml: add feature flags for the various source adapters

This commit is contained in:
2026-04-27 06:30:51 +09:00
parent cdc4b7d03e
commit 84c9f7b931
5 changed files with 87 additions and 23 deletions
+18 -5
View File
@@ -20,12 +20,13 @@ autolib = false
anyhow = "1.0.102"
clap = { version = "4.6.1", features = ["derive"] }
clap_complete = "4.6.2"
forgejo-api = { version = "0.10.0", default-features = false, features = ["rustls-tls"] }
gitea-sdk = "0.6.1"
gitlab = "0.1811.0"
gix = "0.82.0"
octocrab = "0.49.8"
forgejo-api = { version = "0.10.0", default-features = false, features = ["rustls-tls"], optional = true }
gitea-sdk = { version = "0.6.1", optional = true }
gitlab = { version = "0.1811.0", default-features = false, features = ["client_api", "rustls", "ring"], optional = true }
# gix = "0.82.0"
octocrab = { version = "0.49.8", optional = true }
regex = "1.12.3"
rustls = { version = "0.23.39", features = ["ring", "logging", "tls12"], default-features = false }
sd-notify = "0.5.0"
serde = "1.0.228"
serde_json = "1.0.149"
@@ -33,6 +34,18 @@ tokio = { version = "1.52.1", features = ["macros", "rt-multi-thread"] }
tracing = "0.1.44"
tracing-journald = "0.3.2"
[features]
default = [
"github",
# "gitlab",
"gitea",
"forgejo",
]
github = ["dep:octocrab"]
gitlab = ["dep:gitlab"]
gitea = ["dep:gitea-sdk"]
forgejo = ["dep:forgejo-api"]
[[bin]]
name = "kagami"
path = "src/main.rs"
+45 -8
View File
@@ -2,7 +2,7 @@ use std::collections::HashSet;
use crate::{
config::{Config, RepositoryFilterConfig, SourceConfig, SourceHostConfig, SourceHostType},
sources::{KagamiSource, KagamiSourceGitea, KagamiSourceGithub, RepositoryInfo},
sources::{self, KagamiSource, RepositoryInfo},
};
// TODO: implement json output option
@@ -127,18 +127,29 @@ async fn fetch_for_user(
repo_filters: &RepositoryFilterConfig,
) -> anyhow::Result<HashSet<RepositoryInfo>> {
match host_cfg._type {
#[cfg(feature = "github")]
SourceHostType::Github => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = KagamiSourceGithub::new(host);
let provider = sources::KagamiSourceGithub::new(host);
provider
.get_repositories_by_user(owner, token.as_deref(), repo_filters)
.await
}
#[cfg(feature = "gitea")]
SourceHostType::Gitea => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = KagamiSourceGitea::new(host);
let provider = sources::KagamiSourceGitea::new(host);
provider
.get_repositories_by_user(owner, token.as_deref(), repo_filters)
.await
}
#[cfg(feature = "gitlab")]
SourceHostType::Gitlab => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = sources::KagamiSourceGitlab::new(host);
provider
.get_repositories_by_user(owner, token.as_deref(), repo_filters)
.await
@@ -159,18 +170,29 @@ async fn fetch_for_org(
repo_filters: &RepositoryFilterConfig,
) -> anyhow::Result<HashSet<RepositoryInfo>> {
match host_cfg._type {
#[cfg(feature = "github")]
SourceHostType::Github => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = KagamiSourceGithub::new(host);
let provider = sources::KagamiSourceGithub::new(host);
provider
.get_repositories_by_organization(owner, token.as_deref(), recurse, repo_filters)
.await
}
#[cfg(feature = "gitea")]
SourceHostType::Gitea => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = KagamiSourceGitea::new(host);
let provider = sources::KagamiSourceGitea::new(host);
provider
.get_repositories_by_organization(owner, token.as_deref(), recurse, repo_filters)
.await
}
#[cfg(feature = "gitlab")]
SourceHostType::Gitlab => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = sources::KagamiSourceGitlab::new(host);
provider
.get_repositories_by_organization(owner, token.as_deref(), recurse, repo_filters)
.await
@@ -188,20 +210,31 @@ async fn fetch_for_stars(
host_key: &str,
owner: &str,
repo_filters: &RepositoryFilterConfig,
) -> anyhow::Result<HashSet<RepositoryInfo>> {
) -> anyhow::Result<HashSet<sources::RepositoryInfo>> {
match host_cfg._type {
#[cfg(feature = "github")]
SourceHostType::Github => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = KagamiSourceGithub::new(host);
let provider = sources::KagamiSourceGithub::new(host);
provider
.get_repositories_by_stars(owner, token.as_deref(), repo_filters)
.await
}
#[cfg(feature = "gitea")]
SourceHostType::Gitea => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = KagamiSourceGitea::new(host);
let provider = sources::KagamiSourceGitea::new(host);
provider
.get_repositories_by_stars(owner, token.as_deref(), repo_filters)
.await
}
#[cfg(feature = "gitlab")]
SourceHostType::Gitlab => {
let host = host_cfg.host.as_deref();
let token = host_cfg.get_token()?;
let provider = sources::KagamiSourceGitlab::new(host);
provider
.get_repositories_by_stars(owner, token.as_deref(), repo_filters)
.await
@@ -220,24 +253,28 @@ fn resolve_host_cfg(config: &Config, key: &str) -> anyhow::Result<SourceHostConf
}
match key.to_lowercase().as_str() {
#[cfg(feature = "github")]
"github" => Ok(SourceHostConfig {
_type: SourceHostType::Github,
host: None,
token_file: None,
token: None,
}),
#[cfg(feature = "gitlab")]
"gitlab" => Ok(SourceHostConfig {
_type: SourceHostType::Gitlab,
host: None,
token_file: None,
token: None,
}),
#[cfg(feature = "gitea")]
"gitea" => Ok(SourceHostConfig {
_type: SourceHostType::Gitea,
host: None,
token_file: None,
token: None,
}),
#[cfg(feature = "forgejo")]
"codeberg" | "forgejo" => Ok(SourceHostConfig {
_type: SourceHostType::Forgejo,
host: None,
+19 -8
View File
@@ -1,14 +1,25 @@
pub mod forgejo;
pub mod git;
pub mod gitea;
pub mod github;
pub mod gitlab;
// pub use forgejo::KagamiSourceForgejo;
mod git;
pub use git::KagamiSourceGit;
#[cfg(feature = "forgejo")]
mod forgejo;
#[cfg(feature = "forgejo")]
pub use forgejo::KagamiSourceForgejo;
#[cfg(feature = "gitea")]
mod gitea;
#[cfg(feature = "gitea")]
pub use gitea::KagamiSourceGitea;
#[cfg(feature = "github")]
mod github;
#[cfg(feature = "github")]
pub use github::KagamiSourceGithub;
// pub use gitlab::KagamiSourceGitLab;
#[cfg(feature = "gitlab")]
mod gitlab;
#[cfg(feature = "gitlab")]
pub use gitlab::KagamiSourceGitlab;
use std::collections::HashSet;
+1 -1
View File
@@ -1,5 +1,5 @@
pub struct KagamiSourceForgejo {
host: String,
host: String,
}
impl KagamiSourceForgejo {
+4 -1
View File
@@ -1,6 +1,9 @@
use std::collections::HashSet;
use crate::{config::RepositoryFilterConfig, sources::{KagamiSource, RepositoryInfo}};
use crate::{
config::RepositoryFilterConfig,
sources::{KagamiSource, RepositoryInfo},
};
pub struct KagamiSourceGit {
host: String,