From 84c9f7b931441c6d22c3c01ba7e44337a15096df Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 27 Apr 2026 06:30:51 +0900 Subject: [PATCH] Cargo.toml: add feature flags for the various source adapters --- Cargo.toml | 23 ++++++++++++++---- src/commands/list.rs | 53 +++++++++++++++++++++++++++++++++++------- src/sources.rs | 27 ++++++++++++++------- src/sources/forgejo.rs | 2 +- src/sources/git.rs | 5 +++- 5 files changed, 87 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 13e950f..3e0fe09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/commands/list.rs b/src/commands/list.rs index 485a48e..d00f640 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -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> { 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> { 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> { +) -> anyhow::Result> { 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 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, diff --git a/src/sources.rs b/src/sources.rs index 1b9f82b..c3947d4 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -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; diff --git a/src/sources/forgejo.rs b/src/sources/forgejo.rs index efc28ca..227a695 100644 --- a/src/sources/forgejo.rs +++ b/src/sources/forgejo.rs @@ -1,5 +1,5 @@ pub struct KagamiSourceForgejo { - host: String, + host: String, } impl KagamiSourceForgejo { diff --git a/src/sources/git.rs b/src/sources/git.rs index c9fc804..71a56a5 100644 --- a/src/sources/git.rs +++ b/src/sources/git.rs @@ -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,