zed/crates/git_hosting_providers/src/settings.rs
ᴀᴍᴛᴏᴀᴇʀ b948d8b9e7
git: Improve self-hosted provider support and Bitbucket integration (#42343)
This PR includes several minor modifications and improvements related to
Git hosting providers, covering the following areas:

1. Bitbucket Owner Parsing Fix: Remove the common `scm` prefix from the
remote URL of self-hosted Bitbucket instances to prevent incorrect owner
parsing.
[Reference](a6e3c6fbb2/src/git/remotes/bitbucket-server.ts (L72-L74))
2. Bitbucket Avatars in Blame: Add support for displaying Bitbucket
avatars in the Git blame view.
<img width="2750" height="1994" alt="CleanShot 2025-11-10 at 20 34
40@2x"
src="https://github.com/user-attachments/assets/9e26abdf-7880-4085-b636-a1f99ebeeb97"
/>
3. Self-hosted SourceHut Support: Add support for self-hosted SourceHut
instances.
4. Configuration: Add recently introduced self-hosted Git providers
(Gitea, Forgejo, and SourceHut) to the `git_hosting_providers` setting
option.
<img width="2750" height="1994" alt="CleanShot 2025-11-10 at 20 33
48@2x"
src="https://github.com/user-attachments/assets/44ffc799-182d-4145-9b89-e509bbc08843"
/>


Closes #11043

Release Notes:

- Improved self-hosted git provider support and Bitbucket integration
2025-12-08 13:32:14 -05:00

76 lines
2.5 KiB
Rust

use std::sync::Arc;
use git::GitHostingProviderRegistry;
use gpui::App;
use settings::{
GitHostingProviderConfig, GitHostingProviderKind, RegisterSetting, Settings, SettingsStore,
};
use url::Url;
use util::ResultExt as _;
use crate::{Bitbucket, Forgejo, Gitea, Github, Gitlab, SourceHut};
pub(crate) fn init(cx: &mut App) {
init_git_hosting_provider_settings(cx);
}
fn init_git_hosting_provider_settings(cx: &mut App) {
update_git_hosting_providers_from_settings(cx);
cx.observe_global::<SettingsStore>(update_git_hosting_providers_from_settings)
.detach();
}
fn update_git_hosting_providers_from_settings(cx: &mut App) {
let settings_store = cx.global::<SettingsStore>();
let settings = GitHostingProviderSettings::get_global(cx);
let provider_registry = GitHostingProviderRegistry::global(cx);
let local_values: Vec<GitHostingProviderConfig> = settings_store
.get_all_locals::<GitHostingProviderSettings>()
.into_iter()
.flat_map(|(_, _, providers)| providers.git_hosting_providers.clone())
.collect();
let iter = settings
.git_hosting_providers
.clone()
.into_iter()
.chain(local_values)
.filter_map(|provider| {
let url = Url::parse(&provider.base_url).log_err()?;
Some(match provider.provider {
GitHostingProviderKind::Bitbucket => {
Arc::new(Bitbucket::new(&provider.name, url)) as _
}
GitHostingProviderKind::Github => Arc::new(Github::new(&provider.name, url)) as _,
GitHostingProviderKind::Gitlab => Arc::new(Gitlab::new(&provider.name, url)) as _,
GitHostingProviderKind::Gitea => Arc::new(Gitea::new(&provider.name, url)) as _,
GitHostingProviderKind::Forgejo => Arc::new(Forgejo::new(&provider.name, url)) as _,
GitHostingProviderKind::SourceHut => {
Arc::new(SourceHut::new(&provider.name, url)) as _
}
})
});
provider_registry.set_setting_providers(iter);
}
#[derive(Debug, Clone, RegisterSetting)]
pub struct GitHostingProviderSettings {
pub git_hosting_providers: Vec<GitHostingProviderConfig>,
}
impl Settings for GitHostingProviderSettings {
fn from_settings(content: &settings::SettingsContent) -> Self {
Self {
git_hosting_providers: content
.project
.git_hosting_providers
.clone()
.unwrap()
.into(),
}
}
}