Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 9b40871

Browse files
committed
Open outdated file if we can't find a line for comment
In case the line matching algorithms catch us out, fall back to viewing comment on file revision when comment was made.
1 parent ea273a9 commit 9b40871

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewCommentViewModel.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,23 @@ async Task DoOpen()
5252
{
5353
if (thread == null)
5454
{
55-
var sha = model.Thread.IsOutdated ? model.Thread.OriginalCommitSha : model.Thread.CommitSha;
56-
var file = await session.GetFile(RelativePath, sha);
57-
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
55+
if(model.Thread.IsOutdated)
56+
{
57+
var file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha);
58+
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
59+
}
60+
else
61+
{
62+
var file = await session.GetFile(RelativePath, model.Thread.CommitSha);
63+
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
64+
65+
// Fall back to opening outdated file if we can't find a line number for the comment
66+
if(thread?.LineNumber == -1)
67+
{
68+
file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha);
69+
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
70+
}
71+
}
5872
}
5973

6074
if (thread != null && thread.LineNumber != -1)

0 commit comments

Comments
 (0)