Allow configuring custom git hosting providers in project settings (#31929)

Closes #29229

Release Notes:

- Extended the support for configuring custom git hosting providers to
cover project settings in addition to global settings.

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
This commit is contained in:
Cole Miller 2025-06-03 12:23:01 -04:00 committed by GitHub
parent 203754d0db
commit 1307b81721
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 138 additions and 20 deletions

View file

@ -2,7 +2,6 @@ use std::{ops::Range, sync::Arc};
use anyhow::Result;
use async_trait::async_trait;
use collections::BTreeMap;
use derive_more::{Deref, DerefMut};
use gpui::{App, Global, SharedString};
use http_client::HttpClient;
@ -130,7 +129,8 @@ impl Global for GlobalGitHostingProviderRegistry {}
#[derive(Default)]
struct GitHostingProviderRegistryState {
providers: BTreeMap<String, Arc<dyn GitHostingProvider + Send + Sync + 'static>>,
default_providers: Vec<Arc<dyn GitHostingProvider + Send + Sync + 'static>>,
setting_providers: Vec<Arc<dyn GitHostingProvider + Send + Sync + 'static>>,
}
#[derive(Default)]
@ -140,6 +140,7 @@ pub struct GitHostingProviderRegistry {
impl GitHostingProviderRegistry {
/// Returns the global [`GitHostingProviderRegistry`].
#[track_caller]
pub fn global(cx: &App) -> Arc<Self> {
cx.global::<GlobalGitHostingProviderRegistry>().0.clone()
}
@ -168,7 +169,8 @@ impl GitHostingProviderRegistry {
pub fn new() -> Self {
Self {
state: RwLock::new(GitHostingProviderRegistryState {
providers: BTreeMap::default(),
setting_providers: Vec::default(),
default_providers: Vec::default(),
}),
}
}
@ -177,7 +179,22 @@ impl GitHostingProviderRegistry {
pub fn list_hosting_providers(
&self,
) -> Vec<Arc<dyn GitHostingProvider + Send + Sync + 'static>> {
self.state.read().providers.values().cloned().collect()
let state = self.state.read();
state
.default_providers
.iter()
.cloned()
.chain(state.setting_providers.iter().cloned())
.collect()
}
pub fn set_setting_providers(
&self,
providers: impl IntoIterator<Item = Arc<dyn GitHostingProvider + Send + Sync + 'static>>,
) {
let mut state = self.state.write();
state.setting_providers.clear();
state.setting_providers.extend(providers);
}
/// Adds the provided [`GitHostingProvider`] to the registry.
@ -185,10 +202,7 @@ impl GitHostingProviderRegistry {
&self,
provider: Arc<dyn GitHostingProvider + Send + Sync + 'static>,
) {
self.state
.write()
.providers
.insert(provider.name(), provider);
self.state.write().default_providers.push(provider);
}
}