Add a registry for GitHostingProviders (#11470)

This PR adds a registry for `GitHostingProvider`s.

The intent here is to help decouple these provider-specific concerns
from the lower-level `git` crate.

Similar to languages, the Git hosting providers live in the new
`git_hosting_providers` crate.

This work also lays the foundation for if we wanted to allow defining a
`GitHostingProvider` from within an extension. This could be useful if
we wanted to extend the support to work with self-hosted Git providers
(like GitHub Enterprise).

I also took the opportunity to move some of the provider-specific code
out of the `util` crate, since it had leaked into there.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-05-06 21:24:48 -04:00 committed by GitHub
parent a64e20ed96
commit 88c4e0b2d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 405 additions and 229 deletions

View file

@ -1,4 +1,5 @@
use crate::blame::Blame;
use crate::GitHostingProviderRegistry;
use anyhow::{Context, Result};
use collections::HashMap;
use git2::{BranchType, StatusShow};
@ -71,13 +72,19 @@ impl std::fmt::Debug for dyn GitRepository {
pub struct RealGitRepository {
pub repository: LibGitRepository,
pub git_binary_path: PathBuf,
hosting_provider_registry: Arc<GitHostingProviderRegistry>,
}
impl RealGitRepository {
pub fn new(repository: LibGitRepository, git_binary_path: Option<PathBuf>) -> Self {
pub fn new(
repository: LibGitRepository,
git_binary_path: Option<PathBuf>,
hosting_provider_registry: Arc<GitHostingProviderRegistry>,
) -> Self {
Self {
repository,
git_binary_path: git_binary_path.unwrap_or_else(|| PathBuf::from("git")),
hosting_provider_registry,
}
}
}
@ -246,6 +253,7 @@ impl GitRepository for RealGitRepository {
path,
&content,
remote_url,
self.hosting_provider_registry.clone(),
)
}
}