3
3
using System . Reactive ;
4
4
using System . Threading . Tasks ;
5
5
using GitHub . Extensions ;
6
+ using GitHub . Logging ;
6
7
using GitHub . Models ;
7
8
using GitHub . Services ;
8
9
using ReactiveUI ;
10
+ using Serilog ;
9
11
10
12
namespace GitHub . ViewModels . GitHubPane
11
13
{
@@ -14,6 +16,8 @@ namespace GitHub.ViewModels.GitHubPane
14
16
/// </summary>
15
17
public class PullRequestReviewCommentViewModel : IPullRequestReviewFileCommentViewModel
16
18
{
19
+ static readonly ILogger log = LogManager . ForContext < PullRequestReviewCommentViewModel > ( ) ;
20
+
17
21
readonly IPullRequestEditorService editorService ;
18
22
readonly IPullRequestSession session ;
19
23
readonly PullRequestReviewCommentModel model ;
@@ -52,18 +56,34 @@ async Task DoOpen()
52
56
{
53
57
if ( thread == null )
54
58
{
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
+ }
57
77
}
58
78
59
79
if ( thread != null && thread . LineNumber != - 1 )
60
80
{
61
81
await editorService . OpenDiff ( session , RelativePath , thread ) ;
62
82
}
63
83
}
64
- catch ( Exception )
84
+ catch ( Exception e )
65
85
{
66
- // TODO: Show error.
86
+ log . Error ( e , nameof ( DoOpen ) ) ;
67
87
}
68
88
}
69
89
}
0 commit comments