GitHub - add branch protection telemetry (#187589)

This commit is contained in:
Ladislau Szomoru 2023-07-11 22:51:09 +02:00 committed by GitHub
parent ef8b1483fc
commit 0af4ba0b54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View file

@ -8,6 +8,7 @@ import { Repository as GitHubRepository, RepositoryRuleset } from '@octokit/grap
import { AuthenticationError, getOctokitGraphql } from './auth';
import { API, BranchProtection, BranchProtectionProvider, BranchProtectionRule, Repository } from './typings/git';
import { DisposableStore, getRepositoryFromUrl } from './util';
import TelemetryReporter from '@vscode/extension-telemetry';
const REPOSITORY_QUERY = `
query repositoryPermissions($owner: String!, $repo: String!) {
@ -60,7 +61,7 @@ export class GithubBranchProtectionProviderManager {
if (enabled) {
for (const repository of this.gitAPI.repositories) {
this.providerDisposables.add(this.gitAPI.registerBranchProtectionProvider(repository.rootUri, new GithubBranchProtectionProvider(repository, this.globalState, this.logger)));
this.providerDisposables.add(this.gitAPI.registerBranchProtectionProvider(repository.rootUri, new GithubBranchProtectionProvider(repository, this.globalState, this.logger, this.telemetryReporter)));
}
} else {
this.providerDisposables.dispose();
@ -72,10 +73,11 @@ export class GithubBranchProtectionProviderManager {
constructor(
private readonly gitAPI: API,
private readonly globalState: Memento,
private readonly logger: LogOutputChannel) {
private readonly logger: LogOutputChannel,
private readonly telemetryReporter: TelemetryReporter) {
this.disposables.add(this.gitAPI.onDidOpenRepository(repository => {
if (this._enabled) {
this.providerDisposables.add(gitAPI.registerBranchProtectionProvider(repository.rootUri, new GithubBranchProtectionProvider(repository, this.globalState, this.logger)));
this.providerDisposables.add(gitAPI.registerBranchProtectionProvider(repository.rootUri, new GithubBranchProtectionProvider(repository, this.globalState, this.logger, this.telemetryReporter)));
}
}));
@ -110,7 +112,8 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
constructor(
private readonly repository: Repository,
private readonly globalState: Memento,
private readonly logger: LogOutputChannel) {
private readonly logger: LogOutputChannel,
private readonly telemetryReporter: TelemetryReporter) {
// Restore branch protection from global state
this.branchProtection = this.globalState.get<BranchProtection[]>(this.globalStateKey, []);
@ -199,6 +202,14 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
// Save branch protection to global state
await this.globalState.update(this.globalStateKey, branchProtection);
this.logger.trace(`Branch protection for "${this.repository.rootUri.toString()}": ${JSON.stringify(branchProtection)}.`);
/* __GDPR__
"branchProtection" : {
"owner": "lszomoru",
"rulesetCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of repository rulesets" }
}
*/
this.telemetryReporter.sendTelemetryEvent('branchProtection', undefined, { rulesetCount: this.branchProtection.length });
} catch (err) {
this.logger.warn(`Failed to update repository branch protection: ${err.message}`);

View file

@ -97,7 +97,7 @@ function initializeGitExtension(context: ExtensionContext, telemetryReporter: Te
disposables.add(registerCommands(gitAPI));
disposables.add(new GithubCredentialProviderManager(gitAPI));
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger));
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger, telemetryReporter));
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler(telemetryReporter)));
disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI)));
disposables.add(new GitHubCanonicalUriProvider(gitAPI));