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

Commit 60b95d4

Browse files
committed
Handle repo change and status change events separately
Fix the SetActiveRepository method to fire PropertyChanged not StatusChanged.
1 parent e3d8de8 commit 60b95d4

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ public PullRequestSessionManager(
6767
this.modelServiceFactory = modelServiceFactory;
6868

6969
Observable.FromEventPattern(teamExplorerContext, nameof(teamExplorerContext.StatusChanged))
70-
.StartWith((EventPattern<object>)null)
7170
.ObserveOn(RxApp.MainThreadScheduler)
72-
.Subscribe(_ => RepoChanged(teamExplorerContext.ActiveRepository).Forget());
71+
.Subscribe(_ => StatusChanged().Forget());
7372

7473
teamExplorerContext.WhenAnyValue(x => x.ActiveRepository)
75-
.Skip(1)
7674
.ObserveOn(RxApp.MainThreadScheduler)
7775
.Subscribe(x => RepoChanged(x).Forget());
7876
}
@@ -159,8 +157,8 @@ public async Task<IPullRequestSession> GetSession(IPullRequestModel pullRequest)
159157
{
160158
// The branch for the PR was not previously marked with the PR number in the git
161159
// config so we didn't pick up that the current branch is a PR branch. That has
162-
// now been corrected, so call RepoChanged to make sure everything is up-to-date.
163-
await RepoChanged(repository);
160+
// now been corrected, so call StatusChanged to make sure everything is up-to-date.
161+
await StatusChanged();
164162
}
165163

166164
return await GetSessionInternal(pullRequest);
@@ -191,28 +189,23 @@ public PullRequestTextBufferInfo GetTextBufferInfo(ITextBuffer buffer)
191189

192190
async Task RepoChanged(ILocalRepositoryModel localRepositoryModel)
193191
{
194-
try
195-
{
196-
if (localRepositoryModel != repository)
197-
{
198-
repository = localRepositoryModel;
199-
CurrentSession = null;
200-
sessions.Clear();
201-
202-
if (localRepositoryModel == null)
203-
{
204-
return;
205-
}
192+
repository = localRepositoryModel;
193+
CurrentSession = null;
194+
sessions.Clear();
206195

207-
if (string.IsNullOrWhiteSpace(localRepositoryModel.CloneUrl))
208-
{
209-
return;
210-
}
211-
}
196+
if (localRepositoryModel != null)
197+
{
198+
await StatusChanged();
199+
}
200+
}
212201

202+
async Task StatusChanged()
203+
{
204+
try
205+
{
213206
var session = CurrentSession;
214207

215-
var pr = await service.GetPullRequestForCurrentBranch(localRepositoryModel).FirstOrDefaultAsync();
208+
var pr = await service.GetPullRequestForCurrentBranch(repository).FirstOrDefaultAsync();
216209
if (pr != null)
217210
{
218211
var changePR =
@@ -222,7 +215,7 @@ async Task RepoChanged(ILocalRepositoryModel localRepositoryModel)
222215
if (changePR)
223216
{
224217
var modelService = await connectionManager.GetModelService(repository, modelServiceFactory);
225-
var pullRequest = await modelService?.GetPullRequest(pr.Item1, localRepositoryModel.Name, pr.Item2);
218+
var pullRequest = await modelService?.GetPullRequest(pr.Item1, repository.Name, pr.Item2);
226219
if (pullRequest != null)
227220
{
228221
var newSession = await GetSessionInternal(pullRequest);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.VisualStudio.Utilities;
1919
using NSubstitute;
2020
using NUnit.Framework;
21+
using System.ComponentModel;
2122

2223
namespace GitHub.InlineReviews.UnitTests.Services
2324
{
@@ -1066,7 +1067,8 @@ static ITeamExplorerContext CreateTeamExplorerContext(ILocalRepositoryModel repo
10661067
static void SetActiveRepository(ITeamExplorerContext teamExplorerContext, ILocalRepositoryModel localRepositoryModel)
10671068
{
10681069
teamExplorerContext.ActiveRepository.Returns(localRepositoryModel);
1069-
teamExplorerContext.StatusChanged += Raise.Event();
1070+
var eventArgs = new PropertyChangedEventArgs(nameof(teamExplorerContext.ActiveRepository));
1071+
teamExplorerContext.PropertyChanged += Raise.Event<PropertyChangedEventHandler>(teamExplorerContext, eventArgs);
10701072
}
10711073
}
10721074
}

0 commit comments

Comments
 (0)