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:
@@ -1,4 +1,4 @@
|
||||
use crate::http::HttpClient;
|
||||
use crate::{git_author::GitAuthor, http::HttpClient};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use futures::AsyncReadExt;
|
||||
use isahc::{config::Configurable, AsyncBody, Request};
|
||||
@@ -49,19 +49,12 @@ struct User {
|
||||
pub avatar_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GitHubAuthor {
|
||||
pub id: u64,
|
||||
pub email: String,
|
||||
pub avatar_url: String,
|
||||
}
|
||||
|
||||
pub async fn fetch_github_commit_author(
|
||||
repo_owner: &str,
|
||||
repo: &str,
|
||||
commit: &str,
|
||||
client: &Arc<dyn HttpClient>,
|
||||
) -> Result<Option<GitHubAuthor>> {
|
||||
) -> Result<Option<GitAuthor>> {
|
||||
let url = format!("https://api.github.com/repos/{repo_owner}/{repo}/commits/{commit}");
|
||||
|
||||
let mut request = Request::get(&url)
|
||||
@@ -93,10 +86,8 @@ pub async fn fetch_github_commit_author(
|
||||
serde_json::from_str::<CommitDetails>(body_str)
|
||||
.map(|github_commit| {
|
||||
if let Some(author) = github_commit.author {
|
||||
Some(GitHubAuthor {
|
||||
id: author.id,
|
||||
Some(GitAuthor {
|
||||
avatar_url: author.avatar_url,
|
||||
email: github_commit.commit.author.email,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user