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
+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,