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

Commit 73efd94

Browse files
authored
Merge branch 'master' into fixes/1620-disable-in-blend
2 parents 44f47c5 + 12a81c6 commit 73efd94

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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 GitHub.Commands;
10+
using GitHub.Extensions;
11+
using GitHub.Primitives;
912
using GitHub.InlineReviews.Views;
1013
using GitHub.InlineReviews.ViewModels;
1114
using GitHub.Services;
@@ -32,6 +35,7 @@ public class PullRequestStatusBarManager
3235
// TeamExplorerContext needs to retrieve DTE using GetService.
3336
readonly Lazy<IPullRequestSessionManager> pullRequestSessionManager;
3437
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
38+
readonly Lazy<IConnectionManager> connectionManager;
3539

3640
IDisposable currentSessionSubscription;
3741

@@ -41,7 +45,8 @@ public PullRequestStatusBarManager(
4145
IOpenPullRequestsCommand openPullRequestsCommand,
4246
IShowCurrentPullRequestCommand showCurrentPullRequestCommand,
4347
Lazy<IPullRequestSessionManager> pullRequestSessionManager,
44-
Lazy<ITeamExplorerContext> teamExplorerContext)
48+
Lazy<ITeamExplorerContext> teamExplorerContext,
49+
Lazy<IConnectionManager> connectionManager)
4550
{
4651
this.openPullRequestsCommand = new UsageTrackingCommand(usageTracker,
4752
x => x.NumberOfStatusBarOpenPullRequestList, openPullRequestsCommand);
@@ -50,6 +55,7 @@ public PullRequestStatusBarManager(
5055

5156
this.pullRequestSessionManager = pullRequestSessionManager;
5257
this.teamExplorerContext = teamExplorerContext;
58+
this.connectionManager = connectionManager;
5359
}
5460

5561
/// <summary>
@@ -76,24 +82,55 @@ void RefreshActiveRepository(ILocalRepositoryModel repository)
7682
{
7783
currentSessionSubscription?.Dispose();
7884
currentSessionSubscription = pullRequestSessionManager.Value.WhenAnyValue(x => x.CurrentSession)
79-
.Subscribe(x => RefreshCurrentSession(repository, x));
85+
.Subscribe(x => RefreshCurrentSession(repository, x).Forget());
8086
}
8187

82-
void RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
88+
async Task RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
8389
{
84-
var cloneUrl = repository?.CloneUrl;
85-
if (cloneUrl != null)
90+
try
8691
{
87-
// Only show PR status bar if repo has remote
92+
var showStatus = await IsDotComOrEnterpriseRepository(repository);
93+
if (!showStatus)
94+
{
95+
ShowStatus(null);
96+
return;
97+
}
98+
8899
var viewModel = CreatePullRequestStatusViewModel(session);
89100
ShowStatus(viewModel);
90101
}
91-
else
102+
catch (Exception e)
92103
{
93-
ShowStatus(null);
104+
log.Error(e, nameof(RefreshCurrentSession));
94105
}
95106
}
96107

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

src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@
4949
VerticalAlignment="Bottom"
5050
Margin="0 0 4 0 "
5151
Icon="git_pull_request" />
52-
<TextBlock VerticalAlignment="Center">
53-
Pull requests
54-
</TextBlock>
5552
</StackPanel>
5653
</Button>
5754
<Grid.ToolTip>
5855
<TextBlock VerticalAlignment="Center">
59-
Open or Create a Pull request
56+
View, Checkout or Create a Pull request
6057
</TextBlock>
6158
</Grid.ToolTip>
6259
</Grid>

0 commit comments

Comments
 (0)