fix: avoid merging unrelated comments into replies

This commit is contained in:
2026-04-08 23:20:41 +08:00
parent 9036dccabd
commit a61be1b4c4
3 changed files with 117 additions and 42 deletions
+79
View File
@@ -55,6 +55,7 @@ fn normalize_groups_replies_and_sorts_threads_by_time() {
path: Some("src/main.rs".into()),
line: Some(10),
pull_request_review_id: Some(7),
in_reply_to: Some(1),
original_position: Some(10),
position: Some(10),
commit_id: Some("abc123".into()),
@@ -72,6 +73,7 @@ fn normalize_groups_replies_and_sorts_threads_by_time() {
path: Some("src/main.rs".into()),
line: Some(10),
pull_request_review_id: Some(7),
in_reply_to: None,
original_position: Some(10),
position: Some(10),
commit_id: Some("abc123".into()),
@@ -89,6 +91,7 @@ fn normalize_groups_replies_and_sorts_threads_by_time() {
path: Some("src/lib.rs".into()),
line: Some(22),
pull_request_review_id: Some(8),
in_reply_to: None,
original_position: Some(22),
position: Some(22),
commit_id: Some("def456".into()),
@@ -170,3 +173,79 @@ fn normalize_groups_replies_and_sorts_threads_by_time() {
assert_eq!(doc.threads[1].file_path.as_deref(), Some("src/main.rs"));
assert_eq!(doc.threads[1].line, Some(10));
}
#[test]
fn normalize_does_not_merge_unrelated_comments_on_same_file() {
let bundle = PullBundleDto {
pull: PullDto {
number: 100,
title: "T".into(),
state: "open".into(),
body: None,
user: UserDto {
login: "alice".into(),
},
base: PullBranchDto {
ref_name: "main".into(),
},
head: PullBranchDto {
ref_name: "feature/y".into(),
},
created_at: "2026-04-08T10:00:00Z".into(),
updated_at: "2026-04-08T10:00:00Z".into(),
merged_at: None,
additions: None,
deletions: None,
changed_files: None,
},
reviews: vec![],
comments: vec![
ReviewCommentDto {
id: 10,
body: "first line comment".into(),
created_at: "2026-04-08T12:01:00Z".into(),
updated_at: None,
user: UserDto {
login: "bob".into(),
},
path: Some("src/main.rs".into()),
line: Some(10),
pull_request_review_id: Some(1),
in_reply_to: None,
original_position: Some(10),
position: Some(10),
commit_id: Some("abc123".into()),
original_commit_id: Some("abc123".into()),
diff_hunk: None,
},
ReviewCommentDto {
id: 11,
body: "second line comment".into(),
created_at: "2026-04-08T12:02:00Z".into(),
updated_at: None,
user: UserDto {
login: "bob".into(),
},
path: Some("src/main.rs".into()),
line: Some(20),
pull_request_review_id: Some(1),
in_reply_to: None,
original_position: Some(20),
position: Some(20),
commit_id: Some("abc123".into()),
original_commit_id: Some("abc123".into()),
diff_hunk: None,
},
],
commits: vec![],
files: vec![],
};
let doc = normalize_bundle("org/repo", bundle);
assert_eq!(doc.threads.len(), 2);
assert_eq!(doc.threads[0].root_comment.id, 10);
assert_eq!(doc.threads[0].replies.len(), 0);
assert_eq!(doc.threads[1].root_comment.id, 11);
assert_eq!(doc.threads[1].replies.len(), 0);
}