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

Commit ac5a8f1

Browse files
author
Steven Kirk
committed
Track gist creation usage.
1 parent 7dff96e commit ac5a8f1

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/GitHub.App/Services/UsageTracker.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class UsageTracker : IUsageTracker
2828
const string GHCreateCountKey = "GHCreateCountKey";
2929
const string GHCloneCountKey = "GHCloneCount";
3030
const string GHPublishCountKey = "GHPublishCountKey";
31-
const string GHGistCountKey = "GHPublishCountKey";
31+
const string GHCreateGistCountKey = "GHCreateGistCountKey";
3232
const string GHOpenInGitHubCountKey = "GHOpenInGitHubCountKey";
3333
const string GHLinkToGitHubCountKey = "GHLinkToGitHubCountKey";
3434
const string GHUpstreamPullRequestCount = "GHUpstreamPullRequestCount";
@@ -134,7 +134,7 @@ IObservable<Unit> ClearCounters(bool weekly, bool monthly)
134134
GHCloneCountKey,
135135
GHCreateCountKey,
136136
GHPublishCountKey,
137-
GHGistCountKey,
137+
GHCreateGistCountKey,
138138
GHOpenInGitHubCountKey,
139139
GHLinkToGitHubCountKey,
140140
GHLoginCountKey,
@@ -195,7 +195,7 @@ IObservable<UsageModel> BuildUsageModel(bool weekly, bool monthly)
195195
GetCounter(GHCloneCountKey).Do(x => model.NumberOfClones = x),
196196
GetCounter(GHCreateCountKey).Do(x => model.NumberOfReposCreated = x),
197197
GetCounter(GHPublishCountKey).Do(x => model.NumberOfReposPublished = x),
198-
GetCounter(GHGistCountKey).Do(x => model.NumberOfGists = x),
198+
GetCounter(GHCreateGistCountKey).Do(x => model.NumberOfGists = x),
199199
GetCounter(GHOpenInGitHubCountKey).Do(x => model.NumberOfOpenInGitHub = x),
200200
GetCounter(GHLinkToGitHubCountKey).Do(x => model.NumberOfLinkToGitHub = x),
201201
GetCounter(GHLoginCountKey).Do(x => model.NumberOfLogins = x),
@@ -306,6 +306,12 @@ public void IncrementLinkToGitHubCount()
306306
.Subscribe();
307307
}
308308

309+
public void IncrementCreateGistCount()
310+
{
311+
IncrementCounter(GHCreateGistCountKey)
312+
.Subscribe();
313+
}
314+
309315
public void IncrementUpstreamPullRequestCount()
310316
{
311317
IncrementCounter(GHUpstreamPullRequestCount)

src/GitHub.App/ViewModels/GistCreationViewModel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,30 @@ public class GistCreationViewModel : BaseViewModel, IGistCreationViewModel
2525
readonly ObservableAsPropertyHelper<IAccount> account;
2626
readonly IGistPublishService gistPublishService;
2727
readonly INotificationService notificationService;
28+
readonly IUsageTracker usageTracker;
2829

2930
[ImportingConstructor]
3031
GistCreationViewModel(
3132
IConnectionRepositoryHostMap connectionRepositoryHostMap,
3233
ISelectedTextProvider selectedTextProvider,
3334
IGistPublishService gistPublishService,
34-
INotificationService notificationService)
35-
: this(connectionRepositoryHostMap.CurrentRepositoryHost, selectedTextProvider, gistPublishService)
35+
INotificationService notificationService,
36+
IUsageTracker usageTracker)
37+
: this(connectionRepositoryHostMap.CurrentRepositoryHost, selectedTextProvider, gistPublishService, usageTracker)
3638
{
3739
this.notificationService = notificationService;
3840
}
3941

4042
public GistCreationViewModel(
4143
IRepositoryHost repositoryHost,
4244
ISelectedTextProvider selectedTextProvider,
43-
IGistPublishService gistPublishService)
45+
IGistPublishService gistPublishService,
46+
IUsageTracker usageTracker)
4447
{
4548
Title = Resources.CreateGistTitle;
4649
apiClient = repositoryHost.ApiClient;
4750
this.gistPublishService = gistPublishService;
51+
this.usageTracker = usageTracker;
4852

4953
FileName = VisualStudio.Services.GetFileNameFromActiveDocument() ?? Resources.DefaultGistFileName;
5054
SelectedText = selectedTextProvider.GetSelectedText();
@@ -74,6 +78,7 @@ IObservable<Gist> OnCreateGist(object unused)
7478
newGist.Files.Add(FileName, SelectedText);
7579

7680
return gistPublishService.PublishGist(apiClient, newGist)
81+
.Do(_ => usageTracker.IncrementCreateGistCount())
7782
.Catch<Gist, Exception>(ex =>
7883
{
7984
if (!ex.IsCriticalException())

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IUsageTracker
88
void IncrementPublishCount();
99
void IncrementOpenInGitHubCount();
1010
void IncrementLinkToGitHubCount();
11+
void IncrementCreateGistCount();
1112
void IncrementUpstreamPullRequestCount();
1213
}
1314
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static IGistCreationViewModel CreateViewModel(IServiceProvider provider, string
2424
var accounts = new ReactiveList<IAccount>() { Substitute.For<IAccount>(), Substitute.For<IAccount>() };
2525
repositoryHost.ModelService.GetAccounts().Returns(Observable.Return(accounts));
2626
var gistPublishService = provider.GetGistPublishService();
27-
return new GistCreationViewModel(repositoryHost, selectedTextProvider, gistPublishService)
27+
return new GistCreationViewModel(repositoryHost, selectedTextProvider, gistPublishService, Substitute.For<IUsageTracker>())
2828
{
2929
FileName = fileName,
3030
IsPrivate = isPrivate

0 commit comments

Comments
 (0)