@@ -8,6 +8,7 @@ import { Repository as GitHubRepository, RepositoryRuleset } from '@octokit/grap
8
8
import { AuthenticationError , getOctokitGraphql } from './auth' ;
9
9
import { API , BranchProtection , BranchProtectionProvider , BranchProtectionRule , Repository } from './typings/git' ;
10
10
import { DisposableStore , getRepositoryFromUrl } from './util' ;
11
+ import TelemetryReporter from '@vscode/extension-telemetry' ;
11
12
12
13
const REPOSITORY_QUERY = `
13
14
query repositoryPermissions($owner: String!, $repo: String!) {
@@ -60,7 +61,7 @@ export class GithubBranchProtectionProviderManager {
60
61
61
62
if ( enabled ) {
62
63
for ( const repository of this . gitAPI . repositories ) {
63
- this . providerDisposables . add ( this . gitAPI . registerBranchProtectionProvider ( repository . rootUri , new GithubBranchProtectionProvider ( repository , this . globalState , this . logger ) ) ) ;
64
+ this . providerDisposables . add ( this . gitAPI . registerBranchProtectionProvider ( repository . rootUri , new GithubBranchProtectionProvider ( repository , this . globalState , this . logger , this . telemetryReporter ) ) ) ;
64
65
}
65
66
} else {
66
67
this . providerDisposables . dispose ( ) ;
@@ -72,10 +73,11 @@ export class GithubBranchProtectionProviderManager {
72
73
constructor (
73
74
private readonly gitAPI : API ,
74
75
private readonly globalState : Memento ,
75
- private readonly logger : LogOutputChannel ) {
76
+ private readonly logger : LogOutputChannel ,
77
+ private readonly telemetryReporter : TelemetryReporter ) {
76
78
this . disposables . add ( this . gitAPI . onDidOpenRepository ( repository => {
77
79
if ( this . _enabled ) {
78
- this . providerDisposables . add ( gitAPI . registerBranchProtectionProvider ( repository . rootUri , new GithubBranchProtectionProvider ( repository , this . globalState , this . logger ) ) ) ;
80
+ this . providerDisposables . add ( gitAPI . registerBranchProtectionProvider ( repository . rootUri , new GithubBranchProtectionProvider ( repository , this . globalState , this . logger , this . telemetryReporter ) ) ) ;
79
81
}
80
82
} ) ) ;
81
83
@@ -110,7 +112,8 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
110
112
constructor (
111
113
private readonly repository : Repository ,
112
114
private readonly globalState : Memento ,
113
- private readonly logger : LogOutputChannel ) {
115
+ private readonly logger : LogOutputChannel ,
116
+ private readonly telemetryReporter : TelemetryReporter ) {
114
117
// Restore branch protection from global state
115
118
this . branchProtection = this . globalState . get < BranchProtection [ ] > ( this . globalStateKey , [ ] ) ;
116
119
@@ -199,6 +202,14 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
199
202
// Save branch protection to global state
200
203
await this . globalState . update ( this . globalStateKey , branchProtection ) ;
201
204
this . logger . trace ( `Branch protection for "${ this . repository . rootUri . toString ( ) } ": ${ JSON . stringify ( branchProtection ) } .` ) ;
205
+
206
+ /* __GDPR__
207
+ "branchProtection" : {
208
+ "owner": "lszomoru",
209
+ "rulesetCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of repository rulesets" }
210
+ }
211
+ */
212
+ this . telemetryReporter . sendTelemetryEvent ( 'branchProtection' , undefined , { rulesetCount : this . branchProtection . length } ) ;
202
213
} catch ( err ) {
203
214
this . logger . warn ( `Failed to update repository branch protection: ${ err . message } ` ) ;
204
215
0 commit comments