Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Remove project path from telemetry and add hash project name #896

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/projectInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ export class ProjectInitializer {
const scaffoldType = ScaffoldType.Local;

// Step 1: Get project name
const projectPath = await this.generateProjectFolder(scaffoldType);
const projectPath =
await this.generateProjectFolder(telemetryContext, scaffoldType);
if (!projectPath) {
throw new CancelOperationError(
`Project initialization cancelled: Project name input cancelled.`);
} else {
telemetryContext.properties.projectPath = projectPath;
}

// Step 2: Select platform
Expand Down Expand Up @@ -178,8 +177,9 @@ export class ProjectInitializer {
return templateSelection;
}

private async generateProjectFolder(scaffoldType: ScaffoldType):
Promise<string|undefined> {
private async generateProjectFolder(
telemetryContext: TelemetryContext,
scaffoldType: ScaffoldType): Promise<string|undefined> {
// Get default workbench path.
const settings = await IoTWorkbenchSettings.getInstance();
const workbench = settings.getWorkbenchPath();
Expand Down Expand Up @@ -223,6 +223,10 @@ export class ProjectInitializer {
}
}
});
if (projectName) {
const projectNameMd5 = utils.getHashFromString(projectName);
telemetryContext.properties.projectName = projectNameMd5;
}

const projectPath =
projectName ? path.join(projectRootPath, projectName) : undefined;
Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import * as cp from 'child_process';
import * as crypto from 'crypto';
import * as fs from 'fs-plus';
import * as path from 'path';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -890,4 +891,17 @@ export function shouldShowLandingPage(context: vscode.ExtensionContext):
boolean {
const hasPopUp = context.globalState.get<boolean>(ConfigKey.hasPopUp, false);
return !hasPopUp;
}

/**
* Hash a string and get hash value.
* @param stringToHash string to hash
* @param algorithm hash algorithm
*/
export function getHashFromString(
stringToHash: string, algorithm = 'md5'): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use sha256 instead of md5

const hash = crypto.createHash(algorithm);
hash.update(stringToHash);
const hashValue = hash.digest('hex');
return hashValue;
}