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

Commit 40d66be

Browse files
authored
Merge branch 'master' into fixes/1444-pr-session-manager-tests-factory
2 parents 7ba2610 + 2199169 commit 40d66be

File tree

8 files changed

+104
-23
lines changed

8 files changed

+104
-23
lines changed

src/GitHub.App/Caches/CacheIndex.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static IObservable<CacheIndex> AddAndSaveToIndex(IBlobCache cache, string
6262
Guard.ArgumentNotNull(item, nameof(item));
6363

6464
return cache.GetOrCreateObject(indexKey, () => Create(indexKey))
65+
.Select(x => x.IndexKey == null ? Create(indexKey) : x)
6566
.Do(index =>
6667
{
6768
var k = string.Format(CultureInfo.InvariantCulture, "{0}|{1}", index.IndexKey, item.Key);

src/GitHub.App/Extensions/AkavacheExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ static IObservable<T> GetAndFetchLatestFromIndex<T>(this IBlobCache This,
200200
bool shouldInvalidateOnError = false)
201201
where T : CacheItem
202202
{
203-
var idx = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))).Replay().RefCount();
203+
var idx = Observable.Defer(() => This
204+
.GetOrCreateObject(key, () => CacheIndex.Create(key)))
205+
.Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x)
206+
.Replay()
207+
.RefCount();
204208

205209

206210
var fetch = idx
@@ -264,6 +268,7 @@ public static IObservable<T> PutAndUpdateIndex<T>(this IBlobCache blobCache,
264268
{
265269
var absoluteExpiration = blobCache.Scheduler.Now + maxCacheDuration;
266270
return blobCache.GetOrCreateObject(key, () => CacheIndex.Create(key))
271+
.Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x)
267272
.SelectMany(index => fetchFunc()
268273
.Catch<T, Exception>(Observable.Throw<T>)
269274
.SelectMany(x => x.Save<T>(blobCache, key, absoluteExpiration))

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class NavigationViewModel : ViewModelBase, INavigationViewModel
2525
public NavigationViewModel()
2626
{
2727
history = new ReactiveList<IPanePageViewModel>();
28-
history.BeforeItemsAdded.Subscribe(BeforeItemAdded);
29-
history.CollectionChanged += CollectionChanged;
28+
history.Changing.Subscribe(CollectionChanging);
29+
history.Changed.Subscribe(CollectionChanged);
3030

3131
var pos = this.WhenAnyValue(
3232
x => x.Index,
@@ -107,7 +107,7 @@ public bool Forward()
107107
public void Clear()
108108
{
109109
Index = -1;
110-
history.RemoveRange(0, history.Count);
110+
history.Clear();
111111
}
112112

113113
public int RemoveAll(IPanePageViewModel page)
@@ -139,27 +139,34 @@ void ItemRemoved(int removedIndex, IPanePageViewModel page)
139139
}
140140
}
141141

142-
void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
142+
void CollectionChanging(NotifyCollectionChangedEventArgs e)
143143
{
144-
using (DelayChangeNotifications())
144+
if (e.Action == NotifyCollectionChangedAction.Add)
145145
{
146-
switch (e.Action)
146+
foreach (IPanePageViewModel page in e.NewItems)
147147
{
148-
case NotifyCollectionChangedAction.Add:
149-
break;
150-
151-
case NotifyCollectionChangedAction.Remove:
152-
for (var i = 0; i < e.OldItems.Count; ++i)
153-
{
154-
ItemRemoved(e.OldStartingIndex + i, (IPanePageViewModel)e.OldItems[i]);
155-
}
156-
break;
157-
158-
case NotifyCollectionChangedAction.Reset:
159-
throw new NotSupportedException();
148+
BeforeItemAdded(page);
149+
}
150+
}
151+
else if (e.Action == NotifyCollectionChangedAction.Reset)
152+
{
153+
foreach (var page in history)
154+
{
155+
page.Dispose();
156+
}
157+
}
158+
}
160159

161-
default:
162-
throw new NotImplementedException();
160+
void CollectionChanged(NotifyCollectionChangedEventArgs e)
161+
{
162+
using (DelayChangeNotifications())
163+
{
164+
if (e.Action == NotifyCollectionChangedAction.Remove)
165+
{
166+
for (var i = 0; i < e.OldItems.Count; ++i)
167+
{
168+
ItemRemoved(e.OldStartingIndex + i, (IPanePageViewModel)e.OldItems[i]);
169+
}
163170
}
164171
}
165172
}

src/GitHub.InlineReviews/Models/InlineCommentThreadModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public InlineCommentThreadModel(
3939

4040
Comments = comments.ToList();
4141
DiffMatch = diffMatch;
42+
DiffLineType = diffMatch[0].Type;
4243
OriginalCommitSha = originalCommitSha;
4344
OriginalPosition = originalPosition;
4445
RelativePath = relativePath;
@@ -51,7 +52,7 @@ public InlineCommentThreadModel(
5152
public IList<DiffLine> DiffMatch { get; }
5253

5354
/// <inheritdoc/>
54-
public DiffChangeType DiffLineType => DiffMatch.First().Type;
55+
public DiffChangeType DiffLineType { get; }
5556

5657
/// <inheritdoc/>
5758
public bool IsStale

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 11 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,6 +92,13 @@ 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+
if (firstLine == null)
97+
{
98+
log.Warning("Ignoring in-line comment in {RelativePath} with no diff line context", relativePath);
99+
continue;
100+
}
101+
91102
var thread = new InlineCommentThreadModel(
92103
relativePath,
93104
comments.Key.Item1,

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ async Task RefreshRepositories()
375375

376376
public void DoCreate()
377377
{
378+
ServiceProvider.GitServiceProvider = TEServiceProvider;
378379
var dialogService = ServiceProvider.GetService<IDialogService>();
379380
dialogService.ShowCreateRepositoryDialog(SectionConnection);
380381
}

test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionServiceTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ Line 2
5353
}
5454
}
5555

56+
[Test]
57+
public async Task IgnoreCommentsWithNoDiffLineContext()
58+
{
59+
var baseContents = "Line 1";
60+
var headContents = "Line 1";
61+
62+
var comment = CreateComment(@"@@ -10,7 +10,6 @@ class Program");
63+
64+
using (var diffService = new FakeDiffService(FilePath, baseContents))
65+
{
66+
var diff = await diffService.Diff(FilePath, headContents);
67+
var pullRequest = CreatePullRequest(FilePath, comment);
68+
var target = CreateTarget(diffService);
69+
70+
var result = target.BuildCommentThreads(
71+
pullRequest,
72+
FilePath,
73+
diff);
74+
75+
Assert.That(result, Is.Empty);
76+
}
77+
}
78+
5679
[Test]
5780
public async Task MatchesReviewCommentOnDifferentLine()
5881
{
@@ -212,7 +235,7 @@ Line 2
212235

213236
Assert.That(3, Is.EqualTo(threads[0].LineNumber));
214237
Assert.That(
215-
new[]
238+
new[]
216239
{
217240
Tuple.Create(2, DiffSide.Right),
218241
Tuple.Create(3, DiffSide.Right)

test/UnitTests/GitHub.App/ViewModels/GitHubPane/NavigationViewModelTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using System.Reactive;
35
using System.Reactive.Linq;
46
using System.Reactive.Subjects;
@@ -309,6 +311,36 @@ public void CallsDeactivatedAndThenDisposedOnPages()
309311
first.Dispose();
310312
});
311313
}
314+
315+
[Test]
316+
public void DoesntThrowWhenHistoryHasMoreThan10Items()
317+
{
318+
var target = new NavigationViewModel();
319+
var pages = new List<IPanePageViewModel>();
320+
321+
for (var i = 0; i < 11; ++i)
322+
{
323+
var page = CreatePage();
324+
pages.Add(page);
325+
target.NavigateTo(page);
326+
}
327+
328+
foreach (var page in pages)
329+
{
330+
page.ClearReceivedCalls();
331+
}
332+
333+
target.Clear();
334+
335+
pages.Last().Received().Deactivated();
336+
pages.Last().Received().Dispose();
337+
338+
foreach (var page in pages.Take(pages.Count - 1))
339+
{
340+
page.DidNotReceive().Deactivated();
341+
page.Received().Dispose();
342+
}
343+
}
312344
}
313345

314346
public class TheRemoveMethod

0 commit comments

Comments
 (0)