@@ -8,6 +8,7 @@ import { Repository as GitHubRepository, RepositoryRuleset } from '@octokit/grap
88import { AuthenticationError , getOctokitGraphql } from './auth' ;
99import { API , BranchProtection , BranchProtectionProvider , BranchProtectionRule , Repository } from './typings/git' ;
1010import { DisposableStore , getRepositoryFromUrl } from './util' ;
11+ import TelemetryReporter from '@vscode/extension-telemetry' ;
1112
1213const REPOSITORY_QUERY = `
1314 query repositoryPermissions($owner: String!, $repo: String!) {
@@ -60,7 +61,7 @@ export class GithubBranchProtectionProviderManager {
6061
6162 if ( enabled ) {
6263 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 ) ) ) ;
6465 }
6566 } else {
6667 this . providerDisposables . dispose ( ) ;
@@ -72,10 +73,11 @@ export class GithubBranchProtectionProviderManager {
7273 constructor (
7374 private readonly gitAPI : API ,
7475 private readonly globalState : Memento ,
75- private readonly logger : LogOutputChannel ) {
76+ private readonly logger : LogOutputChannel ,
77+ private readonly telemetryReporter : TelemetryReporter ) {
7678 this . disposables . add ( this . gitAPI . onDidOpenRepository ( repository => {
7779 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 ) ) ) ;
7981 }
8082 } ) ) ;
8183
@@ -110,7 +112,8 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
110112 constructor (
111113 private readonly repository : Repository ,
112114 private readonly globalState : Memento ,
113- private readonly logger : LogOutputChannel ) {
115+ private readonly logger : LogOutputChannel ,
116+ private readonly telemetryReporter : TelemetryReporter ) {
114117 // Restore branch protection from global state
115118 this . branchProtection = this . globalState . get < BranchProtection [ ] > ( this . globalStateKey , [ ] ) ;
116119
@@ -199,6 +202,14 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
199202 // Save branch protection to global state
200203 await this . globalState . update ( this . globalStateKey , branchProtection ) ;
201204 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 } ) ;
202213 } catch ( err ) {
203214 this . logger . warn ( `Failed to update repository branch protection: ${ err . message } ` ) ;
204215
0 commit comments