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

Commit 45b48dd

Browse files
committed
Add log when no diff lines for inline comment
Inline comments should be associated with a number of diff lines. This adds a log warning that will help us track down the issue.
1 parent 9eb8dfb commit 45b48dd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/GitHub.InlineReviews/Models/InlineCommentThreadModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public InlineCommentThreadModel(
3131
string originalCommitSha,
3232
int originalPosition,
3333
IList<DiffLine> diffMatch,
34+
DiffChangeType diffLineType,
3435
IEnumerable<IPullRequestReviewCommentModel> comments)
3536
{
3637
Guard.ArgumentNotNull(relativePath, nameof(relativePath));
@@ -39,6 +40,7 @@ public InlineCommentThreadModel(
3940

4041
Comments = comments.ToList();
4142
DiffMatch = diffMatch;
43+
DiffLineType = diffLineType;
4244
OriginalCommitSha = originalCommitSha;
4345
OriginalPosition = originalPosition;
4446
RelativePath = relativePath;
@@ -51,7 +53,7 @@ public InlineCommentThreadModel(
5153
public IList<DiffLine> DiffMatch { get; }
5254

5355
/// <inheritdoc/>
54-
public DiffChangeType DiffLineType => DiffMatch.First().Type;
56+
public DiffChangeType DiffLineType { get; }
5557

5658
/// <inheritdoc/>
5759
public bool IsStale

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
using GitHub.InlineReviews.Models;
1212
using GitHub.Models;
1313
using GitHub.Primitives;
14+
using GitHub.Logging;
1415
using GitHub.Services;
1516
using LibGit2Sharp;
1617
using Microsoft.VisualStudio.Text;
1718
using Microsoft.VisualStudio.Text.Projection;
1819
using ReactiveUI;
20+
using Serilog;
1921

2022
namespace GitHub.InlineReviews.Services
2123
{
@@ -25,6 +27,8 @@ namespace GitHub.InlineReviews.Services
2527
[Export(typeof(IPullRequestSessionService))]
2628
public class PullRequestSessionService : IPullRequestSessionService
2729
{
30+
static readonly ILogger log = LogManager.ForContext<PullRequestSessionService>();
31+
2832
readonly IGitService gitService;
2933
readonly IGitClient gitClient;
3034
readonly IDiffService diffService;
@@ -88,11 +92,21 @@ public IReadOnlyList<IInlineCommentThreadModel> BuildCommentThreads(
8892
var chunks = DiffUtilities.ParseFragment(hunk);
8993
var chunk = chunks.Last();
9094
var diffLines = chunk.Lines.Reverse().Take(5).ToList();
95+
var firstLine = diffLines.FirstOrDefault();
96+
var diffLineType = firstLine != null ? firstLine.Type : DiffChangeType.None;
97+
98+
if (firstLine == null)
99+
{
100+
log.Warning("Couldn't find diff lines for inline comment. RelativePath={RelativePath}, OriginalCommitSha={Sha}, OriginalPosition={Position}, Chunks={Chunks}, DiffHunk={DiffHunk}",
101+
relativePath, comments.Key.Item1, comments.Key.Item2, chunks.Count(), hunk);
102+
}
103+
91104
var thread = new InlineCommentThreadModel(
92105
relativePath,
93106
comments.Key.Item1,
94107
comments.Key.Item2,
95108
diffLines,
109+
diffLineType,
96110
comments);
97111
threads.Add(thread);
98112
}

0 commit comments

Comments
 (0)