bin: Basic hunk comment rendering in patch review

This commit is contained in:
Erik Kundt
2024-11-20 16:45:23 +01:00
parent 70f89884b5
commit cf44bb8e9d
3 changed files with 49 additions and 9 deletions
+10 -1
View File
@@ -343,7 +343,7 @@ mod interface {
return Ok(());
};
let (review_id, review) = if let Some((id, review)) = patch
let (review_id, _) = if let Some((id, review)) = patch
.clone()
.reviews_of(revision.id())
.find(|(_, review)| review.author().public_key() == signer.public_key())
@@ -376,6 +376,15 @@ mod interface {
};
loop {
// Reload review
let (review_id, review) = match patch
.reviews_of(revision.id())
.find(|(_, review)| review.author().public_key() == signer.public_key())
{
Some((id, review)) => (id.clone(), review.clone()),
None => anyhow::bail!("Could not find review {}", review_id),
};
log::info!(
"Found comments for {review_id}: {:?}",
review.comments().collect::<Vec<_>>()
+2 -2
View File
@@ -161,14 +161,14 @@ impl<'a> App<'a> {
pub fn new(
profile: Profile,
rid: RepoId,
_review: Review,
review: Review,
queue: ReviewQueue,
) -> Result<Self, anyhow::Error> {
let repository = profile.storage.repository(rid)?;
let queue = queue
.iter()
.map(|item| HunkItem::from((&repository, item)))
.map(|item| HunkItem::from((&repository, &review, item)))
.collect::<Vec<_>>();
let mut items = HashMap::new();
+37 -6
View File
@@ -10,14 +10,14 @@ use nom::{IResult, Parser};
use ansi_to_tui::IntoText;
use radicle::cob::thread::{Comment, CommentId};
use radicle::cob::{Label, ObjectId, Timestamp, TypedId};
use radicle::cob::{CodeLocation, EntryId, Label, ObjectId, Timestamp, TypedId};
use radicle::git::Oid;
use radicle::identity::{Did, Identity};
use radicle::issue;
use radicle::issue::{CloseReason, Issue, IssueId, Issues};
use radicle::node::notifications::{Notification, NotificationId, NotificationKind};
use radicle::node::{Alias, AliasStore, NodeId};
use radicle::patch;
use radicle::patch::{self, Review};
use radicle::patch::{Patch, PatchId, Patches};
use radicle::storage::git::Repository;
use radicle::storage::{ReadRepository, ReadStorage, RefUpdate, WriteRepository};
@@ -1043,18 +1043,35 @@ impl<'a> Into<Line<'a>> for TermLine {
pub struct HunkItem<'a> {
pub inner: IndexedHunkItem,
pub highlighted: Blobs<Vec<Line<'a>>>,
pub comments: Vec<(EntryId, Comment<CodeLocation>)>,
}
impl<'a> From<(&Repository, &IndexedHunkItem)> for HunkItem<'a> {
fn from(value: (&Repository, &IndexedHunkItem)) -> Self {
let (repo, item) = value;
impl<'a> From<(&Repository, &Review, &IndexedHunkItem)> for HunkItem<'a> {
fn from(value: (&Repository, &Review, &IndexedHunkItem)) -> Self {
let (repo, review, item) = value;
let hi = Highlighter::default();
let path = match &item.1 {
crate::cob::HunkItem::FileAdded { path, .. } => path,
crate::cob::HunkItem::FileModified { path, .. } => path,
crate::cob::HunkItem::FileDeleted { path, .. } => path,
crate::cob::HunkItem::FileCopied { copied } => &copied.new_path,
crate::cob::HunkItem::FileMoved { moved } => &moved.new_path,
crate::cob::HunkItem::FileModeChanged { path, .. } => path,
crate::cob::HunkItem::FileEofChanged { path, .. } => path,
};
let blobs = item.1.clone().blobs(repo.raw());
let highlighted = blobs.highlight(hi);
Self {
inner: item.clone(),
highlighted,
comments: review
.comments()
.filter(|(_, comment)| comment.location().is_some())
.filter(|(_, comment)| comment.location().unwrap().path == *path)
.map(|(id, comment)| (id.clone(), comment.clone()))
.collect::<Vec<_>>(),
}
}
}
@@ -1444,7 +1461,7 @@ impl<'a> HunkItem<'a> {
}
pub fn hunk_text(&'a self) -> Option<Text<'a>> {
match &self.inner {
let mut hunk = match &self.inner {
(
_,
crate::cob::HunkItem::FileAdded {
@@ -1480,7 +1497,21 @@ impl<'a> HunkItem<'a> {
.as_ref()
.map(|hunk| Text::from(hunk.to_text(&self.highlighted))),
_ => None,
};
let comments = self
.comments
.iter()
.fold(Text::raw(""), |mut comments, comment| {
comments.extend(Text::from(comment.1.body()));
comments
});
if let Some(ref mut hunk) = hunk {
hunk.extend(comments);
}
hunk
}
}