fix: use pr-index based comment numbering in markdown

This commit is contained in:
2026-04-08 23:17:57 +08:00
parent d9eab0bebd
commit 9036dccabd
3 changed files with 9 additions and 8 deletions
+2 -2
View File
@@ -71,14 +71,14 @@ total: <files_changed> files, +<additions>, -<deletions>
## Review 1 (<review-state>) ## Review 1 (<review-state>)
> <reviewer> > <reviewer>
### Comment 1.1 ### Comment <pr-index>.<comment-seq>
<file>:<line> <file>:<line>
<user>: <user>:
```md ```md
<原始评论正文> <原始评论正文>
``` ```
### Reply 1.1.1 ### Reply <pr-index>.<comment-seq>.<reply-seq>
<user>: <user>:
```md ```md
<原始回复正文> <原始回复正文>
+5 -4
View File
@@ -22,9 +22,10 @@ fn render_body(body: &str) -> String {
format!("{fence}md\n{body}\n{fence}\n") format!("{fence}md\n{body}\n{fence}\n")
} }
fn render_thread(thread_index: usize, thread: &CommentThread) -> String { fn render_thread(pr_index: i64, comment_seq: usize, thread: &CommentThread) -> String {
let mut out = String::new(); let mut out = String::new();
out.push_str(&format!("### Comment {}.1\n", thread_index)); 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(file_path) = &thread.file_path {
if let Some(line) = thread.line { if let Some(line) = thread.line {
out.push_str(&format!("{file_path}:{line}\n")); out.push_str(&format!("{file_path}:{line}\n"));
@@ -36,7 +37,7 @@ fn render_thread(thread_index: usize, thread: &CommentThread) -> String {
out.push_str(&render_body(&thread.root_comment.body)); out.push_str(&render_body(&thread.root_comment.body));
for (reply_index, reply) in thread.replies.iter().enumerate() { for (reply_index, reply) in thread.replies.iter().enumerate() {
let reply_number = format!("{thread_index}.1.{}", reply_index + 1); let reply_number = format!("{comment_number}.{}", reply_index + 1);
out.push_str(&format!("\n### Reply {reply_number}\n")); out.push_str(&format!("\n### Reply {reply_number}\n"));
out.push_str(&format!("{}:\n", reply.user)); out.push_str(&format!("{}:\n", reply.user));
out.push_str(&render_body(&reply.body)); out.push_str(&render_body(&reply.body));
@@ -101,7 +102,7 @@ pub fn render_markdown(doc: &PrReviewDocument) -> String {
} }
for (thread_index, thread) in doc.threads.iter().enumerate() { for (thread_index, thread) in doc.threads.iter().enumerate() {
out.push_str(&render_thread(thread_index + 1, thread)); out.push_str(&render_thread(doc.meta.pr_index, thread_index + 1, thread));
out.push('\n'); out.push('\n');
} }
+2 -2
View File
@@ -68,8 +68,8 @@ fn render_markdown_includes_expected_sections_and_preserves_comment_markdown() {
assert!(md.contains("## Commits")); assert!(md.contains("## Commits"));
assert!(md.contains("## Diff Stat")); assert!(md.contains("## Diff Stat"));
assert!(md.contains("## Review 1 (COMMENT)")); assert!(md.contains("## Review 1 (COMMENT)"));
assert!(md.contains("### Comment 1.1")); assert!(md.contains("### Comment 7.1"));
assert!(md.contains("### Reply 1.1")); assert!(md.contains("### Reply 7.1.1"));
assert!(md.contains("````md")); assert!(md.contains("````md"));
assert!(md.contains("```rs\nlet x = 1;\n```")); assert!(md.contains("```rs\nlet x = 1;\n```"));
assert!(md.contains("looks good")); assert!(md.contains("looks good"));