Add avatar support for codeberg in git blame (#10991)
Release Notes: - Added support for avatars in git blame for repositories hosted on codeberg <img width="1144" alt="Screenshot 2024-04-25 at 16 45 22" src="https://github.com/zed-industries/zed/assets/43210583/d44770d8-44ea-4c6b-a1c0-ac2d1d49408f"> Questions: - Should we move git stuff like `Commit`, `Author`, etc outside of hosting-specific files (I don't think so, as other hostings can have different stuff) - Should we also add support for self hosted forgejo instances or should it be a different PR?
This commit is contained in:
parent
8152e0676f
commit
f96cab286c
5 changed files with 107 additions and 28 deletions
|
@ -3,7 +3,7 @@ use std::{ops::Range, sync::Arc};
|
|||
|
||||
use anyhow::Result;
|
||||
use url::Url;
|
||||
use util::{github, http::HttpClient};
|
||||
use util::{codeberg, github, http::HttpClient};
|
||||
|
||||
use crate::Oid;
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl HostingProvider {
|
|||
|
||||
pub fn supports_avatars(&self) -> bool {
|
||||
match self {
|
||||
HostingProvider::Github => true,
|
||||
HostingProvider::Github | HostingProvider::Codeberg => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -71,24 +71,27 @@ impl HostingProvider {
|
|||
commit: Oid,
|
||||
client: Arc<dyn HttpClient>,
|
||||
) -> Result<Option<Url>> {
|
||||
match self {
|
||||
Ok(match self {
|
||||
HostingProvider::Github => {
|
||||
let commit = commit.to_string();
|
||||
|
||||
let author =
|
||||
github::fetch_github_commit_author(repo_owner, repo, &commit, &client).await?;
|
||||
|
||||
let url = if let Some(author) = author {
|
||||
let mut url = Url::parse(&author.avatar_url)?;
|
||||
url.set_query(Some("size=128"));
|
||||
Some(url)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(url)
|
||||
github::fetch_github_commit_author(repo_owner, repo, &commit, &client)
|
||||
.await?
|
||||
.map(|author| -> Result<Url, url::ParseError> {
|
||||
let mut url = Url::parse(&author.avatar_url)?;
|
||||
url.set_query(Some("size=128"));
|
||||
Ok(url)
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
HostingProvider::Codeberg => {
|
||||
let commit = commit.to_string();
|
||||
codeberg::fetch_codeberg_commit_author(repo_owner, repo, &commit, &client)
|
||||
.await?
|
||||
.map(|author| Url::parse(&author.avatar_url))
|
||||
.transpose()
|
||||
}
|
||||
_ => Ok(None),
|
||||
}
|
||||
}?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue