Add pull requests to git blame tooltip (#10784)

Release Notes:

- Added links to GitHub pull requests to the git blame tooltips, if they
are available.

Screenshot:

(Yes, the icon will be resized! cc @iamnbutler)

![screenshot-2024-04-19-18 31
13@2x](https://github.com/zed-industries/zed/assets/1185253/774af0b3-f587-4acc-aa1e-1846c2bec127)
This commit is contained in:
Thorsten Ball
2024-04-19 18:54:20 +02:00
committed by GitHub
parent 70427daed2
commit f082344747
8 changed files with 145 additions and 20 deletions
+49 -20
View File
@@ -149,6 +149,11 @@ impl Render for BlameEntryTooltip {
})
.unwrap_or("<no commit message>".into_any());
let pull_request = self
.details
.as_ref()
.and_then(|details| details.pull_request.clone());
let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
let message_max_height = cx.line_height() * 12 + (ui_font_size / 0.4);
@@ -192,27 +197,51 @@ impl Render for BlameEntryTooltip {
.justify_between()
.child(absolute_timestamp)
.child(
Button::new("commit-sha-button", short_commit_id.clone())
.style(ButtonStyle::Transparent)
.color(Color::Muted)
.icon(IconName::FileGit)
.icon_color(Color::Muted)
.icon_position(IconPosition::Start)
.disabled(
self.details.as_ref().map_or(true, |details| {
details.permalink.is_none()
}),
)
.when_some(
self.details
.as_ref()
.and_then(|details| details.permalink.clone()),
|this, url| {
this.on_click(move |_, cx| {
h_flex()
.gap_2()
.when_some(pull_request, |this, pr| {
this.child(
Button::new(
"pull-request-button",
format!("#{}", pr.number),
)
.color(Color::Muted)
.icon(IconName::PullRequest)
.icon_color(Color::Muted)
.icon_position(IconPosition::Start)
.style(ButtonStyle::Transparent)
.on_click(move |_, cx| {
cx.stop_propagation();
cx.open_url(url.as_str())
})
},
cx.open_url(pr.url.as_str())
}),
)
})
.child(
Button::new(
"commit-sha-button",
short_commit_id.clone(),
)
.style(ButtonStyle::Transparent)
.color(Color::Muted)
.icon(IconName::FileGit)
.icon_color(Color::Muted)
.icon_position(IconPosition::Start)
.disabled(
self.details.as_ref().map_or(true, |details| {
details.permalink.is_none()
}),
)
.when_some(
self.details
.as_ref()
.and_then(|details| details.permalink.clone()),
|this, url| {
this.on_click(move |_, cx| {
cx.stop_propagation();
cx.open_url(url.as_str())
})
},
),
),
),
),
+7
View File
@@ -6,6 +6,7 @@ use git::{
blame::{Blame, BlameEntry},
hosting_provider::HostingProvider,
permalink::{build_commit_permalink, parse_git_remote_url},
pull_request::{extract_pull_request, PullRequest},
Oid,
};
use gpui::{Model, ModelContext, Subscription, Task};
@@ -75,6 +76,7 @@ pub struct CommitDetails {
pub message: String,
pub parsed_message: ParsedMarkdown,
pub permalink: Option<Url>,
pub pull_request: Option<PullRequest>,
pub remote: Option<GitRemote>,
}
@@ -438,6 +440,10 @@ async fn parse_commit_messages(
repo: remote.repo.to_string(),
});
let pull_request = parsed_remote_url
.as_ref()
.and_then(|remote| extract_pull_request(remote, &message));
commit_details.insert(
oid,
CommitDetails {
@@ -445,6 +451,7 @@ async fn parse_commit_messages(
parsed_message,
permalink,
remote,
pull_request,
},
);
}