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

Commit 0983ef0

Browse files
committed
Moved NumberOfShowCurrentPullRequest tracking into command
1 parent 7511113 commit 0983ef0

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Windows;
3-
using System.Windows.Input;
43
using System.Windows.Controls;
54
using System.Windows.Controls.Primitives;
65
using System.ComponentModel.Composition;
@@ -10,7 +9,6 @@
109
using GitHub.Services;
1110
using GitHub.Models;
1211
using GitHub.Logging;
13-
using GitHub.Extensions;
1412
using Serilog;
1513
using ReactiveUI;
1614

@@ -71,8 +69,7 @@ void RefreshCurrentSession()
7169

7270
PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestModel pullRequest)
7371
{
74-
var trackingCommand = new UsageTrackingCommand(showCurrentPullRequestCommand, usageTracker);
75-
var pullRequestStatusViewModel = new PullRequestStatusViewModel(trackingCommand);
72+
var pullRequestStatusViewModel = new PullRequestStatusViewModel(showCurrentPullRequestCommand);
7673
pullRequestStatusViewModel.Number = pullRequest.Number;
7774
pullRequestStatusViewModel.Title = pullRequest.Title;
7875
return pullRequestStatusViewModel;
@@ -116,41 +113,5 @@ StatusBar FindSccStatusBar(Window mainWindow)
116113
var contentControl = mainWindow?.Template?.FindName(StatusBarPartName, mainWindow) as ContentControl;
117114
return contentControl?.Content as StatusBar;
118115
}
119-
120-
class UsageTrackingCommand : ICommand
121-
{
122-
readonly ICommand command;
123-
readonly IUsageTracker usageTracker;
124-
125-
internal UsageTrackingCommand(ICommand command, IUsageTracker usageTracker)
126-
{
127-
this.command = command;
128-
this.usageTracker = usageTracker;
129-
}
130-
131-
public event EventHandler CanExecuteChanged
132-
{
133-
add
134-
{
135-
command.CanExecuteChanged += value;
136-
}
137-
138-
remove
139-
{
140-
command.CanExecuteChanged -= value;
141-
}
142-
}
143-
144-
public bool CanExecute(object parameter)
145-
{
146-
return command.CanExecute(parameter);
147-
}
148-
149-
public void Execute(object parameter)
150-
{
151-
command.Execute(parameter);
152-
usageTracker.IncrementCounter(x => x.NumberOfShowCurrentPullRequest).Forget();
153-
}
154-
}
155116
}
156117
}

src/GitHub.VisualStudio/Commands/ShowCurrentPullRequestCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GitHub.Commands;
55
using GitHub.Logging;
66
using GitHub.Services;
7+
using GitHub.Extensions;
78
using GitHub.Services.Vssdk.Commands;
89
using Serilog;
910

@@ -20,12 +21,14 @@ public class ShowCurrentPullRequestCommand : VsCommand, IShowCurrentPullRequestC
2021
{
2122
static readonly ILogger log = LogManager.ForContext<ShowCurrentPullRequestCommand>();
2223
readonly IGitHubServiceProvider serviceProvider;
24+
readonly Lazy<IUsageTracker> usageTracker;
2325

2426
[ImportingConstructor]
25-
protected ShowCurrentPullRequestCommand(IGitHubServiceProvider serviceProvider)
27+
protected ShowCurrentPullRequestCommand(IGitHubServiceProvider serviceProvider, Lazy<IUsageTracker> usageTracker)
2628
: base(CommandSet, CommandId)
2729
{
2830
this.serviceProvider = serviceProvider;
31+
this.usageTracker = usageTracker;
2932
}
3033

3134
/// <summary>
@@ -58,6 +61,8 @@ public override async Task Execute()
5861
var manager = serviceProvider.TryGetService<IGitHubToolWindowManager>();
5962
var host = await manager.ShowGitHubPane();
6063
await host.ShowPullRequest(session.RepositoryOwner, host.LocalRepository.Name, pullRequest.Number);
64+
65+
usageTracker.Value.IncrementCounter(x => x.NumberOfShowCurrentPullRequest).Forget();
6166
}
6267
catch (Exception ex)
6368
{

0 commit comments

Comments
 (0)