From 15257a132eb4b8c3141c0bc60bd8da34c558fd21 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Mon, 23 Apr 2018 13:16:12 +0100 Subject: [PATCH 1/3] Make the Pull requests button less distracting --- .../Services/PullRequestStatusBarManager.cs | 3 ++- src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs b/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs index d9f0a93790..afbaaf9ea1 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs @@ -84,7 +84,8 @@ void RefreshActiveRepository(ILocalRepositoryModel repository) void RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session) { var cloneUrl = repository?.CloneUrl; - if (cloneUrl != null) + var host = cloneUrl?.Host; + if (host != null && host.Equals("github.com", StringComparison.OrdinalIgnoreCase)) { // Only show PR status bar if repo has remote var viewModel = CreatePullRequestStatusViewModel(session); diff --git a/src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml b/src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml index d74bf1c804..180ecd8532 100644 --- a/src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml +++ b/src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml @@ -49,14 +49,11 @@ VerticalAlignment="Bottom" Margin="0 0 4 0 " Icon="git_pull_request" /> - - Pull requests - - Open or Create a Pull request + View, Checkout or Create a Pull request From 6648d1d7e277ad793889a51ac09227d990eb67c0 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Mon, 14 May 2018 11:59:03 +0100 Subject: [PATCH 2/3] Only show PR status bar for GitHub repositories --- .../Services/PullRequestStatusBarManager.cs | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs b/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs index afbaaf9ea1..de3a71bb04 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs @@ -5,8 +5,10 @@ using System.Windows.Controls.Primitives; using System.ComponentModel.Composition; using System.Reactive.Linq; +using System.Threading.Tasks; using System.Linq.Expressions; using GitHub.Commands; +using GitHub.Primitives; using GitHub.InlineReviews.Views; using GitHub.InlineReviews.ViewModels; using GitHub.Services; @@ -34,6 +36,7 @@ public class PullRequestStatusBarManager // TeamExplorerContext needs to retrieve DTE using GetService. readonly Lazy pullRequestSessionManager; readonly Lazy teamExplorerContext; + readonly Lazy connectionManager; IDisposable currentSessionSubscription; @@ -43,7 +46,8 @@ public PullRequestStatusBarManager( IOpenPullRequestsCommand openPullRequestsCommand, IShowCurrentPullRequestCommand showCurrentPullRequestCommand, Lazy pullRequestSessionManager, - Lazy teamExplorerContext) + Lazy teamExplorerContext, + Lazy connectionManager) { this.openPullRequestsCommand = new UsageTrackingCommand(openPullRequestsCommand, usageTracker, x => x.NumberOfStatusBarOpenPullRequestList); @@ -52,6 +56,7 @@ public PullRequestStatusBarManager( this.pullRequestSessionManager = pullRequestSessionManager; this.teamExplorerContext = teamExplorerContext; + this.connectionManager = connectionManager; } /// @@ -78,25 +83,55 @@ void RefreshActiveRepository(ILocalRepositoryModel repository) { currentSessionSubscription?.Dispose(); currentSessionSubscription = pullRequestSessionManager.Value.WhenAnyValue(x => x.CurrentSession) - .Subscribe(x => RefreshCurrentSession(repository, x)); + .Subscribe(x => RefreshCurrentSession(repository, x).Forget()); } - void RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session) + async Task RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session) { - var cloneUrl = repository?.CloneUrl; - var host = cloneUrl?.Host; - if (host != null && host.Equals("github.com", StringComparison.OrdinalIgnoreCase)) + try { - // Only show PR status bar if repo has remote + var showStatus = await IsDotComOrEnterpriseRepository(repository); + if (!showStatus) + { + ShowStatus(null); + return; + } + var viewModel = CreatePullRequestStatusViewModel(session); ShowStatus(viewModel); } - else + catch (Exception e) { - ShowStatus(null); + log.Error(e, nameof(RefreshCurrentSession)); } } + async Task IsDotComOrEnterpriseRepository(ILocalRepositoryModel repository) + { + var cloneUrl = repository?.CloneUrl; + if (cloneUrl == null) + { + // No active repository or remote + return false; + } + + var isDotCom = HostAddress.IsGitHubDotComUri(cloneUrl.ToRepositoryUrl()); + if (isDotCom) + { + // This is a github.com repository + return true; + } + + var connection = await connectionManager.Value.GetConnection(repository); + if (connection != null) + { + // This is an enterprise repository + return true; + } + + return false; + } + PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestSession session) { var pullRequestStatusViewModel = new PullRequestStatusViewModel(openPullRequestsCommand, showCurrentPullRequestCommand); From 65f5f6c2446fa55b8138957349dad34c60bf35c9 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Wed, 16 May 2018 18:26:27 +0100 Subject: [PATCH 3/3] Restore using GitHub.Extensions --- .../Services/PullRequestStatusBarManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs b/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs index 5a4f906794..c6672b2847 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs @@ -6,8 +6,8 @@ using System.ComponentModel.Composition; using System.Reactive.Linq; using System.Threading.Tasks; -using System.Linq.Expressions; using GitHub.Commands; +using GitHub.Extensions; using GitHub.Primitives; using GitHub.InlineReviews.Views; using GitHub.InlineReviews.ViewModels;