Skip to main content

jj_ryu/platform/
factory.rs

1//! Platform service factory
2//!
3//! Creates platform services based on configuration.
4
5use crate::auth::{get_github_auth, get_gitlab_auth};
6use crate::error::Result;
7use crate::platform::{GitHubService, GitLabService, PlatformService};
8use crate::types::{Platform, PlatformConfig};
9
10/// Create a platform service from configuration
11///
12/// Handles authentication and client construction for both GitHub and GitLab.
13pub async fn create_platform_service(config: &PlatformConfig) -> Result<Box<dyn PlatformService>> {
14    match config.platform {
15        Platform::GitHub => {
16            let auth = get_github_auth().await?;
17            Ok(Box::new(GitHubService::new(
18                &auth.token,
19                config.owner.clone(),
20                config.repo.clone(),
21                config.host.clone(),
22            )?))
23        }
24        Platform::GitLab => {
25            let auth = get_gitlab_auth(config.host.as_deref()).await?;
26            Ok(Box::new(GitLabService::new(
27                auth.token.clone(),
28                config.owner.clone(),
29                config.repo.clone(),
30                Some(auth.host),
31            )?))
32        }
33    }
34}