forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats-store.ts
1509 lines (1318 loc) · 46.1 KB
/
stats-store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { StatsDatabase, ILaunchStats, IDailyMeasures } from './stats-database'
import { getDotComAPIEndpoint } from '../api'
import { getVersion } from '../../ui/lib/app-proxy'
import { hasShownWelcomeFlow } from '../welcome'
import { Account } from '../../models/account'
import { getOS } from '../get-os'
import { getGUID } from './get-guid'
import { Repository } from '../../models/repository'
import { merge } from '../../lib/merge'
import { getPersistedThemeName } from '../../ui/lib/application-theme'
import { IUiActivityMonitor } from '../../ui/lib/ui-activity-monitor'
import { Disposable } from 'event-kit'
import { SignInMethod } from '../stores'
import { assertNever } from '../fatal-error'
import {
getNumber,
setNumber,
getBoolean,
setBoolean,
getNumberArray,
setNumberArray,
} from '../local-storage'
import { PushOptions } from '../git'
const StatsEndpoint = 'https://central.github.com/api/usage/desktop'
/** The URL to the stats samples page. */
export const SamplesURL = 'https://desktop.github.com/usage-data/'
const LastDailyStatsReportKey = 'last-daily-stats-report'
/** The localStorage key for whether the user has opted out. */
const StatsOptOutKey = 'stats-opt-out'
/** Have we successfully sent the stats opt-in? */
const HasSentOptInPingKey = 'has-sent-stats-opt-in-ping'
const WelcomeWizardInitiatedAtKey = 'welcome-wizard-initiated-at'
const WelcomeWizardCompletedAtKey = 'welcome-wizard-terminated-at'
const FirstRepositoryAddedAtKey = 'first-repository-added-at'
const FirstRepositoryClonedAtKey = 'first-repository-cloned-at'
const FirstRepositoryCreatedAtKey = 'first-repository-created-at'
const FirstCommitCreatedAtKey = 'first-commit-created-at'
const FirstPushToGitHubAtKey = 'first-push-to-github-at'
const FirstNonDefaultBranchCheckoutAtKey =
'first-non-default-branch-checkout-at'
const WelcomeWizardSignInMethodKey = 'welcome-wizard-sign-in-method'
const terminalEmulatorKey = 'shell'
const textEditorKey: string = 'externalEditor'
const RepositoriesCommittedInWithoutWriteAccessKey =
'repositories-committed-in-without-write-access'
/** How often daily stats should be submitted (i.e., 24 hours). */
const DailyStatsReportInterval = 1000 * 60 * 60 * 24
const DefaultDailyMeasures: IDailyMeasures = {
commits: 0,
partialCommits: 0,
openShellCount: 0,
coAuthoredCommits: 0,
branchComparisons: 0,
defaultBranchComparisons: 0,
mergesInitiatedFromComparison: 0,
updateFromDefaultBranchMenuCount: 0,
mergeIntoCurrentBranchMenuCount: 0,
prBranchCheckouts: 0,
repoWithIndicatorClicked: 0,
repoWithoutIndicatorClicked: 0,
divergingBranchBannerDismissal: 0,
divergingBranchBannerInitatedMerge: 0,
divergingBranchBannerInitiatedCompare: 0,
divergingBranchBannerInfluencedMerge: 0,
divergingBranchBannerDisplayed: 0,
dotcomPushCount: 0,
dotcomForcePushCount: 0,
enterprisePushCount: 0,
enterpriseForcePushCount: 0,
externalPushCount: 0,
externalForcePushCount: 0,
active: false,
mergeConflictFromPullCount: 0,
mergeConflictFromExplicitMergeCount: 0,
mergedWithLoadingHintCount: 0,
mergedWithCleanMergeHintCount: 0,
mergedWithConflictWarningHintCount: 0,
mergeSuccessAfterConflictsCount: 0,
mergeAbortedAfterConflictsCount: 0,
unattributedCommits: 0,
enterpriseCommits: 0,
dotcomCommits: 0,
mergeConflictsDialogDismissalCount: 0,
anyConflictsLeftOnMergeConflictsDialogDismissalCount: 0,
mergeConflictsDialogReopenedCount: 0,
guidedConflictedMergeCompletionCount: 0,
unguidedConflictedMergeCompletionCount: 0,
createPullRequestCount: 0,
rebaseConflictsDialogDismissalCount: 0,
rebaseConflictsDialogReopenedCount: 0,
rebaseAbortedAfterConflictsCount: 0,
rebaseSuccessAfterConflictsCount: 0,
rebaseSuccessWithoutConflictsCount: 0,
pullWithRebaseCount: 0,
pullWithDefaultSettingCount: 0,
stashEntriesCreatedOutsideDesktop: 0,
errorWhenSwitchingBranchesWithUncommmittedChanges: 0,
rebaseCurrentBranchMenuCount: 0,
stashViewedAfterCheckoutCount: 0,
stashCreatedOnCurrentBranchCount: 0,
stashNotViewedAfterCheckoutCount: 0,
changesTakenToNewBranchCount: 0,
stashRestoreCount: 0,
stashDiscardCount: 0,
stashViewCount: 0,
noActionTakenOnStashCount: 0,
suggestedStepOpenInExternalEditor: 0,
suggestedStepOpenWorkingDirectory: 0,
suggestedStepViewOnGitHub: 0,
suggestedStepPublishRepository: 0,
suggestedStepPublishBranch: 0,
suggestedStepCreatePullRequest: 0,
suggestedStepViewStash: 0,
commitsToProtectedBranch: 0,
commitsToRepositoryWithBranchProtections: 0,
tutorialStarted: false,
tutorialRepoCreated: false,
tutorialEditorInstalled: false,
tutorialBranchCreated: false,
tutorialFileEdited: false,
tutorialCommitCreated: false,
tutorialBranchPushed: false,
tutorialPrCreated: false,
tutorialCompleted: false,
// this is `-1` because `0` signifies "tutorial created"
highestTutorialStepCompleted: -1,
commitsToRepositoryWithoutWriteAccess: 0,
forksCreated: 0,
issueCreationWebpageOpenedCount: 0,
tagsCreatedInDesktop: 0,
tagsCreated: 0,
tagsDeleted: 0,
}
interface IOnboardingStats {
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user added their first existing repository.
*
* A negative value means that this action hasn't yet
* taken place while undefined means that the current
* user installed desktop prior to this metric beeing
* added and we will thus never be able to provide a
* value.
*/
readonly timeToFirstAddedRepository?: number
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user cloned their first repository.
*
* A negative value means that this action hasn't yet
* taken place while undefined means that the current
* user installed desktop prior to this metric beeing
* added and we will thus never be able to provide a
* value.
*/
readonly timeToFirstClonedRepository?: number
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user created their first new repository.
*
* A negative value means that this action hasn't yet
* taken place while undefined means that the current
* user installed desktop prior to this metric beeing
* added and we will thus never be able to provide a
* value.
*/
readonly timeToFirstCreatedRepository?: number
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user crafted their first commit.
*
* A negative value means that this action hasn't yet
* taken place while undefined means that the current
* user installed desktop prior to this metric beeing
* added and we will thus never be able to provide a
* value.
*/
readonly timeToFirstCommit?: number
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user performed their first push of a repository
* to GitHub.com or GitHub Enterprise Server. This metric
* does not track pushes to non-GitHub remotes.
*/
readonly timeToFirstGitHubPush?: number
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user first checked out a branch in any repository
* which is not the default branch of that repository.
*
* Note that this metric will be set regardless of whether
* that repository was a GitHub.com/GHE repository, local
* repository or has a non-GitHub remote.
*
* A negative value means that this action hasn't yet
* taken place while undefined means that the current
* user installed desktop prior to this metric beeing
* added and we will thus never be able to provide a
* value.
*/
readonly timeToFirstNonDefaultBranchCheckout?: number
/**
* Time (in seconds) from when the user first launched
* the application and entered the welcome wizard until
* the user completed the wizard.
*
* A negative value means that this action hasn't yet
* taken place while undefined means that the current
* user installed desktop prior to this metric beeing
* added and we will thus never be able to provide a
* value.
*/
readonly timeToWelcomeWizardTerminated?: number
/**
* The method that was used when authenticating a
* user in the welcome flow. If multiple succesful
* authentications happened during the welcome flow
* due to the user stepping back and signing in to
* another account this will reflect the last one.
*/
readonly welcomeWizardSignInMethod?: 'basic' | 'web'
}
/**
* Returns the account id of the current user's GitHub.com account or null if the user
* is not currently signed in to GitHub.com.
*
* @param accounts The active accounts stored in Desktop
*/
function findDotComAccountId(accounts: ReadonlyArray<Account>): number | null {
const gitHubAccount = accounts.find(
a => a.endpoint === getDotComAPIEndpoint()
)
return gitHubAccount !== undefined ? gitHubAccount.id : null
}
interface ICalculatedStats {
/** The app version. */
readonly version: string
/** The OS version. */
readonly osVersion: string
/** The platform. */
readonly platform: string
/** The number of total repositories. */
readonly repositoryCount: number
/** The number of GitHub repositories. */
readonly gitHubRepositoryCount: number
/** The install ID. */
readonly guid: string
/** Is the user logged in with a GitHub.com account? */
readonly dotComAccount: boolean
/** Is the user logged in with an Enterprise Server account? */
readonly enterpriseAccount: boolean
/**
* The name of the currently selected theme/application
* appearance as set at time of stats submission.
*/
readonly theme: string
/** The selected terminal emulator at the time of stats submission */
readonly selectedTerminalEmulator: string
/** The selected text editor at the time of stats submission */
readonly selectedTextEditor: string
readonly eventType: 'usage'
/**
* _[Forks]_
* How many repos did the user commit in without having `write` access?
*
* This is a hack in that its really a "computed daily measure" and the
* moment we have another one of those we should consider refactoring
* them into their own interface
*/
readonly repositoriesCommittedInWithoutWriteAccess: number
}
type DailyStats = ICalculatedStats &
ILaunchStats &
IDailyMeasures &
IOnboardingStats
/**
* Testable interface for StatsStore
*
* Note: for the moment this only contains methods that are needed for testing,
* so fight the urge to implement every public method from StatsStore here
*
*/
export interface IStatsStore {
recordMergeAbortedAfterConflicts: () => void
recordMergeSuccessAfterConflicts: () => void
recordRebaseAbortedAfterConflicts: () => void
recordRebaseSuccessAfterConflicts: () => void
}
/** The store for the app's stats. */
export class StatsStore implements IStatsStore {
private readonly db: StatsDatabase
private readonly uiActivityMonitor: IUiActivityMonitor
private uiActivityMonitorSubscription: Disposable | null = null
/** Has the user opted out of stats reporting? */
private optOut: boolean
public constructor(db: StatsDatabase, uiActivityMonitor: IUiActivityMonitor) {
this.db = db
this.uiActivityMonitor = uiActivityMonitor
const storedValue = getBoolean(StatsOptOutKey)
this.optOut = storedValue || false
// If the user has set an opt out value but we haven't sent the ping yet,
// give it a shot now.
if (!getBoolean(HasSentOptInPingKey, false)) {
this.sendOptInStatusPing(this.optOut, storedValue)
}
this.enableUiActivityMonitoring()
}
/** Should the app report its daily stats? */
private shouldReportDailyStats(): boolean {
const lastDate = getNumber(LastDailyStatsReportKey, 0)
const now = Date.now()
return now - lastDate > DailyStatsReportInterval
}
/** Report any stats which are eligible for reporting. */
public async reportStats(
accounts: ReadonlyArray<Account>,
repositories: ReadonlyArray<Repository>
) {
if (this.optOut) {
return
}
// Never report stats while in dev or test. They could be pretty crazy.
if (__DEV__ || process.env.TEST_ENV) {
return
}
// don't report until the user has had a chance to view and opt-in for
// sharing their stats with us
if (!hasShownWelcomeFlow()) {
return
}
if (!this.shouldReportDailyStats()) {
return
}
const now = Date.now()
const stats = await this.getDailyStats(accounts, repositories)
const user_id = findDotComAccountId(accounts)
const payload = user_id === null ? stats : { ...stats, user_id }
try {
const response = await this.post(payload)
if (!response.ok) {
throw new Error(
`Unexpected status: ${response.statusText} (${response.status})`
)
}
log.info('Stats reported.')
await this.clearDailyStats()
setNumber(LastDailyStatsReportKey, now)
} catch (e) {
log.error('Error reporting stats:', e)
}
}
/** Record the given launch stats. */
public async recordLaunchStats(stats: ILaunchStats) {
await this.db.launches.add(stats)
}
/**
* Clear the stored daily stats. Not meant to be called
* directly. Marked as public in order to enable testing
* of a specific scenario, see stats-store-tests for more
* detail.
*/
public async clearDailyStats() {
await this.db.launches.clear()
await this.db.dailyMeasures.clear()
// This is a one-off, and the moment we have another
// computed daily measure we should consider refactoring
// them into their own interface
localStorage.removeItem(RepositoriesCommittedInWithoutWriteAccessKey)
this.enableUiActivityMonitoring()
}
private enableUiActivityMonitoring() {
if (this.uiActivityMonitorSubscription !== null) {
return
}
this.uiActivityMonitorSubscription = this.uiActivityMonitor.onActivity(
this.onUiActivity
)
}
private disableUiActivityMonitoring() {
if (this.uiActivityMonitorSubscription === null) {
return
}
this.uiActivityMonitorSubscription.dispose()
this.uiActivityMonitorSubscription = null
}
/** Get the daily stats. */
private async getDailyStats(
accounts: ReadonlyArray<Account>,
repositories: ReadonlyArray<Repository>
): Promise<DailyStats> {
const launchStats = await this.getAverageLaunchStats()
const dailyMeasures = await this.getDailyMeasures()
const userType = this.determineUserType(accounts)
const repositoryCounts = this.categorizedRepositoryCounts(repositories)
const onboardingStats = this.getOnboardingStats()
const selectedTerminalEmulator =
localStorage.getItem(terminalEmulatorKey) || 'none'
const selectedTextEditor = localStorage.getItem(textEditorKey) || 'none'
const repositoriesCommittedInWithoutWriteAccess = getNumberArray(
RepositoriesCommittedInWithoutWriteAccessKey
).length
return {
eventType: 'usage',
version: getVersion(),
osVersion: getOS(),
platform: process.platform,
theme: getPersistedThemeName(),
selectedTerminalEmulator,
selectedTextEditor,
...launchStats,
...dailyMeasures,
...userType,
...onboardingStats,
guid: getGUID(),
...repositoryCounts,
repositoriesCommittedInWithoutWriteAccess,
}
}
private getOnboardingStats(): IOnboardingStats {
const wizardInitiatedAt = getLocalStorageTimestamp(
WelcomeWizardInitiatedAtKey
)
// If we don't have a start time for the wizard none of our other metrics
// makes sense. This will happen for users who installed the app before
// we started tracking onboarding stats.
if (wizardInitiatedAt === null) {
return {}
}
const timeToWelcomeWizardTerminated = timeTo(WelcomeWizardCompletedAtKey)
const timeToFirstAddedRepository = timeTo(FirstRepositoryAddedAtKey)
const timeToFirstClonedRepository = timeTo(FirstRepositoryClonedAtKey)
const timeToFirstCreatedRepository = timeTo(FirstRepositoryCreatedAtKey)
const timeToFirstCommit = timeTo(FirstCommitCreatedAtKey)
const timeToFirstGitHubPush = timeTo(FirstPushToGitHubAtKey)
const timeToFirstNonDefaultBranchCheckout = timeTo(
FirstNonDefaultBranchCheckoutAtKey
)
const welcomeWizardSignInMethod = getWelcomeWizardSignInMethod()
return {
timeToWelcomeWizardTerminated,
timeToFirstAddedRepository,
timeToFirstClonedRepository,
timeToFirstCreatedRepository,
timeToFirstCommit,
timeToFirstGitHubPush,
timeToFirstNonDefaultBranchCheckout,
welcomeWizardSignInMethod,
}
}
private categorizedRepositoryCounts(repositories: ReadonlyArray<Repository>) {
return {
repositoryCount: repositories.length,
gitHubRepositoryCount: repositories.filter(r => r.gitHubRepository)
.length,
}
}
/** Determines if an account is a dotCom and/or enterprise user */
private determineUserType(accounts: ReadonlyArray<Account>) {
const dotComAccount = !!accounts.find(
a => a.endpoint === getDotComAPIEndpoint()
)
const enterpriseAccount = !!accounts.find(
a => a.endpoint !== getDotComAPIEndpoint()
)
return {
dotComAccount,
enterpriseAccount,
}
}
/** Calculate the average launch stats. */
private async getAverageLaunchStats(): Promise<ILaunchStats> {
const launches:
| ReadonlyArray<ILaunchStats>
| undefined = await this.db.launches.toArray()
if (!launches || !launches.length) {
return {
mainReadyTime: -1,
loadTime: -1,
rendererReadyTime: -1,
}
}
const start: ILaunchStats = {
mainReadyTime: 0,
loadTime: 0,
rendererReadyTime: 0,
}
const totals = launches.reduce((running, current) => {
return {
mainReadyTime: running.mainReadyTime + current.mainReadyTime,
loadTime: running.loadTime + current.loadTime,
rendererReadyTime:
running.rendererReadyTime + current.rendererReadyTime,
}
}, start)
return {
mainReadyTime: totals.mainReadyTime / launches.length,
loadTime: totals.loadTime / launches.length,
rendererReadyTime: totals.rendererReadyTime / launches.length,
}
}
/** Get the daily measures. */
private async getDailyMeasures(): Promise<IDailyMeasures> {
const measures:
| IDailyMeasures
| undefined = await this.db.dailyMeasures.limit(1).first()
return {
...DefaultDailyMeasures,
...measures,
// We could spread the database ID in, but we really don't want it.
id: undefined,
}
}
private async updateDailyMeasures<K extends keyof IDailyMeasures>(
fn: (measures: IDailyMeasures) => Pick<IDailyMeasures, K>
): Promise<void> {
const defaultMeasures = DefaultDailyMeasures
await this.db.transaction('rw', this.db.dailyMeasures, async () => {
const measures = await this.db.dailyMeasures.limit(1).first()
const measuresWithDefaults = {
...defaultMeasures,
...measures,
}
const newMeasures = merge(measuresWithDefaults, fn(measuresWithDefaults))
return this.db.dailyMeasures.put(newMeasures)
})
}
/** Record that a commit was accomplished. */
public async recordCommit(): Promise<void> {
await this.updateDailyMeasures(m => ({
commits: m.commits + 1,
}))
createLocalStorageTimestamp(FirstCommitCreatedAtKey)
}
/** Record that a partial commit was accomplished. */
public recordPartialCommit(): Promise<void> {
return this.updateDailyMeasures(m => ({
partialCommits: m.partialCommits + 1,
}))
}
/** Record that a commit was created with one or more co-authors. */
public recordCoAuthoredCommit(): Promise<void> {
return this.updateDailyMeasures(m => ({
coAuthoredCommits: m.coAuthoredCommits + 1,
}))
}
/** Record that the user opened a shell. */
public recordOpenShell(): Promise<void> {
return this.updateDailyMeasures(m => ({
openShellCount: m.openShellCount + 1,
}))
}
/** Record that a branch comparison has been made */
public recordBranchComparison(): Promise<void> {
return this.updateDailyMeasures(m => ({
branchComparisons: m.branchComparisons + 1,
}))
}
/** Record that a branch comparison has been made to the `master` branch */
public recordDefaultBranchComparison(): Promise<void> {
return this.updateDailyMeasures(m => ({
defaultBranchComparisons: m.defaultBranchComparisons + 1,
}))
}
/** Record that a merge has been initiated from the `compare` sidebar */
public recordCompareInitiatedMerge(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergesInitiatedFromComparison: m.mergesInitiatedFromComparison + 1,
}))
}
/** Record that a merge has been initiated from the `Branch -> Update From Default Branch` menu item */
public recordMenuInitiatedUpdate(): Promise<void> {
return this.updateDailyMeasures(m => ({
updateFromDefaultBranchMenuCount: m.updateFromDefaultBranchMenuCount + 1,
}))
}
/** Record that conflicts were detected by a merge initiated by Desktop */
public recordMergeConflictFromPull(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergeConflictFromPullCount: m.mergeConflictFromPullCount + 1,
}))
}
/** Record that conflicts were detected by a merge initiated by Desktop */
public recordMergeConflictFromExplicitMerge(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergeConflictFromExplicitMergeCount:
m.mergeConflictFromExplicitMergeCount + 1,
}))
}
/** Record that a merge has been initiated from the `Branch -> Merge Into Current Branch` menu item */
public recordMenuInitiatedMerge(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergeIntoCurrentBranchMenuCount: m.mergeIntoCurrentBranchMenuCount + 1,
}))
}
public recordMenuInitiatedRebase(): Promise<void> {
return this.updateDailyMeasures(m => ({
rebaseCurrentBranchMenuCount: m.rebaseCurrentBranchMenuCount + 1,
}))
}
/** Record that the user checked out a PR branch */
public recordPRBranchCheckout(): Promise<void> {
return this.updateDailyMeasures(m => ({
prBranchCheckouts: m.prBranchCheckouts + 1,
}))
}
public recordRepoClicked(repoHasIndicator: boolean): Promise<void> {
if (repoHasIndicator) {
return this.updateDailyMeasures(m => ({
repoWithIndicatorClicked: m.repoWithIndicatorClicked + 1,
}))
}
return this.updateDailyMeasures(m => ({
repoWithoutIndicatorClicked: m.repoWithoutIndicatorClicked + 1,
}))
}
/**
* Records that the user made a commit using an email address that
* was not associated with the user's account on GitHub.com or GitHub
* Enterprise Server, meaning that the commit will not be attributed to the
* user's account.
*/
public recordUnattributedCommit(): Promise<void> {
return this.updateDailyMeasures(m => ({
unattributedCommits: m.unattributedCommits + 1,
}))
}
/**
* Records that the user made a commit to a repository hosted on
* a GitHub Enterprise Server instance
*/
public recordCommitToEnterprise(): Promise<void> {
return this.updateDailyMeasures(m => ({
enterpriseCommits: m.enterpriseCommits + 1,
}))
}
/** Records that the user made a commit to a repository hosted on GitHub.com */
public recordCommitToDotcom(): Promise<void> {
return this.updateDailyMeasures(m => ({
dotcomCommits: m.dotcomCommits + 1,
}))
}
/** Record the user made a commit to a protected GitHub or GitHub Enterprise Server repository */
public recordCommitToProtectedBranch(): Promise<void> {
return this.updateDailyMeasures(m => ({
commitsToProtectedBranch: m.commitsToProtectedBranch + 1,
}))
}
/** Record the user made a commit to repository which has branch protections enabled */
public recordCommitToRepositoryWithBranchProtections(): Promise<void> {
return this.updateDailyMeasures(m => ({
commitsToRepositoryWithBranchProtections:
m.commitsToRepositoryWithBranchProtections + 1,
}))
}
/** Set whether the user has opted out of stats reporting. */
public async setOptOut(
optOut: boolean,
userViewedPrompt: boolean
): Promise<void> {
const changed = this.optOut !== optOut
this.optOut = optOut
const previousValue = getBoolean(StatsOptOutKey)
setBoolean(StatsOptOutKey, optOut)
if (changed || userViewedPrompt) {
await this.sendOptInStatusPing(optOut, previousValue)
}
}
/** Has the user opted out of stats reporting? */
public getOptOut(): boolean {
return this.optOut
}
/** Record that user dismissed diverging branch notification */
public recordDivergingBranchBannerDismissal(): Promise<void> {
return this.updateDailyMeasures(m => ({
divergingBranchBannerDismissal: m.divergingBranchBannerDismissal + 1,
}))
}
/** Record that user initiated a merge from within the notification banner */
public recordDivergingBranchBannerInitatedMerge(): Promise<void> {
return this.updateDailyMeasures(m => ({
divergingBranchBannerInitatedMerge:
m.divergingBranchBannerInitatedMerge + 1,
}))
}
/** Record that user initiated a compare from within the notification banner */
public recordDivergingBranchBannerInitiatedCompare(): Promise<void> {
return this.updateDailyMeasures(m => ({
divergingBranchBannerInitiatedCompare:
m.divergingBranchBannerInitiatedCompare + 1,
}))
}
/**
* Record that user initiated a merge after getting to compare view
* from within notification banner
*/
public recordDivergingBranchBannerInfluencedMerge(): Promise<void> {
return this.updateDailyMeasures(m => ({
divergingBranchBannerInfluencedMerge:
m.divergingBranchBannerInfluencedMerge + 1,
}))
}
/** Record that the user was shown the notification banner */
public recordDivergingBranchBannerDisplayed(): Promise<void> {
return this.updateDailyMeasures(m => ({
divergingBranchBannerDisplayed: m.divergingBranchBannerDisplayed + 1,
}))
}
public async recordPush(
githubAccount: Account | null,
options?: PushOptions
) {
if (githubAccount === null) {
await this.recordPushToGenericRemote(options)
} else if (githubAccount.endpoint === getDotComAPIEndpoint()) {
await this.recordPushToGitHub(options)
} else {
await this.recordPushToGitHubEnterprise(options)
}
}
/** Record that the user pushed to GitHub.com */
private async recordPushToGitHub(options?: PushOptions): Promise<void> {
if (options && options.forceWithLease) {
await this.updateDailyMeasures(m => ({
dotcomForcePushCount: m.dotcomForcePushCount + 1,
}))
}
await this.updateDailyMeasures(m => ({
dotcomPushCount: m.dotcomPushCount + 1,
}))
createLocalStorageTimestamp(FirstPushToGitHubAtKey)
}
/** Record that the user pushed to a GitHub Enterprise Server instance */
private async recordPushToGitHubEnterprise(
options?: PushOptions
): Promise<void> {
if (options && options.forceWithLease) {
await this.updateDailyMeasures(m => ({
enterpriseForcePushCount: m.enterpriseForcePushCount + 1,
}))
}
await this.updateDailyMeasures(m => ({
enterprisePushCount: m.enterprisePushCount + 1,
}))
// Note, this is not a typo. We track both GitHub.com and
// GitHub Enteprise under the same key
createLocalStorageTimestamp(FirstPushToGitHubAtKey)
}
/** Record that the user pushed to a generic remote */
private async recordPushToGenericRemote(
options?: PushOptions
): Promise<void> {
if (options && options.forceWithLease) {
await this.updateDailyMeasures(m => ({
externalForcePushCount: m.externalForcePushCount + 1,
}))
}
await this.updateDailyMeasures(m => ({
externalPushCount: m.externalPushCount + 1,
}))
}
/** Record that the user saw a 'merge conflicts' warning but continued with the merge */
public recordUserProceededWhileLoading(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergedWithLoadingHintCount: m.mergedWithLoadingHintCount + 1,
}))
}
/** Record that the user saw a 'merge conflicts' warning but continued with the merge */
public recordMergeHintSuccessAndUserProceeded(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergedWithCleanMergeHintCount: m.mergedWithCleanMergeHintCount + 1,
}))
}
/** Record that the user saw a 'merge conflicts' warning but continued with the merge */
public recordUserProceededAfterConflictWarning(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergedWithConflictWarningHintCount:
m.mergedWithConflictWarningHintCount + 1,
}))
}
/**
* Increments the `mergeConflictsDialogDismissalCount` metric
*/
public recordMergeConflictsDialogDismissal(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergeConflictsDialogDismissalCount:
m.mergeConflictsDialogDismissalCount + 1,
}))
}
/**
* Increments the `anyConflictsLeftOnMergeConflictsDialogDismissalCount` metric
*/
public recordAnyConflictsLeftOnMergeConflictsDialogDismissal(): Promise<
void
> {
return this.updateDailyMeasures(m => ({
anyConflictsLeftOnMergeConflictsDialogDismissalCount:
m.anyConflictsLeftOnMergeConflictsDialogDismissalCount + 1,
}))
}
/**
* Increments the `mergeConflictsDialogReopenedCount` metric
*/
public recordMergeConflictsDialogReopened(): Promise<void> {
return this.updateDailyMeasures(m => ({
mergeConflictsDialogReopenedCount:
m.mergeConflictsDialogReopenedCount + 1,
}))
}
/**
* Increments the `guidedConflictedMergeCompletionCount` metric
*/
public recordGuidedConflictedMergeCompletion(): Promise<void> {
return this.updateDailyMeasures(m => ({
guidedConflictedMergeCompletionCount:
m.guidedConflictedMergeCompletionCount + 1,
}))
}
/**
* Increments the `unguidedConflictedMergeCompletionCount` metric
*/
public recordUnguidedConflictedMergeCompletion(): Promise<void> {
return this.updateDailyMeasures(m => ({
unguidedConflictedMergeCompletionCount:
m.unguidedConflictedMergeCompletionCount + 1,
}))
}
/**
* Increments the `createPullRequestCount` metric
*/
public recordCreatePullRequest(): Promise<void> {
return this.updateDailyMeasures(m => ({
createPullRequestCount: m.createPullRequestCount + 1,
}))
}
/**
* Increments the `rebaseConflictsDialogDismissalCount` metric
*/
public recordRebaseConflictsDialogDismissal(): Promise<void> {
return this.updateDailyMeasures(m => ({
rebaseConflictsDialogDismissalCount:
m.rebaseConflictsDialogDismissalCount + 1,
}))
}
/**
* Increments the `rebaseConflictsDialogReopenedCount` metric
*/
public recordRebaseConflictsDialogReopened(): Promise<void> {
return this.updateDailyMeasures(m => ({
rebaseConflictsDialogReopenedCount:
m.rebaseConflictsDialogReopenedCount + 1,
}))
}
/**
* Increments the `rebaseAbortedAfterConflictsCount` metric
*/
public recordRebaseAbortedAfterConflicts(): Promise<void> {
return this.updateDailyMeasures(m => ({
rebaseAbortedAfterConflictsCount: m.rebaseAbortedAfterConflictsCount + 1,
}))
}
/**
* Increments the `pullWithRebaseCount` metric
*/
public recordPullWithRebaseEnabled() {
return this.updateDailyMeasures(m => ({
pullWithRebaseCount: m.pullWithRebaseCount + 1,