Skip to content

Commit

Permalink
GitHub - add push error handler telemetry to understand usage (#185573)
Browse files Browse the repository at this point in the history
* GitHub - add push error handler telemetry to understand usage

* Add yarn.lock file

* Pull request feedback
  • Loading branch information
lszomoru authored Jun 19, 2023
1 parent 2dcfc37 commit 8f88484
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 5 deletions.
4 changes: 3 additions & 1 deletion extensions/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"engines": {
"vscode": "^1.41.0"
},
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
"icon": "images/icon.png",
"categories": [
"Other"
Expand Down Expand Up @@ -181,7 +182,8 @@
"@octokit/graphql": "5.0.5",
"@octokit/graphql-schema": "14.4.0",
"@octokit/rest": "19.0.4",
"tunnel": "^0.0.6"
"tunnel": "^0.0.6",
"@vscode/extension-telemetry": "0.7.5"
},
"devDependencies": {
"@types/node": "16.x"
Expand Down
11 changes: 8 additions & 3 deletions extensions/github/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { commands, Disposable, ExtensionContext, extensions, l10n, LogLevel, LogOutputChannel, window } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import { GithubRemoteSourceProvider } from './remoteSourceProvider';
import { API, GitExtension } from './typings/git';
import { registerCommands } from './commands';
Expand All @@ -29,8 +30,12 @@ export function activate(context: ExtensionContext): void {
disposables.push(logger.onDidChangeLogLevel(onDidChangeLogLevel));
onDidChangeLogLevel(logger.logLevel);

const { aiKey } = require('../package.json') as { aiKey: string };
const telemetryReporter = new TelemetryReporter(aiKey);
disposables.push(telemetryReporter);

disposables.push(initializeGitBaseExtension());
disposables.push(initializeGitExtension(context, logger));
disposables.push(initializeGitExtension(context, telemetryReporter, logger));
}

function initializeGitBaseExtension(): Disposable {
Expand Down Expand Up @@ -78,7 +83,7 @@ function setGitHubContext(gitAPI: API, disposables: DisposableStore) {
}
}

function initializeGitExtension(context: ExtensionContext, logger: LogOutputChannel): Disposable {
function initializeGitExtension(context: ExtensionContext, telemetryReporter: TelemetryReporter, logger: LogOutputChannel): Disposable {
const disposables = new DisposableStore();

let gitExtension = extensions.getExtension<GitExtension>('vscode.git');
Expand All @@ -93,7 +98,7 @@ function initializeGitExtension(context: ExtensionContext, logger: LogOutputChan
disposables.add(registerCommands(gitAPI));
disposables.add(new GithubCredentialProviderManager(gitAPI));
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger));
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler()));
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler(telemetryReporter)));
disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI)));
disposables.add(new GitHubCanonicalUriProvider(gitAPI));
disposables.add(new VscodeDevShareProvider(gitAPI));
Expand Down
29 changes: 28 additions & 1 deletion extensions/github/src/pushErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { TextDecoder } from 'util';
import { commands, env, ProgressLocation, Uri, window, workspace, QuickPickOptions, FileType, l10n, Disposable, TextDocumentContentProvider } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import { getOctokit } from './auth';
import { GitErrorCodes, PushErrorHandler, Remote, Repository } from './typings/git';
import * as path from 'path';
Expand Down Expand Up @@ -99,7 +100,7 @@ export class GithubPushErrorHandler implements PushErrorHandler {
private disposables: Disposable[] = [];
private commandErrors = new CommandErrorOutputTextDocumentContentProvider();

constructor() {
constructor(private readonly telemetryReporter: TelemetryReporter) {
this.disposables.push(workspace.registerTextDocumentContentProvider('github-output', this.commandErrors));
}

Expand All @@ -126,15 +127,41 @@ export class GithubPushErrorHandler implements PushErrorHandler {

if (error.gitErrorCode === GitErrorCodes.PermissionDenied) {
await this.handlePermissionDeniedError(repository, remote, refspec, owner, repo);

/* __GDPR__
"pushErrorHandler" : {
"owner": "lszomoru",
"handler": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryReporter.sendTelemetryEvent('pushErrorHandler', { handler: 'PermissionDenied' });

return true;
}

// Push protection
if (/GH009: Secrets detected!/i.test(error.stderr)) {
await this.handlePushProtectionError(owner, repo, error.stderr);

/* __GDPR__
"pushErrorHandler" : {
"owner": "lszomoru",
"handler": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryReporter.sendTelemetryEvent('pushErrorHandler', { handler: 'PushRejected.PushProtection' });

return true;
}

/* __GDPR__
"pushErrorHandler" : {
"owner": "lszomoru",
"handler": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryReporter.sendTelemetryEvent('pushErrorHandler', { handler: 'None' });

return false;
}

Expand Down
Loading

0 comments on commit 8f88484

Please sign in to comment.