git_hosting_providers.rs

 1mod providers;
 2
 3use std::sync::Arc;
 4
 5use git::repository::GitRepository;
 6use git::GitHostingProviderRegistry;
 7use gpui::App;
 8
 9pub use crate::providers::*;
10
11/// Initializes the Git hosting providers.
12pub fn init(cx: &App) {
13    let provider_registry = GitHostingProviderRegistry::global(cx);
14    provider_registry.register_hosting_provider(Arc::new(Bitbucket));
15    provider_registry.register_hosting_provider(Arc::new(Codeberg));
16    provider_registry.register_hosting_provider(Arc::new(Gitee));
17    provider_registry.register_hosting_provider(Arc::new(Github));
18    provider_registry.register_hosting_provider(Arc::new(Gitlab::new()));
19    provider_registry.register_hosting_provider(Arc::new(Sourcehut));
20}
21
22/// Registers additional Git hosting providers.
23///
24/// These require information from the Git repository to construct, so their
25/// registration is deferred until we have a Git repository initialized.
26pub fn register_additional_providers(
27    provider_registry: Arc<GitHostingProviderRegistry>,
28    repository: Arc<dyn GitRepository>,
29) {
30    let Some(origin_url) = repository.remote_url("origin") else {
31        return;
32    };
33
34    if let Ok(gitlab_self_hosted) = Gitlab::from_remote_url(&origin_url) {
35        provider_registry.register_hosting_provider(Arc::new(gitlab_self_hosted));
36    }
37}