|
1 | 1 | // Copyright (c) Microsoft Corporation.
|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 |
| -import os = require("os"); |
5 | 4 | import vscode = require("vscode");
|
6 | 5 | import child_process = require("child_process");
|
7 | 6 | import { SessionManager } from "../session";
|
8 | 7 |
|
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?"; |
25 | 9 |
|
26 | 10 | export class GenerateBugReportFeature implements vscode.Disposable {
|
27 | 11 |
|
28 | 12 | private command: vscode.Disposable;
|
29 | 13 |
|
30 | 14 | constructor(private sessionManager: SessionManager) {
|
31 | 15 | 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); |
74 | 25 | });
|
75 | 26 | }
|
76 | 27 |
|
77 | 28 | public dispose() {
|
78 | 29 | this.command.dispose();
|
79 | 30 | }
|
80 | 31 |
|
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 { |
108 | 33 | if (this.sessionManager.PowerShellExeDetails === undefined) {
|
109 |
| - return; |
| 34 | + return "Session's PowerShell details are unknown!"; |
110 | 35 | }
|
111 | 36 |
|
112 | 37 | 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" ]; |
120 | 39 | 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(";", ","); |
122 | 42 | }
|
123 | 43 | }
|
0 commit comments