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

Commit 4c193c7

Browse files
author
Steven Kirk
committed
Increase usage count on appropriate operation.
1 parent 4e2c77c commit 4c193c7

File tree

8 files changed

+61
-24
lines changed

8 files changed

+61
-24
lines changed

src/GitHub.App/Services/UsageTracker.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ public class UsageTracker : IUsageTracker
2525
// Whenever you add a counter make sure it gets added to _both_
2626
// BuildUsageModel and ClearCounters
2727
const string GHLastSubmissionKey = "GHLastSubmission";
28-
const string GHCommitCountKey = "GHCommitCount";
2928
const string GHCreateCountKey = "GHCreateCountKey";
3029
const string GHCloneCountKey = "GHCloneCount";
3130
const string GHPublishCountKey = "GHPublishCountKey";
3231
const string GHGistCountKey = "GHPublishCountKey";
3332
const string GHOpenInGitHubCountKey = "GHOpenInGitHubCountKey";
3433
const string GHLinkToGitHubCountKey = "GHLinkToGitHubCountKey";
34+
const string GHUpstreamPullRequestCount = "GHUpstreamPullRequestCount";
3535
const string GHLoginCountKey = "GHLoginCountKey";
3636
const string GHLaunchCountKeyDay = "GHLaunchCountDay";
3737
const string GHLaunchCountKeyWeek = "GHLaunchCountWeek";
3838
const string GHLaunchCountKeyMonth = "GHLaunchCountMonth";
39-
const string GHUpstreamPullRequestCount = "GHUpstreamPullRequestCount";
4039

4140
static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
4241

@@ -132,15 +131,14 @@ IObservable<Unit> ClearCounters(bool weekly, bool monthly)
132131
{
133132
var standardCounters = new[] {
134133
GHLaunchCountKeyDay,
135-
GHUpstreamPullRequestCount,
136134
GHCloneCountKey,
137135
GHCreateCountKey,
138136
GHPublishCountKey,
139-
GHCommitCountKey,
140137
GHGistCountKey,
141138
GHOpenInGitHubCountKey,
142139
GHLinkToGitHubCountKey,
143140
GHLoginCountKey,
141+
GHUpstreamPullRequestCount,
144142
};
145143

146144
var counters = standardCounters
@@ -194,14 +192,14 @@ IObservable<UsageModel> BuildUsageModel(bool weekly, bool monthly)
194192
GetCounter(GHLaunchCountKeyDay).Do(x => model.NumberOfStartups = x),
195193
GetCounter(GHLaunchCountKeyWeek).Do(x => model.NumberOfStartupsWeek = x),
196194
GetCounter(GHLaunchCountKeyMonth).Do(x => model.NumberOfStartupsMonth = x),
197-
GetCounter(GHUpstreamPullRequestCount).Do(x => model.NumberOfUpstreamPullRequests = x),
198195
GetCounter(GHCloneCountKey).Do(x => model.NumberOfClones = x),
199196
GetCounter(GHCreateCountKey).Do(x => model.NumberOfReposCreated = x),
200197
GetCounter(GHPublishCountKey).Do(x => model.NumberOfReposPublished = x),
201198
GetCounter(GHGistCountKey).Do(x => model.NumberOfGists = x),
202199
GetCounter(GHOpenInGitHubCountKey).Do(x => model.NumberOfOpenInGitHub = x),
203200
GetCounter(GHLinkToGitHubCountKey).Do(x => model.NumberOfLinkToGitHub = x),
204201
GetCounter(GHLoginCountKey).Do(x => model.NumberOfLogins = x),
202+
GetCounter(GHUpstreamPullRequestCount).Do(x => model.NumberOfUpstreamPullRequests = x),
205203
};
206204

207205
if (weekly)
@@ -270,15 +268,15 @@ IObservable<int> IncrementCounter(string key)
270268
});
271269
}
272270

273-
public void IncrementCommitCount()
271+
public void IncrementCloneCount()
274272
{
275-
IncrementCounter(GHCommitCountKey)
273+
IncrementCounter(GHCloneCountKey)
276274
.Subscribe();
277275
}
278276

279-
public void IncrementCloneCount()
277+
public void IncrementCreateCount()
280278
{
281-
IncrementCounter(GHCloneCountKey)
279+
IncrementCounter(GHCreateCountKey)
282280
.Subscribe();
283281
}
284282

@@ -290,6 +288,24 @@ public void IncrementLaunchCount()
290288
.Subscribe();
291289
}
292290

291+
public void IncrementPublishCount()
292+
{
293+
IncrementCounter(GHPublishCountKey)
294+
.Subscribe();
295+
}
296+
297+
public void IncrementOpenInGitHubCount()
298+
{
299+
IncrementCounter(GHOpenInGitHubCountKey)
300+
.Subscribe();
301+
}
302+
303+
public void IncrementLinkToGitHubCount()
304+
{
305+
IncrementCounter(GHLinkToGitHubCountKey)
306+
.Subscribe();
307+
}
308+
293309
public void IncrementUpstreamPullRequestCount()
294310
{
295311
IncrementCounter(GHUpstreamPullRequestCount)

src/GitHub.App/ViewModels/RepositoryCloneViewModel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ IObservable<Unit> OnCloneRepository(object state)
134134
// The following is a noop if the directory already exists.
135135
operatingSystem.Directory.CreateDirectory(BaseRepositoryPath);
136136

137-
// Are we OK doing this here or should we be doing it after the clone succeeds?
138-
this.usageTracker.IncrementCloneCount();
139-
140-
return cloneService.CloneRepository(repository.CloneUrl, repository.Name, BaseRepositoryPath);
137+
return cloneService.CloneRepository(repository.CloneUrl, repository.Name, BaseRepositoryPath)
138+
.Do(_ => this.usageTracker.IncrementCloneCount());
141139
})
142140
.SelectMany(_ => _)
143141
.Catch<Unit, Exception>(e =>

src/GitHub.App/ViewModels/RepositoryCreationViewModel.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,29 @@ public class RepositoryCreationViewModel : RepositoryFormViewModel, IRepositoryC
3939
readonly ObservableAsPropertyHelper<bool> isCreating;
4040
readonly ObservableAsPropertyHelper<bool> canKeepPrivate;
4141
readonly IOperatingSystem operatingSystem;
42+
readonly IUsageTracker usageTracker;
4243

4344
[ImportingConstructor]
4445
RepositoryCreationViewModel(
4546
IConnectionRepositoryHostMap connectionRepositoryHostMap,
4647
IOperatingSystem operatingSystem,
4748
IRepositoryCreationService repositoryCreationService,
48-
IAvatarProvider avatarProvider)
49-
: this(connectionRepositoryHostMap.CurrentRepositoryHost, operatingSystem, repositoryCreationService, avatarProvider)
49+
IAvatarProvider avatarProvider,
50+
IUsageTracker usageTracker)
51+
: this(connectionRepositoryHostMap.CurrentRepositoryHost, operatingSystem, repositoryCreationService, avatarProvider, usageTracker)
5052
{}
5153

5254
public RepositoryCreationViewModel(
5355
IRepositoryHost repositoryHost,
5456
IOperatingSystem operatingSystem,
5557
IRepositoryCreationService repositoryCreationService,
56-
IAvatarProvider avatarProvider)
58+
IAvatarProvider avatarProvider,
59+
IUsageTracker usageTracker)
5760
{
5861
this.repositoryHost = repositoryHost;
5962
this.operatingSystem = operatingSystem;
6063
this.repositoryCreationService = repositoryCreationService;
64+
this.usageTracker = usageTracker;
6165

6266
Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, repositoryHost.Title);
6367
SelectedGitIgnoreTemplate = GitIgnoreItem.None;
@@ -278,7 +282,8 @@ IObservable<Unit> OnCreateRepository(object state)
278282
newRepository,
279283
SelectedAccount,
280284
BaseRepositoryPath,
281-
repositoryHost.ApiClient);
285+
repositoryHost.ApiClient)
286+
.Do(_ => usageTracker.IncrementCreateCount());
282287
}
283288

284289
ReactiveCommand<Unit> InitializeCreateRepositoryCommand()

src/GitHub.App/ViewModels/RepositoryPublishViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ public class RepositoryPublishViewModel : RepositoryFormViewModel, IRepositoryPu
3333
readonly ObservableAsPropertyHelper<bool> canKeepPrivate;
3434
readonly ObservableAsPropertyHelper<bool> isPublishing;
3535
readonly ObservableAsPropertyHelper<string> title;
36+
readonly IUsageTracker usageTracker;
3637

3738
[ImportingConstructor]
3839
public RepositoryPublishViewModel(
3940
IRepositoryHosts hosts,
4041
IRepositoryPublishService repositoryPublishService,
4142
INotificationService notificationService,
42-
IConnectionManager connectionManager)
43+
IConnectionManager connectionManager,
44+
IUsageTracker usageTracker)
4345
{
4446
this.notificationService = notificationService;
4547
this.hosts = hosts;
48+
this.usageTracker = usageTracker;
4649

4750
title = this.WhenAny(
4851
x => x.SelectedHost,
@@ -151,6 +154,7 @@ IObservable<ProgressState> OnPublishRepository(object arg)
151154
var account = SelectedAccount;
152155

153156
return repositoryPublishService.PublishRepository(newRepository, account, SelectedHost.ApiClient)
157+
.Do(_ => usageTracker.IncrementPublishCount())
154158
.Select(_ => ProgressState.Success)
155159
.Catch<ProgressState, Exception>(ex =>
156160
{

src/GitHub.Exports.Reactive/Services/IUsageTracker.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
{
33
public interface IUsageTracker
44
{
5-
void IncrementCloneCount();
6-
void IncrementCommitCount();
75
void IncrementLaunchCount();
6+
void IncrementCloneCount();
7+
void IncrementCreateCount();
8+
void IncrementPublishCount();
9+
void IncrementOpenInGitHubCount();
10+
void IncrementLinkToGitHubCount();
811
void IncrementUpstreamPullRequestCount();
912
}
1013
}

src/GitHub.VisualStudio/Menus/CopyLink.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ namespace GitHub.VisualStudio.Menus
1313
[PartCreationPolicy(CreationPolicy.Shared)]
1414
public class CopyLink : LinkMenuBase, IDynamicMenuHandler
1515
{
16+
readonly IUsageTracker usageTracker;
17+
1618
[ImportingConstructor]
17-
public CopyLink([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
19+
public CopyLink([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IUsageTracker usageTracker)
1820
: base(serviceProvider)
1921
{
22+
this.usageTracker = usageTracker;
2023
}
2124

2225
public Guid Guid => GuidList.guidContextMenuSet;
@@ -35,6 +38,7 @@ public void Activate([AllowNull]object data = null)
3538
Clipboard.SetText(link);
3639
var ns = ServiceProvider.GetExportedValue<IStatusBarNotificationService>();
3740
ns?.ShowMessage(Resources.LinkCopiedToClipboardMessage);
41+
this.usageTracker.IncrementLinkToGitHubCount();
3842
}
3943
catch
4044
{

src/GitHub.VisualStudio/Menus/OpenLink.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ namespace GitHub.VisualStudio.Menus
1111
[PartCreationPolicy(CreationPolicy.Shared)]
1212
public class OpenLink: LinkMenuBase, IDynamicMenuHandler
1313
{
14+
readonly IUsageTracker usageTracker;
15+
1416
[ImportingConstructor]
15-
public OpenLink([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
17+
public OpenLink([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IUsageTracker usageTracker)
1618
: base(serviceProvider)
1719
{
20+
this.usageTracker = usageTracker;
1821
}
1922

2023
public Guid Guid => GuidList.guidContextMenuSet;
@@ -30,6 +33,8 @@ public void Activate([AllowNull]object data = null)
3033
return;
3134
var browser = ServiceProvider.GetExportedValue<IVisualStudioBrowser>();
3235
browser?.OpenUrl(link.ToUri());
36+
37+
usageTracker.IncrementOpenInGitHubCount();
3338
}
3439

3540
public bool CanShow()

src/UnitTests/GitHub.App/ViewModels/RepositoryCreationViewModelTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ static IRepositoryCreationViewModel GetMeAViewModel(
3232
creationService = creationService ?? provider.GetRepositoryCreationService();
3333
var avatarProvider = provider.GetAvatarProvider();
3434
var connection = provider.GetConnection();
35+
var usageTracker = Substitute.For<IUsageTracker>();
3536

36-
return new RepositoryCreationViewModel(repositoryHost, os, creationService, avatarProvider);
37+
return new RepositoryCreationViewModel(repositoryHost, os, creationService, avatarProvider, usageTracker);
3738
}
3839

3940
public class TheSafeRepositoryNameProperty : TestBaseClass
@@ -334,7 +335,8 @@ public void IsPopulatedByTheRepositoryHost()
334335
repositoryHost,
335336
Substitute.For<IOperatingSystem>(),
336337
Substitute.For<IRepositoryCreationService>(),
337-
Substitute.For<IAvatarProvider>());
338+
Substitute.For<IAvatarProvider>(),
339+
Substitute.For<IUsageTracker>());
338340

339341
Assert.Equal(vm.Accounts[0], vm.SelectedAccount);
340342
Assert.Equal(2, vm.Accounts.Count);

0 commit comments

Comments
 (0)