Skip to content

Adds option to generate a bug report in GitHub #963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ to file an issue on our GitHub repository:
Make sure to fill in the information that is requested in the issue template as it
will help us investigate the problem more quickly.

> Note To automatically create a bug report from within the extension run the *"Report a problem on GitHub"* command. Some basic information about your instance and powershell versions will be collected and inserted into a new GitHub issue.

### 2. Capture verbose logs and send them to us

If you're having an issue with crashing or other erratic behavior, add the following
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
"title": "Open PowerShell Extension Logs Folder",
"category": "PowerShell"
},
{
"command": "PowerShell.GenerateBugReport",
"title": "Upload Bug Report to Github",
"category": "PowerShell"
},
{
"command": "PowerShell.OpenInISE",
"title": "Open Current File in PowerShell ISE",
Expand Down Expand Up @@ -399,6 +404,11 @@
"default": true,
"description": "Loads user and system-wide PowerShell profiles (profile.ps1 and Microsoft.VSCode_profile.ps1) into the PowerShell session. This affects IntelliSense and interactive script execution, but it does not affect the debugger."
},
"powershell.bugReporting.project": {
"type": "string",
"default": "https://github.com/PowerShell/vscode-powershell",
"description": "Specifies the url of the GitHub project in which to generate bug reports."
},
"powershell.scriptAnalysis.enable": {
"type": "boolean",
"default": true,
Expand Down
133 changes: 133 additions & 0 deletions src/features/GenerateBugReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import vscode = require('vscode');
import { SessionManager } from '../session';
import cp = require('child_process');
import Settings = require('../settings');

import window = vscode.window;
const os = require("os");

import { IFeature, LanguageClient } from '../feature';
// import { IExtensionManagementService, LocalExtensionType, ILocalExtension } from 'vs/platform/extensionManagement/common/extensionManagement';

const extensionId: string = 'ms-vscode.PowerShell';
const extensionVersion: string = vscode.extensions.getExtension(extensionId).packageJSON.version;

const queryStringPrefix: string = '?'

var settings = Settings.load();
let project = settings.bugReporting.project;

const issuesUrl: string = `${project}/issues/new`

var extensions = vscode.extensions.all.filter(element => element.packageJSON.isBuiltin == false).sort((leftside, rightside): number => {
if (leftside.packageJSON.name.toLowerCase() < rightside.packageJSON.name.toLowerCase()) return -1;
if (leftside.packageJSON.name.toLowerCase() > rightside.packageJSON.name.toLowerCase()) return 1;
return 0;
})

export class GenerateBugReportFeature implements IFeature {

private command: vscode.Disposable;
private powerShellProcess: cp.ChildProcess;

constructor(private sessionManager: SessionManager) {
this.command = vscode.commands.registerCommand('PowerShell.GenerateBugReport', () => {


var OutputChannel = window.createOutputChannel('Debug');
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the ILogger interface for this instead of an output channel, it'll go to the PowerShell Extension Logs channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, actually that was just used for debugging my code. I will remove it. Unless you think it would be beneficial to put the information into the log file.

OutputChannel.show();

OutputChannel.appendLine('Starting Bug Report');

var body = encodeURIComponent(`## Issue Description ##

I am experiencing a problem with...

## Attached Logs ##

Follow the instructions in the [README](https://github.com/PowerShell/vscode-powershell#reporting-problems) about capturing and sending logs.

## Environment Information ##

### Visual Studio Code ###

| Name | Version |
| --- | --- |
| Operating System | ${os.type() + ' ' + os.arch() + ' ' + os.release()} |
| VSCode | ${vscode.version}|
| PowerShell Extension Version | ${extensionVersion} |

### PowerShell Information ###

${this.getRuntimeInfo()}

### Visual Studio Code Extensions ###

<details><summary>Visual Studio Code Extensions(Click to Expand)</summary>

${this.generateExtensionTable(extensions)}
</details>

`);

var encodedBody = encodeURIComponent(body);
var fullUrl = `${issuesUrl}${queryStringPrefix}body=${encodedBody}`;
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(fullUrl));

});

}


public setLanguageClient(LanguageClient: LanguageClient) {
// Not needed for this feature.
}

public dispose() {
this.command.dispose();
}


private generateExtensionTable(extensions): string {
if (!extensions.length) {
return 'none';
}

let tableHeader = `|Extension|Author|Version|\n|---|---|---|`;
const table = extensions.map(e => {

if (e.packageJSON.isBuiltin == false) {
return `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`;
}
}).join('\n');

const extensionTable = `
${tableHeader}\n${table};
`;
// 2000 chars is browsers de-facto limit for URLs, 400 chars are allowed for other string parts of the issue URL
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
// if (encodeURIComponent(extensionTable).length > 1600) {
// return 'the listing length exceeds browsers\' URL characters limit';
// }

return extensionTable;
}

private getRuntimeInfo() {

var psOutput;
var powerShellExePath = this.sessionManager.getPowerShellExePath();
var powerShellArgs = [
"-NoProfile",
"-Command",
'$PSVersionString = "|Name|Value|\n"; $PSVersionString += "|---|---|\n"; $PSVersionTable.keys | ForEach-Object { $PSVersionString += "|$_|$($PSVersionTable.Item($_))|\n" }; $PSVersionString'
]

var spawn = require('child_process').spawnSync;
var child = spawn(powerShellExePath, powerShellArgs);
return child.stdout.toString().replace(';', ',');

}

}

2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PowerShellLanguageId } from './utils';
import { ConsoleFeature } from './features/Console';
import { ExamplesFeature } from './features/Examples';
import { OpenInISEFeature } from './features/OpenInISE';
import { GenerateBugReportFeature } from './features/GenerateBugReport';
import { CustomViewsFeature } from './features/CustomViews';
import { ExpandAliasFeature } from './features/ExpandAlias';
import { ShowHelpFeature } from './features/ShowOnlineHelp';
Expand Down Expand Up @@ -109,6 +110,7 @@ export function activate(context: vscode.ExtensionContext): void {
new ConsoleFeature(),
new ExamplesFeature(),
new OpenInISEFeature(),
new GenerateBugReportFeature(sessionManager),
new ExpandAliasFeature(),
new ShowHelpFeature(),
new FindModuleFeature(),
Expand Down
2 changes: 1 addition & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class SessionManager implements Middleware {
SessionStatus.Failed);
}

private getPowerShellExePath(): string {
public getPowerShellExePath(): string {

if (!this.sessionSettings.powerShellExePath &&
this.sessionSettings.developer.powerShellExePath)
Expand Down
12 changes: 11 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ enum CodeFormattingPreset {
Stroustrup
}

export interface IBugReportingSettings {
project: string;
}

export interface ICodeFormattingSettings {
preset: CodeFormattingPreset;
openBraceOnSameLine: boolean;
Expand Down Expand Up @@ -55,6 +59,7 @@ export interface ISettings {
developer?: IDeveloperSettings;
codeFormatting?: ICodeFormattingSettings;
integratedConsole?: IIntegratedConsoleSettings;
bugReporting?: IBugReportingSettings
}

export interface IIntegratedConsoleSettings {
Expand All @@ -67,6 +72,10 @@ export function load(): ISettings {
vscode.workspace.getConfiguration(
utils.PowerShellLanguageId);

let defaultBugReportingSettings: IBugReportingSettings = {
project: "https://github.com/PowerShell/vscode-powershell"
};

let defaultScriptAnalysisSettings: IScriptAnalysisSettings = {
enable: true,
settingsPath: ""
Expand Down Expand Up @@ -112,7 +121,8 @@ export function load(): ISettings {
debugging: configuration.get<IDebuggingSettings>("debugging", defaultDebuggingSettings),
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings),
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings)
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings),
bugReporting: configuration.get<IBugReportingSettings>("bugReporting", defaultBugReportingSettings)
};
}

Expand Down