55using System . Windows . Controls . Primitives ;
66using System . ComponentModel . Composition ;
77using System . Reactive . Linq ;
8+ using System . Threading . Tasks ;
89using System . Linq . Expressions ;
910using GitHub . Commands ;
11+ using GitHub . Primitives ;
1012using GitHub . InlineReviews . Views ;
1113using GitHub . InlineReviews . ViewModels ;
1214using 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