diff --git a/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewCommentViewModel.cs b/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewCommentViewModel.cs index 9a9a473161..7c960baaa5 100644 --- a/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewCommentViewModel.cs +++ b/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewCommentViewModel.cs @@ -3,9 +3,11 @@ using System.Reactive; using System.Threading.Tasks; using GitHub.Extensions; +using GitHub.Logging; using GitHub.Models; using GitHub.Services; using ReactiveUI; +using Serilog; namespace GitHub.ViewModels.GitHubPane { @@ -14,6 +16,8 @@ namespace GitHub.ViewModels.GitHubPane /// public class PullRequestReviewCommentViewModel : IPullRequestReviewFileCommentViewModel { + static readonly ILogger log = LogManager.ForContext(); + readonly IPullRequestEditorService editorService; readonly IPullRequestSession session; readonly PullRequestReviewCommentModel model; @@ -52,8 +56,24 @@ async Task DoOpen() { if (thread == null) { - var file = await session.GetFile(RelativePath, model.Thread.CommitSha); - thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); + if(model.Thread.IsOutdated) + { + var file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha); + thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); + } + else + { + var file = await session.GetFile(RelativePath, model.Thread.CommitSha); + thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); + + if(thread?.LineNumber == -1) + { + log.Warning("Couldn't find line number for comment on {RelativePath} @ {CommitSha}", RelativePath, model.Thread.CommitSha); + // Fall back to opening outdated file if we can't find a line number for the comment + file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha); + thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); + } + } } if (thread != null && thread.LineNumber != -1) @@ -61,9 +81,9 @@ async Task DoOpen() await editorService.OpenDiff(session, RelativePath, thread); } } - catch (Exception) + catch (Exception e) { - // TODO: Show error. + log.Error(e, nameof(DoOpen)); } } } diff --git a/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs b/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs index e470647330..08e816830c 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs @@ -116,7 +116,7 @@ public IReadOnlyList BuildCommentThreads( relativePath = relativePath.Replace("\\", "/"); var threadsByPosition = pullRequest.Threads - .Where(x => x.Path == relativePath && !x.IsOutdated) + .Where(x => x.Path == relativePath) .OrderBy(x => x.Id) .GroupBy(x => Tuple.Create(x.OriginalCommitSha, x.OriginalPosition)); var threads = new List(); diff --git a/submodules/octokit.graphql.net b/submodules/octokit.graphql.net index 4d2b083bd8..ff20b6e9de 160000 --- a/submodules/octokit.graphql.net +++ b/submodules/octokit.graphql.net @@ -1 +1 @@ -Subproject commit 4d2b083bd8eaeb05b7f089e4aedc9d0e0015b61d +Subproject commit ff20b6e9de3d016112de8787ec8ade080214db2b