fix: render per-comment file line instead of thread-level location
This commit is contained in:
@@ -69,5 +69,7 @@ pub struct CommentItem {
|
||||
pub id: i64,
|
||||
pub user: String,
|
||||
pub created_at: String,
|
||||
pub path: Option<String>,
|
||||
pub line: Option<i64>,
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
@@ -201,6 +201,8 @@ fn to_comment_item(comment: ReviewCommentDto) -> CommentItem {
|
||||
id: comment.id,
|
||||
user: comment.user.login,
|
||||
created_at: comment.created_at,
|
||||
path: comment.path,
|
||||
line: comment.line,
|
||||
body: comment.body,
|
||||
}
|
||||
}
|
||||
|
||||
+15
-6
@@ -22,16 +22,22 @@ fn render_body(body: &str) -> String {
|
||||
format!("{fence}md\n{body}\n{fence}\n")
|
||||
}
|
||||
|
||||
fn render_comment_location(path: Option<&str>, line: Option<i64>) -> Option<String> {
|
||||
path.map(|file_path| match line {
|
||||
Some(value) => format!("{file_path}:{value}"),
|
||||
None => file_path.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn render_thread(pr_index: i64, comment_seq: usize, thread: &CommentThread) -> String {
|
||||
let mut out = String::new();
|
||||
let comment_number = format!("{pr_index}.{comment_seq}");
|
||||
out.push_str(&format!("### Comment {comment_number}\n"));
|
||||
if let Some(file_path) = &thread.file_path {
|
||||
if let Some(line) = thread.line {
|
||||
out.push_str(&format!("{file_path}:{line}\n"));
|
||||
} else {
|
||||
out.push_str(&format!("{file_path}\n"));
|
||||
}
|
||||
let root_location =
|
||||
render_comment_location(thread.root_comment.path.as_deref(), thread.root_comment.line)
|
||||
.or_else(|| render_comment_location(thread.file_path.as_deref(), thread.line));
|
||||
if let Some(location) = root_location {
|
||||
out.push_str(&format!("{location}\n"));
|
||||
}
|
||||
out.push_str(&format!("{}:\n", thread.root_comment.user));
|
||||
out.push_str(&render_body(&thread.root_comment.body));
|
||||
@@ -39,6 +45,9 @@ fn render_thread(pr_index: i64, comment_seq: usize, thread: &CommentThread) -> S
|
||||
for (reply_index, reply) in thread.replies.iter().enumerate() {
|
||||
let reply_number = format!("{comment_number}.{}", reply_index + 1);
|
||||
out.push_str(&format!("\n### Reply {reply_number}\n"));
|
||||
if let Some(location) = render_comment_location(reply.path.as_deref(), reply.line) {
|
||||
out.push_str(&format!("{location}\n"));
|
||||
}
|
||||
out.push_str(&format!("{}:\n", reply.user));
|
||||
out.push_str(&render_body(&reply.body));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user