git_same/provider/mod.rs
1//! Git hosting provider implementations.
2//!
3//! This module contains the [`Provider`] trait and implementations for
4//! various Git hosting services:
5//!
6//! - **GitHub** - github.com (active)
7//! - **GitHub Enterprise** - coming soon
8//! - **GitLab** - coming soon
9//! - **Codeberg** - coming soon
10//! - **Bitbucket** - coming soon
11//!
12//! # Example
13//!
14//! ```no_run
15//! use git_same::provider::{create_provider, DiscoveryOptions, NoProgress};
16//! use git_same::config::WorkspaceProvider;
17//!
18//! # async fn example() -> Result<(), git_same::errors::AppError> {
19//! let provider = WorkspaceProvider::default();
20//! let p = create_provider(&provider, "ghp_token123")?;
21//!
22//! let options = DiscoveryOptions::new();
23//! let progress = NoProgress;
24//! let repos = p.discover_repos(&options, &progress).await?;
25//! # Ok(())
26//! # }
27//! ```
28
29pub mod github;
30pub mod traits;
31
32#[cfg(test)]
33pub mod mock;
34
35pub use traits::{
36 Credentials, DiscoveryOptions, DiscoveryProgress, NoProgress, Provider, RateLimitInfo,
37};
38
39use crate::config::WorkspaceProvider;
40use crate::errors::{AppError, ProviderError};
41use crate::types::ProviderKind;
42
43/// Creates a provider instance based on workspace provider configuration.
44pub fn create_provider(
45 ws_provider: &WorkspaceProvider,
46 token: &str,
47) -> Result<Box<dyn Provider>, AppError> {
48 let api_url = ws_provider.effective_api_url();
49
50 match ws_provider.kind {
51 ProviderKind::GitHub => {
52 let credentials = Credentials::new(token, api_url);
53 let provider =
54 github::GitHubProvider::new(credentials, ws_provider.display_name().to_string())
55 .map_err(AppError::Provider)?;
56 Ok(Box::new(provider))
57 }
58 other => Err(AppError::Provider(ProviderError::NotImplemented(format!(
59 "{} support coming soon",
60 other.display_name()
61 )))),
62 }
63}
64
65#[cfg(test)]
66#[path = "mod_tests.rs"]
67mod tests;