fix: prefer valid position for comment line fallback
This commit is contained in:
+16
-1
@@ -197,12 +197,27 @@ fn to_commit_item(commit: CommitDto) -> CommitItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_comment_item(comment: ReviewCommentDto) -> CommentItem {
|
fn to_comment_item(comment: ReviewCommentDto) -> CommentItem {
|
||||||
|
let line = if let Some(value) = comment.line.filter(|value| *value > 0) {
|
||||||
|
Some(value)
|
||||||
|
} else if let Some(value) = comment
|
||||||
|
.position
|
||||||
|
.filter(|value| *value > 0)
|
||||||
|
.and_then(|value| i64::try_from(value).ok())
|
||||||
|
{
|
||||||
|
Some(value)
|
||||||
|
} else {
|
||||||
|
comment
|
||||||
|
.original_position
|
||||||
|
.filter(|value| *value > 0)
|
||||||
|
.and_then(|value| i64::try_from(value).ok())
|
||||||
|
};
|
||||||
|
|
||||||
CommentItem {
|
CommentItem {
|
||||||
id: comment.id,
|
id: comment.id,
|
||||||
user: comment.user.login,
|
user: comment.user.login,
|
||||||
created_at: comment.created_at,
|
created_at: comment.created_at,
|
||||||
path: comment.path,
|
path: comment.path,
|
||||||
line: comment.line,
|
line,
|
||||||
body: comment.body,
|
body: comment.body,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,3 +249,56 @@ fn normalize_does_not_merge_unrelated_comments_on_same_file() {
|
|||||||
assert_eq!(doc.threads[1].root_comment.id, 11);
|
assert_eq!(doc.threads[1].root_comment.id, 11);
|
||||||
assert_eq!(doc.threads[1].replies.len(), 0);
|
assert_eq!(doc.threads[1].replies.len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn normalize_uses_non_zero_position_when_line_is_missing() {
|
||||||
|
let bundle = PullBundleDto {
|
||||||
|
pull: PullDto {
|
||||||
|
number: 101,
|
||||||
|
title: "T".into(),
|
||||||
|
state: "open".into(),
|
||||||
|
body: None,
|
||||||
|
user: UserDto {
|
||||||
|
login: "alice".into(),
|
||||||
|
},
|
||||||
|
base: PullBranchDto {
|
||||||
|
ref_name: "main".into(),
|
||||||
|
},
|
||||||
|
head: PullBranchDto {
|
||||||
|
ref_name: "feature/z".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: 1001,
|
||||||
|
body: "position based comment".into(),
|
||||||
|
created_at: "2026-04-08T12:00:00Z".into(),
|
||||||
|
updated_at: None,
|
||||||
|
user: UserDto {
|
||||||
|
login: "bob".into(),
|
||||||
|
},
|
||||||
|
path: Some("src/main.rs".into()),
|
||||||
|
line: None,
|
||||||
|
pull_request_review_id: Some(1),
|
||||||
|
in_reply_to: None,
|
||||||
|
original_position: Some(42),
|
||||||
|
position: Some(41),
|
||||||
|
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(), 1);
|
||||||
|
assert_eq!(doc.threads[0].root_comment.path.as_deref(), Some("src/main.rs"));
|
||||||
|
assert_eq!(doc.threads[0].root_comment.line, Some(41));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user