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

Commit 4b2c16c

Browse files
authored
Merge pull request #2249 from github/fixes/2247-viewing-outdated-comments
Fix viewing outdated comments in pull request reviews
2 parents 0054884 + 359275f commit 4b2c16c

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.Reactive;
44
using System.Threading.Tasks;
55
using GitHub.Extensions;
6+
using GitHub.Logging;
67
using GitHub.Models;
78
using GitHub.Services;
89
using ReactiveUI;
10+
using Serilog;
911

1012
namespace GitHub.ViewModels.GitHubPane
1113
{
@@ -14,6 +16,8 @@ namespace GitHub.ViewModels.GitHubPane
1416
/// </summary>
1517
public class PullRequestReviewCommentViewModel : IPullRequestReviewFileCommentViewModel
1618
{
19+
static readonly ILogger log = LogManager.ForContext<PullRequestReviewCommentViewModel>();
20+
1721
readonly IPullRequestEditorService editorService;
1822
readonly IPullRequestSession session;
1923
readonly PullRequestReviewCommentModel model;
@@ -52,18 +56,34 @@ async Task DoOpen()
5256
{
5357
if (thread == null)
5458
{
55-
var file = await session.GetFile(RelativePath, model.Thread.CommitSha);
56-
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
59+
if(model.Thread.IsOutdated)
60+
{
61+
var file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha);
62+
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
63+
}
64+
else
65+
{
66+
var file = await session.GetFile(RelativePath, model.Thread.CommitSha);
67+
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
68+
69+
if(thread?.LineNumber == -1)
70+
{
71+
log.Warning("Couldn't find line number for comment on {RelativePath} @ {CommitSha}", RelativePath, model.Thread.CommitSha);
72+
// Fall back to opening outdated file if we can't find a line number for the comment
73+
file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha);
74+
thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id));
75+
}
76+
}
5777
}
5878

5979
if (thread != null && thread.LineNumber != -1)
6080
{
6181
await editorService.OpenDiff(session, RelativePath, thread);
6282
}
6383
}
64-
catch (Exception)
84+
catch (Exception e)
6585
{
66-
// TODO: Show error.
86+
log.Error(e, nameof(DoOpen));
6787
}
6888
}
6989
}

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public IReadOnlyList<IInlineCommentThreadModel> BuildCommentThreads(
116116
relativePath = relativePath.Replace("\\", "/");
117117

118118
var threadsByPosition = pullRequest.Threads
119-
.Where(x => x.Path == relativePath && !x.IsOutdated)
119+
.Where(x => x.Path == relativePath)
120120
.OrderBy(x => x.Id)
121121
.GroupBy(x => Tuple.Create(x.OriginalCommitSha, x.OriginalPosition));
122122
var threads = new List<IInlineCommentThreadModel>();

submodules/octokit.graphql.net

Submodule octokit.graphql.net updated 154 files

0 commit comments

Comments
 (0)