Skip to content

Commit 0af4ba0

Browse files
authored
GitHub - add branch protection telemetry (microsoft#187589)
1 parent ef8b148 commit 0af4ba0

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

extensions/github/src/branchProtection.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Repository as GitHubRepository, RepositoryRuleset } from '@octokit/grap
88
import { AuthenticationError, getOctokitGraphql } from './auth';
99
import { API, BranchProtection, BranchProtectionProvider, BranchProtectionRule, Repository } from './typings/git';
1010
import { DisposableStore, getRepositoryFromUrl } from './util';
11+
import TelemetryReporter from '@vscode/extension-telemetry';
1112

1213
const 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

extensions/github/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function initializeGitExtension(context: ExtensionContext, telemetryReporter: Te
9797

9898
disposables.add(registerCommands(gitAPI));
9999
disposables.add(new GithubCredentialProviderManager(gitAPI));
100-
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger));
100+
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger, telemetryReporter));
101101
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler(telemetryReporter)));
102102
disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI)));
103103
disposables.add(new GitHubCanonicalUriProvider(gitAPI));

0 commit comments

Comments
 (0)