fix: use pr-index based comment numbering in markdown
This commit is contained in:
@@ -71,14 +71,14 @@ total: <files_changed> files, +<additions>, -<deletions>
|
||||
## Review 1 (<review-state>)
|
||||
> <reviewer>
|
||||
|
||||
### Comment 1.1
|
||||
### Comment <pr-index>.<comment-seq>
|
||||
<file>:<line>
|
||||
<user>:
|
||||
```md
|
||||
<原始评论正文>
|
||||
```
|
||||
|
||||
### Reply 1.1.1
|
||||
### Reply <pr-index>.<comment-seq>.<reply-seq>
|
||||
<user>:
|
||||
```md
|
||||
<原始回复正文>
|
||||
|
||||
@@ -22,9 +22,10 @@ fn render_body(body: &str) -> String {
|
||||
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();
|
||||
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(line) = thread.line {
|
||||
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));
|
||||
|
||||
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.user));
|
||||
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() {
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ fn render_markdown_includes_expected_sections_and_preserves_comment_markdown() {
|
||||
assert!(md.contains("## Commits"));
|
||||
assert!(md.contains("## Diff Stat"));
|
||||
assert!(md.contains("## Review 1 (COMMENT)"));
|
||||
assert!(md.contains("### Comment 1.1"));
|
||||
assert!(md.contains("### Reply 1.1"));
|
||||
assert!(md.contains("### Comment 7.1"));
|
||||
assert!(md.contains("### Reply 7.1.1"));
|
||||
assert!(md.contains("````md"));
|
||||
assert!(md.contains("```rs\nlet x = 1;\n```"));
|
||||
assert!(md.contains("looks good"));
|
||||
|
||||
Reference in New Issue
Block a user