Skip to content

Commit cd5d4c9

Browse files
Fix GenerateBugReport command to pre-fill template (#4454)
1 parent 4fd2e0c commit cd5d4c9

File tree

3 files changed

+26
-98
lines changed

3 files changed

+26
-98
lines changed

src/features/GenerateBugReport.ts

+15-95
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,43 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import os = require("os");
54
import vscode = require("vscode");
65
import child_process = require("child_process");
76
import { SessionManager } from "../session";
87

9-
const queryStringPrefix = "?";
10-
11-
const project = "https://github.com/PowerShell/vscode-powershell";
12-
const issuesUrl = `${project}/issues/new`;
13-
14-
const extensions =
15-
vscode.extensions.all.filter((element) => element.packageJSON.isBuiltin === false)
16-
.sort((leftSide, rightSide): number => {
17-
if (leftSide.packageJSON.name.toLowerCase() < rightSide.packageJSON.name.toLowerCase()) {
18-
return -1;
19-
}
20-
if (leftSide.packageJSON.name.toLowerCase() > rightSide.packageJSON.name.toLowerCase()) {
21-
return 1;
22-
}
23-
return 0;
24-
});
8+
const issuesUrl = "https://github.com/PowerShell/vscode-powershell/issues/new?";
259

2610
export class GenerateBugReportFeature implements vscode.Disposable {
2711

2812
private command: vscode.Disposable;
2913

3014
constructor(private sessionManager: SessionManager) {
3115
this.command = vscode.commands.registerCommand("PowerShell.GenerateBugReport", async () => {
32-
33-
const body = `Issue Description
34-
=====
35-
36-
I am experiencing a problem with...
37-
38-
Attached Logs
39-
=====
40-
41-
Follow the instructions in the [README](https://github.com/PowerShell/vscode-powershell/blob/main/docs/troubleshooting.md) about
42-
capturing and sending logs.
43-
44-
Environment Information
45-
=====
46-
47-
Visual Studio Code
48-
-----
49-
50-
| Name | Version |
51-
| --- | --- |
52-
| Operating System | ${os.type()} ${os.arch()} ${os.release()} |
53-
| VSCode | ${vscode.version}|
54-
| PowerShell Extension Version | ${sessionManager.HostVersion} |
55-
56-
PowerShell Information
57-
-----
58-
59-
${this.getRuntimeInfo()}
60-
61-
Visual Studio Code Extensions
62-
-----
63-
64-
<details><summary>Visual Studio Code Extensions(Click to Expand)</summary>
65-
66-
${this.generateExtensionTable(extensions)}
67-
</details>
68-
69-
`;
70-
71-
const encodedBody = encodeURIComponent(body);
72-
const fullUrl = `${issuesUrl}${queryStringPrefix}body=${encodedBody}`;
73-
await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(fullUrl));
16+
const params = [
17+
"labels=Issue-Bug",
18+
"template=bug-report.yml",
19+
"powershell-version=" + this.getRuntimeInfo(),
20+
"vscode-version=" + vscode.version + "\n" + process.arch,
21+
"extension-version=" + sessionManager.Publisher + "." + sessionManager.HostName + "@" + sessionManager.HostVersion,
22+
];
23+
const url = vscode.Uri.parse(issuesUrl + encodeURIComponent(params.join("&")));
24+
await vscode.env.openExternal(url);
7425
});
7526
}
7627

7728
public dispose() {
7829
this.command.dispose();
7930
}
8031

81-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
82-
private generateExtensionTable(installedExtensions: vscode.Extension<any>[]): string {
83-
if (!installedExtensions.length) {
84-
return "none";
85-
}
86-
87-
const tableHeader = "|Extension|Author|Version|\n|---|---|---|";
88-
const table = installedExtensions.map((e) => {
89-
if (e.packageJSON.isBuiltin === false) {
90-
return `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`;
91-
}
92-
return undefined;
93-
}).join("\n");
94-
95-
const extensionTable = `
96-
${tableHeader}\n${table};
97-
`;
98-
// 2000 chars is browsers de-facto limit for URLs, 400 chars are allowed for other string parts of the issue URL
99-
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
100-
// if (encodeURIComponent(extensionTable).length > 1600) {
101-
// return 'the listing length exceeds browsers\' URL characters limit';
102-
// }
103-
104-
return extensionTable;
105-
}
106-
107-
private getRuntimeInfo(): string | undefined {
32+
private getRuntimeInfo(): string {
10833
if (this.sessionManager.PowerShellExeDetails === undefined) {
109-
return;
34+
return "Session's PowerShell details are unknown!";
11035
}
11136

11237
const powerShellExePath = this.sessionManager.PowerShellExeDetails.exePath;
113-
const powerShellArgs = [
114-
"-NoProfile",
115-
"-Command",
116-
"$PSVersionString = \"|Name|Value|\n\"; $PSVersionString += \"|---|---|\n\"; $PSVersionTable.keys | " +
117-
"ForEach-Object { $PSVersionString += \"|$_|$($PSVersionTable.Item($_))|\n\" }; $PSVersionString",
118-
];
119-
38+
const powerShellArgs = [ "-NoProfile", "-Command", "$PSVersionTable | Out-String" ];
12039
const child = child_process.spawnSync(powerShellExePath, powerShellArgs);
121-
return child.stdout.toString().replace(";", ",");
40+
// Replace semicolons as they'll cause the URI component to truncate
41+
return child.stdout.toString().trim().replace(";", ",");
12242
}
12343
}

src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
135135
settings,
136136
logger,
137137
documentSelector,
138+
PackageJSON.name,
138139
PackageJSON.displayName,
139140
PackageJSON.version,
141+
PackageJSON.publisher,
140142
telemetryReporter);
141143

142144
// Register commands that do not require Language client

src/session.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export const PowerShellVersionRequestType =
7474

7575
export class SessionManager implements Middleware {
7676
public HostName: string;
77+
public DisplayName: string;
7778
public HostVersion: string;
79+
public Publisher: string;
7880
public PowerShellExeDetails: IPowerShellExeDetails | undefined;
7981
private ShowSessionMenuCommandName = "PowerShell.ShowSessionMenu";
8082
private sessionStatus: SessionStatus = SessionStatus.NeverStarted;
@@ -100,7 +102,9 @@ export class SessionManager implements Middleware {
100102
private logger: ILogger,
101103
private documentSelector: DocumentSelector,
102104
hostName: string,
105+
displayName: string,
103106
hostVersion: string,
107+
publisher: string,
104108
private telemetryReporter: TelemetryReporter) {
105109

106110
// Create the language status item
@@ -110,14 +114,16 @@ export class SessionManager implements Middleware {
110114
this.sessionsFolder = vscode.Uri.joinPath(extensionContext.globalStorageUri.with({ scheme: "file"}), "sessions");
111115
this.platformDetails = getPlatformDetails();
112116
this.HostName = hostName;
117+
this.DisplayName = displayName;
113118
this.HostVersion = hostVersion;
119+
this.Publisher = publisher;
114120

115121
const osBitness = this.platformDetails.isOS64Bit ? "64-bit" : "32-bit";
116122
const procBitness = this.platformDetails.isProcess64Bit ? "64-bit" : "32-bit";
117123

118124
this.logger.write(
119125
`Visual Studio Code v${vscode.version} ${procBitness}`,
120-
`${this.HostName} Extension v${this.HostVersion}`,
126+
`${this.DisplayName} Extension v${this.HostVersion}`,
121127
`Operating System: ${OperatingSystem[this.platformDetails.operatingSystem]} ${osBitness}`);
122128

123129
// Fix the host version so that PowerShell can consume it.
@@ -563,9 +569,9 @@ export class SessionManager implements Middleware {
563569
// Unfortunately this means that for some installs of PowerShell
564570
// (such as through the `dotnet` package manager), we can't include
565571
// a multi-line startup banner as the quotes break the command.
566-
editorServicesArgs += `-StartupBanner '${this.HostName} Extension v${this.HostVersion}' `;
572+
editorServicesArgs += `-StartupBanner '${this.DisplayName} Extension v${this.HostVersion}' `;
567573
} else {
568-
const startupBanner = `${this.HostName} Extension v${this.HostVersion}
574+
const startupBanner = `${this.DisplayName} Extension v${this.HostVersion}
569575
Copyright (c) Microsoft Corporation.
570576
571577
https://aka.ms/vscode-powershell

0 commit comments

Comments
 (0)