55using System . Windows . Controls . Primitives ;
66using System . ComponentModel . Composition ;
77using System . Reactive . Linq ;
8+ using System . Threading . Tasks ;
89using GitHub . Commands ;
10+ using GitHub . Extensions ;
11+ using GitHub . Primitives ;
912using GitHub . InlineReviews . Views ;
1013using GitHub . InlineReviews . ViewModels ;
1114using 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 ) ;
0 commit comments