fix: align comment numbering with review sequence

This commit is contained in:
2026-04-08 23:44:43 +08:00
parent eb7dd1125d
commit 56f436592d
7 changed files with 44 additions and 10 deletions
+1
View File
@@ -67,6 +67,7 @@ pub struct CommentThread {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommentItem {
pub id: i64,
pub review_id: Option<i64>,
pub user: String,
pub created_at: String,
pub path: Option<String>,
+1
View File
@@ -214,6 +214,7 @@ fn to_comment_item(comment: ReviewCommentDto) -> CommentItem {
CommentItem {
id: comment.id,
review_id: comment.pull_request_review_id,
user: comment.user.login,
created_at: comment.created_at,
path: comment.path,
+28 -4
View File
@@ -29,9 +29,8 @@ fn render_comment_location(path: Option<&str>, line: Option<i64>) -> Option<Stri
})
}
fn render_thread(pr_index: i64, comment_seq: usize, thread: &CommentThread) -> String {
fn render_thread(comment_number: &str, thread: &CommentThread) -> String {
let mut out = String::new();
let comment_number = format!("{pr_index}.{comment_seq}");
out.push_str(&format!("### Comment {comment_number}\n"));
let root_location =
render_comment_location(thread.root_comment.path.as_deref(), thread.root_comment.line)
@@ -57,6 +56,7 @@ fn render_thread(pr_index: i64, comment_seq: usize, thread: &CommentThread) -> S
pub fn render_markdown(doc: &PrReviewDocument) -> String {
let mut out = String::new();
let mut rendered = vec![false; doc.threads.len()];
out.push_str(&format!(
"# {} `#{}` {}\n\n",
@@ -108,11 +108,35 @@ pub fn render_markdown(doc: &PrReviewDocument) -> String {
if let Some(submitted_at) = &review.submitted_at {
out.push_str(&format!("- submitted at: {}\n\n", submitted_at));
}
let mut review_comment_seq = 1usize;
for (thread_index, thread) in doc.threads.iter().enumerate() {
if thread.root_comment.review_id == Some(review.id) {
let comment_number =
format!("{}.{}.{}", doc.meta.pr_index, review_index + 1, review_comment_seq);
out.push_str(&render_thread(&comment_number, thread));
out.push('\n');
rendered[thread_index] = true;
review_comment_seq += 1;
}
}
out.push('\n');
}
let mut has_unassigned = false;
let mut unassigned_seq = 1usize;
for (thread_index, thread) in doc.threads.iter().enumerate() {
out.push_str(&render_thread(doc.meta.pr_index, thread_index + 1, thread));
out.push('\n');
if !rendered[thread_index] {
if !has_unassigned {
out.push_str("## Comments (No Review)\n\n");
has_unassigned = true;
}
let comment_number = format!("{}.0.{}", doc.meta.pr_index, unassigned_seq);
out.push_str(&render_thread(&comment_number, thread));
out.push('\n');
unassigned_seq += 1;
}
}
out.trim_end().to_string()