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

Commit 392b3fe

Browse files
authored
Merge branch 'master' into fixes/github-fork-limit-functionality
2 parents 6a0d221 + ec382fb commit 392b3fe

File tree

17 files changed

+277
-73
lines changed

17 files changed

+277
-73
lines changed

src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using GitHub.Services;
1313
using ReactiveUI;
1414
using Serilog;
15+
using static System.FormattableString;
1516

1617
namespace GitHub.ViewModels.GitHubPane
1718
{
@@ -71,6 +72,8 @@ public PullRequestReviewAuthoringViewModel(
7172
hasBodyOrComments,
7273
_ => DoSubmit(Octokit.PullRequestReviewEvent.RequestChanges));
7374
Cancel = ReactiveCommand.CreateAsyncTask(DoCancel);
75+
NavigateToPullRequest = ReactiveCommand.Create().OnExecuteCompleted(_ =>
76+
NavigateTo(Invariant($"{LocalRepository.Owner}/{LocalRepository.Name}/pull/{PullRequestModel.Number}")));
7477
}
7578

7679
/// <inheritdoc/>

src/GitHub.Exports/Exports/ExportForProcess.cs renamed to src/GitHub.Exports/Exports/ExportForProcessAttribute.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.ComponentModel.Composition;
45

56
namespace GitHub.Exports
@@ -11,24 +12,32 @@ namespace GitHub.Exports
1112
/// This attribute is used to mark exports that mustn't be loaded into Blend.
1213
/// See: https://github.com/github/VisualStudio/pull/1055
1314
/// </remarks>
15+
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "Extended by ExportForVisualStudioProcessAttribute")]
1416
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
15-
public sealed class ExportForProcessAttribute : ExportAttribute
17+
public class ExportForProcessAttribute : ExportAttribute
1618
{
19+
// Unique name for exports that have been disabled
20+
const string DisabledContractName = "GitHub.Disabled";
21+
1722
/// <summary>
1823
/// Define an export that is only exposed in a specific named process.
1924
/// </summary>
20-
/// <param name="contractType">The contract type to expose.</param>
2125
/// <param name="processName">Name of the process to expose export from (e.g. 'devenv').</param>
22-
public ExportForProcessAttribute(Type contractType, string processName) : base(ExportForProcess(contractType, processName))
26+
/// <param name="contractType">The contract type to expose.</param>
27+
public ExportForProcessAttribute(string processName, Type contractType = null) :
28+
base(ContractNameForProcess(processName), contractType)
2329
{
2430
ProcessName = processName;
2531
}
2632

27-
static Type ExportForProcess(Type contractType, string processName)
33+
static string ContractNameForProcess(string processName)
2834
{
29-
return Process.GetCurrentProcess().ProcessName == processName ? contractType : null;
35+
var enabled = IsProcess(processName);
36+
return enabled ? null : DisabledContractName;
3037
}
3138

39+
public static bool IsProcess(string processName) => Process.GetCurrentProcess().ProcessName == processName;
40+
3241
/// <summary>
3342
/// The process name export will be exposed in.
3443
/// </summary>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
3+
namespace GitHub.Exports
4+
{
5+
/// <summary>
6+
/// Only expose export when executing in Visual Studio (devenv) process.
7+
/// </summary>
8+
/// <remarks>
9+
/// This attribute is used to mark exports that mustn't be loaded into Blend.
10+
/// See: https://github.com/github/VisualStudio/pull/1055
11+
/// </remarks>
12+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
13+
public sealed class ExportForVisualStudioProcessAttribute : ExportForProcessAttribute
14+
{
15+
const string VisualStudioProcessName = "devenv";
16+
17+
/// <summary>
18+
/// Define an export that is only exposed in a Visual Studio (devenv) process.
19+
/// </summary>
20+
/// <param name="contractType">The contract type to expose.</param>
21+
public ExportForVisualStudioProcessAttribute(Type contractType = null) :
22+
base(VisualStudioProcessName, contractType)
23+
{
24+
}
25+
26+
public static bool IsVisualStudioProcess() => IsProcess(VisualStudioProcessName);
27+
}
28+
}

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@
159159
<Compile Include="Commands\IGoToSolutionOrPullRequestFileCommand.cs" />
160160
<Compile Include="Commands\IVsCommand.cs" />
161161
<Compile Include="Commands\IVsCommandBase.cs" />
162-
<Compile Include="Exports\ExportForProcess.cs" />
162+
<Compile Include="Exports\ExportForVisualStudioProcessAttribute.cs" />
163+
<Compile Include="Exports\ExportForProcessAttribute.cs" />
163164
<Compile Include="Extensions\ConnectionManagerExtensions.cs" />
164165
<Compile Include="GitHubLogicException.cs" />
165166
<Compile Include="Models\CommitMessage.cs" />

src/GitHub.InlineReviews/InlineReviewsPackage.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
using System.ComponentModel.Design;
33
using System.Runtime.InteropServices;
44
using System.Threading;
5+
using GitHub.Exports;
6+
using GitHub.Logging;
57
using GitHub.Commands;
68
using GitHub.Services.Vssdk.Commands;
79
using GitHub.VisualStudio;
810
using Microsoft.VisualStudio.ComponentModelHost;
911
using Microsoft.VisualStudio.Shell;
1012
using Microsoft.VisualStudio.Threading;
13+
using Serilog;
1114
using Task = System.Threading.Tasks.Task;
1215

1316
namespace GitHub.InlineReviews
@@ -18,6 +21,8 @@ namespace GitHub.InlineReviews
1821
[ProvideMenuResource("Menus.ctmenu", 1)]
1922
public class InlineReviewsPackage : AsyncPackage
2023
{
24+
static readonly ILogger log = LogManager.ForContext<InlineReviewsPackage>();
25+
2126
protected override async Task InitializeAsync(
2227
CancellationToken cancellationToken,
2328
IProgress<ServiceProgressData> progress)
@@ -33,6 +38,12 @@ protected override async Task InitializeAsync(
3338

3439
async Task InitializeMenus()
3540
{
41+
if (!ExportForVisualStudioProcessAttribute.IsVisualStudioProcess())
42+
{
43+
log.Warning("Don't initialize menus for non-Visual Studio process");
44+
return;
45+
}
46+
3647
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
3748
var exports = componentModel.DefaultExportProvider;
3849
var commands = new IVsCommandBase[]

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>

src/GitHub.TeamFoundation.14/Base/TeamExplorerServiceHolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void NotifyActiveRepo()
138138

139139
void UpdateActiveRepo()
140140
{
141-
// NOTE: gitService will be null in Expression Blend or Safe Mode
141+
// NOTE: gitService might be null in Blend or Safe Mode
142142
var repo = gitService?.ActiveRepositories.FirstOrDefault();
143143

144144
if (!Equals(repo, ActiveRepo))

src/GitHub.VisualStudio.UI/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.VisualStudio.UI/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@
425425
<data name="Options_EnableTraceLoggingText" xml:space="preserve">
426426
<value>Enable Trace Logging</value>
427427
</data>
428+
<data name="BlendDialogText" xml:space="preserve">
429+
<value>The GitHub extension is not available inside Blend</value>
430+
</data>
428431
<data name="Options_ForkButtonLabel" xml:space="preserve">
429432
<value>Show Fork button in Team Explorer</value>
430433
</data>

0 commit comments

Comments
 (0)