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

Commit 6648d1d

Browse files
committed
Only show PR status bar for GitHub repositories
1 parent 15257a1 commit 6648d1d

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
using System.Windows.Controls.Primitives;
66
using System.ComponentModel.Composition;
77
using System.Reactive.Linq;
8+
using System.Threading.Tasks;
89
using System.Linq.Expressions;
910
using GitHub.Commands;
11+
using GitHub.Primitives;
1012
using GitHub.InlineReviews.Views;
1113
using GitHub.InlineReviews.ViewModels;
1214
using GitHub.Services;
@@ -34,6 +36,7 @@ public class PullRequestStatusBarManager
3436
// TeamExplorerContext needs to retrieve DTE using GetService.
3537
readonly Lazy<IPullRequestSessionManager> pullRequestSessionManager;
3638
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
39+
readonly Lazy<IConnectionManager> connectionManager;
3740

3841
IDisposable currentSessionSubscription;
3942

@@ -43,7 +46,8 @@ public PullRequestStatusBarManager(
4346
IOpenPullRequestsCommand openPullRequestsCommand,
4447
IShowCurrentPullRequestCommand showCurrentPullRequestCommand,
4548
Lazy<IPullRequestSessionManager> pullRequestSessionManager,
46-
Lazy<ITeamExplorerContext> teamExplorerContext)
49+
Lazy<ITeamExplorerContext> teamExplorerContext,
50+
Lazy<IConnectionManager> connectionManager)
4751
{
4852
this.openPullRequestsCommand = new UsageTrackingCommand(openPullRequestsCommand,
4953
usageTracker, x => x.NumberOfStatusBarOpenPullRequestList);
@@ -52,6 +56,7 @@ public PullRequestStatusBarManager(
5256

5357
this.pullRequestSessionManager = pullRequestSessionManager;
5458
this.teamExplorerContext = teamExplorerContext;
59+
this.connectionManager = connectionManager;
5560
}
5661

5762
/// <summary>
@@ -78,25 +83,55 @@ void RefreshActiveRepository(ILocalRepositoryModel repository)
7883
{
7984
currentSessionSubscription?.Dispose();
8085
currentSessionSubscription = pullRequestSessionManager.Value.WhenAnyValue(x => x.CurrentSession)
81-
.Subscribe(x => RefreshCurrentSession(repository, x));
86+
.Subscribe(x => RefreshCurrentSession(repository, x).Forget());
8287
}
8388

84-
void RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
89+
async Task RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
8590
{
86-
var cloneUrl = repository?.CloneUrl;
87-
var host = cloneUrl?.Host;
88-
if (host != null && host.Equals("github.com", StringComparison.OrdinalIgnoreCase))
91+
try
8992
{
90-
// Only show PR status bar if repo has remote
93+
var showStatus = await IsDotComOrEnterpriseRepository(repository);
94+
if (!showStatus)
95+
{
96+
ShowStatus(null);
97+
return;
98+
}
99+
91100
var viewModel = CreatePullRequestStatusViewModel(session);
92101
ShowStatus(viewModel);
93102
}
94-
else
103+
catch (Exception e)
95104
{
96-
ShowStatus(null);
105+
log.Error(e, nameof(RefreshCurrentSession));
97106
}
98107
}
99108

109+
async Task<bool> IsDotComOrEnterpriseRepository(ILocalRepositoryModel repository)
110+
{
111+
var cloneUrl = repository?.CloneUrl;
112+
if (cloneUrl == null)
113+
{
114+
// No active repository or remote
115+
return false;
116+
}
117+
118+
var isDotCom = HostAddress.IsGitHubDotComUri(cloneUrl.ToRepositoryUrl());
119+
if (isDotCom)
120+
{
121+
// This is a github.com repository
122+
return true;
123+
}
124+
125+
var connection = await connectionManager.Value.GetConnection(repository);
126+
if (connection != null)
127+
{
128+
// This is an enterprise repository
129+
return true;
130+
}
131+
132+
return false;
133+
}
134+
100135
PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestSession session)
101136
{
102137
var pullRequestStatusViewModel = new PullRequestStatusViewModel(openPullRequestsCommand, showCurrentPullRequestCommand);

0 commit comments

Comments
 (0)