Adding reportIssue command, updating for PR feedback

This commit is contained in:
sfoslund 2020-02-11 14:17:19 -08:00
Родитель 3c46e80fd4
Коммит 73d0e65a61
6 изменённых файлов: 44 добавлений и 16 удалений

Просмотреть файл

@ -11,7 +11,7 @@
### First Acquisition
- Resolve version by fetching release.json
- If we are offline, we will fail here.
- If we are offline, we will fail here because the user also will not be able to download a runtime offline.
- Check if version has been installed previously or is currently being installed
- Fetch dotnet-install script
- Install runtime via script

Просмотреть файл

@ -31,10 +31,19 @@
"onCommand:dotnet.acquire",
"onCommand:dotnet.uninstallAll",
"onCommand:dotnet.showAcquisitionLog",
"onCommand:dotnet.ensureDotnetDependencies"
"onCommand:dotnet.ensureDotnetDependencies",
"onCommand:dotnet.reportIssue"
],
"main": "./dist/extension.js",
"contributes": {},
"contributes": {
"commands": [
{
"command": "dotnet.reportIssue",
"title": "Report an issue with the .NET Install Tool for Extension Authors.",
"category": ".NET Install Tool"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile-all && npm install && webpack --mode production",
"compile-all": "cd vscode-dotnet-runtime-library && npm install && npm run compile && cd .. && cd vscode-dotnet-runtime-extension && npm install && npm run compile && cd .."

Просмотреть файл

@ -3,21 +3,26 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as open from 'open';
import { window } from 'vscode';
import { env, window } from 'vscode';
import { IIssueContext } from './IIssueContext';
import { formatIssueUrl } from './IssueReporter';
const errorMessage = 'An error occurred while installing .NET';
const reportOption = 'Report an issue';
const hideOption = 'Don\'t show again';
let showMessage = true;
export async function callWithErrorHandling<T>(callback: () => T, context: IIssueContext): Promise<T | undefined> {
try {
return await callback();
} catch (error) {
if (error.constructor.name !== 'UserCancelledError') {
window.showErrorMessage(`${errorMessage}: ${ error.message }`, reportOption).then((response: string | undefined) => {
if (response === reportOption) {
const url = formatIssueUrl(error, context);
if (error.constructor.name !== 'UserCancelledError' && showMessage) {
window.showErrorMessage(`${errorMessage}: ${ error.message }`, reportOption, hideOption).then(async (response: string | undefined) => {
if (response === hideOption) {
showMessage = false;
} else if (response === reportOption) {
const [url, issueBody] = formatIssueUrl(error, context);
await env.clipboard.writeText(issueBody);
open(url);
}
});

Просмотреть файл

@ -6,7 +6,7 @@ import { IIssueContext } from './IIssueContext';
const issuesUrl = `https://github.com/dotnet/vscode-dotnet-runtime/issues`;
export function formatIssueUrl(error: Error, context: IIssueContext): string {
export function formatIssueUrl(error: Error | undefined, context: IIssueContext): [ string, string ] {
context.logger.dispose(); // Ensure log file is up to date
const issueBody = `<!-- IMPORTANT: Please be sure to remove any private information before submitting and attach the log file located at ${ context.logger.getFileLocation() }. -->
@ -14,8 +14,9 @@ export function formatIssueUrl(error: Error, context: IIssueContext): string {
1.
**Error:** ${ error.stack }`;
${ error === undefined ? '' : `**Error:** ${ error!.stack }` }`;
const url = `${issuesUrl}/new?body=${encodeURIComponent(issueBody)}`;
return url;
const issueMessage = 'The issue text was copied to the clipboard. Please paste it into this window.';
const url = `${issuesUrl}/new?body=${encodeURIComponent(issueMessage)}`;
return [url, issueBody];
}

Просмотреть файл

@ -4,6 +4,7 @@
* ------------------------------------------------------------------------------------------ */
import * as cp from 'child_process';
import * as fs from 'fs';
import open = require('open');
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
@ -24,6 +25,7 @@ import { IDotnetAcquireResult } from './IDotnetAcquireResult';
import { IDotnetEnsureDependenciesContext } from './IDotnetEnsureDependenciesContext';
import { IExtensionContext } from './IExtensionContext';
import { callWithErrorHandling } from './Utils/ErrorHandler';
import { formatIssueUrl } from './Utils/IssueReporter';
export function activate(context: vscode.ExtensionContext, parentExtensionId: string, extensionContext?: IExtensionContext) {
const extension = vscode.extensions.getExtension(parentExtensionId);
@ -92,12 +94,18 @@ export function activate(context: vscode.ExtensionContext, parentExtensionId: st
}
}, issueContext);
});
const reportIssueRegistration = vscode.commands.registerCommand('dotnet.reportIssue', async () => {
const [url, issueBody] = formatIssueUrl(undefined, issueContext);
await vscode.env.clipboard.writeText(issueBody);
open(url);
});
context.subscriptions.push(
dotnetAcquireRegistration,
dotnetUninstallAllRegistration,
showOutputChannelRegistration,
testApplicationRegistration);
testApplicationRegistration,
reportIssueRegistration);
context.subscriptions.push({
dispose: () => {

Просмотреть файл

@ -9,10 +9,15 @@ const assert = chai.assert;
suite('IssueReporter Unit Tests', () => {
test('Issue url is properly formed', async () => {
const url = formatIssueUrl(new Error(), { logger: new MockLoggingObserver() });
const [url, issueBody] = formatIssueUrl(new Error(), { logger: new MockLoggingObserver() });
const expectedContent = ['Mock file location'].map((s) => encodeURIComponent(s));
for (const expected of expectedContent) {
const expectedBodyContent = ['Mock file location'];
for (const expected of expectedBodyContent) {
assert.include(issueBody, expected);
}
const expectedUrlContent = ['The issue text was copied to the clipboard'].map((s) => encodeURIComponent(s));
for (const expected of expectedUrlContent) {
assert.include(url, expected);
}
});