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

Commit 56844b1

Browse files
committed
Add NumberOfOpenPullRequests counter to UsageModel
Track usage of the PR status bar commands explicitly.
1 parent 18b1ce1 commit 56844b1

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/GitHub.Exports/Models/UsageModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class MeasuresModel
6868
public int NumberOfPRReviewDiffViewInlineCommentStartReview { get; set; }
6969
public int NumberOfPRReviewPosts { get; set; }
7070
public int NumberOfShowCurrentPullRequest { get; set; }
71+
public int NumberOfOpenPullRequests { get; set; }
7172
}
7273
}
7374
}

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
using System;
22
using System.Windows;
3+
using System.Windows.Input;
34
using System.Windows.Controls;
45
using System.Windows.Controls.Primitives;
56
using System.ComponentModel.Composition;
67
using System.Reactive.Linq;
8+
using System.Linq.Expressions;
79
using GitHub.Commands;
810
using GitHub.InlineReviews.Views;
911
using GitHub.InlineReviews.ViewModels;
1012
using GitHub.Services;
1113
using GitHub.Models;
1214
using GitHub.Logging;
15+
using GitHub.Extensions;
1316
using Serilog;
1417
using ReactiveUI;
1518

@@ -24,8 +27,9 @@ public class PullRequestStatusBarManager
2427
static readonly ILogger log = LogManager.ForContext<PullRequestStatusBarManager>();
2528
const string StatusBarPartName = "PART_SccStatusBarHost";
2629

27-
readonly IOpenPullRequestsCommand openPullRequestsCommand;
28-
readonly IShowCurrentPullRequestCommand showCurrentPullRequestCommand;
30+
readonly IUsageTracker usageTracker;
31+
readonly ICommand openPullRequestsCommand;
32+
readonly ICommand showCurrentPullRequestCommand;
2933

3034
// At the moment these must be constructed on the main thread.
3135
// TeamExplorerContext needs to retrieve DTE using GetService.
@@ -36,13 +40,19 @@ public class PullRequestStatusBarManager
3640

3741
[ImportingConstructor]
3842
public PullRequestStatusBarManager(
43+
IUsageTracker usageTracker,
3944
IOpenPullRequestsCommand openPullRequestsCommand,
4045
IShowCurrentPullRequestCommand showCurrentPullRequestCommand,
4146
Lazy<IPullRequestSessionManager> pullRequestSessionManager,
4247
Lazy<ITeamExplorerContext> teamExplorerContext)
4348
{
44-
this.openPullRequestsCommand = openPullRequestsCommand;
45-
this.showCurrentPullRequestCommand = showCurrentPullRequestCommand;
49+
this.usageTracker = usageTracker;
50+
51+
this.openPullRequestsCommand = new UsageTrackingCommand(openPullRequestsCommand,
52+
usageTracker, x => x.NumberOfOpenPullRequests);
53+
this.showCurrentPullRequestCommand = new UsageTrackingCommand(showCurrentPullRequestCommand,
54+
usageTracker, x => x.NumberOfShowCurrentPullRequest);
55+
4656
this.pullRequestSessionManager = pullRequestSessionManager;
4757
this.teamExplorerContext = teamExplorerContext;
4858
}
@@ -136,5 +146,37 @@ StatusBar FindSccStatusBar(Window mainWindow)
136146
var contentControl = mainWindow?.Template?.FindName(StatusBarPartName, mainWindow) as ContentControl;
137147
return contentControl?.Content as StatusBar;
138148
}
149+
150+
class UsageTrackingCommand : ICommand
151+
{
152+
readonly ICommand command;
153+
readonly IUsageTracker usageTracker;
154+
readonly Expression<Func<UsageModel.MeasuresModel, int>> counter;
155+
156+
internal UsageTrackingCommand(ICommand command, IUsageTracker usageTracker,
157+
Expression<Func<UsageModel.MeasuresModel, int>> counter)
158+
{
159+
this.command = command;
160+
this.usageTracker = usageTracker;
161+
this.counter = counter;
162+
}
163+
164+
public event EventHandler CanExecuteChanged
165+
{
166+
add { command.CanExecuteChanged += value; }
167+
remove { command.CanExecuteChanged -= value; }
168+
}
169+
170+
public bool CanExecute(object parameter)
171+
{
172+
return command.CanExecute(parameter);
173+
}
174+
175+
public void Execute(object parameter)
176+
{
177+
command.Execute(parameter);
178+
usageTracker.IncrementCounter(counter).Forget();
179+
}
180+
}
139181
}
140182
}

src/GitHub.VisualStudio/Commands/ShowCurrentPullRequestCommand.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ public class ShowCurrentPullRequestCommand : VsCommand, IShowCurrentPullRequestC
2121
{
2222
static readonly ILogger log = LogManager.ForContext<ShowCurrentPullRequestCommand>();
2323
readonly IGitHubServiceProvider serviceProvider;
24-
readonly Lazy<IUsageTracker> usageTracker;
2524

2625
[ImportingConstructor]
27-
protected ShowCurrentPullRequestCommand(IGitHubServiceProvider serviceProvider, Lazy<IUsageTracker> usageTracker)
26+
protected ShowCurrentPullRequestCommand(IGitHubServiceProvider serviceProvider)
2827
: base(CommandSet, CommandId)
2928
{
3029
this.serviceProvider = serviceProvider;
31-
this.usageTracker = usageTracker;
3230
}
3331

3432
/// <summary>
@@ -61,8 +59,6 @@ public override async Task Execute()
6159
var manager = serviceProvider.TryGetService<IGitHubToolWindowManager>();
6260
var host = await manager.ShowGitHubPane();
6361
await host.ShowPullRequest(session.RepositoryOwner, host.LocalRepository.Name, pullRequest.Number);
64-
65-
usageTracker.Value.IncrementCounter(x => x.NumberOfShowCurrentPullRequest).Forget();
6662
}
6763
catch (Exception ex)
6864
{

0 commit comments

Comments
 (0)