Skip to content

Commit 5c18500

Browse files
authored
fix copilot case for signed out users (microsoft#252437)
1 parent 7e1d9f0 commit 5c18500

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/vs/workbench/contrib/issue/browser/baseIssueReporterService.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ export class BaseIssueReporterService extends Disposable {
301301

302302
private async sendReporterMenu(extension: IssueReporterExtensionData): Promise<IssueReporterData | undefined> {
303303
try {
304-
const data = await this.issueFormService.sendReporterMenu(extension.id);
304+
const timeoutPromise = new Promise<undefined>((_, reject) =>
305+
setTimeout(() => reject(new Error('sendReporterMenu timed out')), 10000)
306+
);
307+
const data = await Promise.race([
308+
this.issueFormService.sendReporterMenu(extension.id),
309+
timeoutPromise
310+
]);
305311
return data;
306312
} catch (e) {
307313
console.error(e);
@@ -1056,11 +1062,12 @@ export class BaseIssueReporterService extends Disposable {
10561062
const baseUrl = this.getIssueUrlWithTitle((<HTMLInputElement>this.getElementById('issue-title')).value, issueUrl);
10571063
let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`;
10581064

1059-
url += this.addTemplateToUrl(gitHubDetails?.owner, gitHubDetails?.repositoryName);
1065+
url = this.addTemplateToUrl(url, gitHubDetails?.owner, gitHubDetails?.repositoryName);
10601066

10611067
if (url.length > MAX_URL_LENGTH) {
10621068
try {
1063-
url = await this.writeToClipboard(baseUrl, issueBody) + this.addTemplateToUrl(gitHubDetails?.owner, gitHubDetails?.repositoryName);
1069+
url = await this.writeToClipboard(baseUrl, issueBody);
1070+
url = this.addTemplateToUrl(url, gitHubDetails?.owner, gitHubDetails?.repositoryName);
10641071
} catch (_) {
10651072
console.error('Writing to clipboard failed');
10661073
return false;
@@ -1081,24 +1088,22 @@ export class BaseIssueReporterService extends Disposable {
10811088
return baseUrl + `&body=${encodeURIComponent(localize('pasteData', "We have written the needed data into your clipboard because it was too large to send. Please paste."))}`;
10821089
}
10831090

1084-
public addTemplateToUrl(owner?: string, repositoryName?: string): string {
1091+
public addTemplateToUrl(baseUrl: string, owner?: string, repositoryName?: string): string {
10851092
const isVscode = this.issueReporterModel.getData().fileOnProduct;
1086-
const isCopilot = owner?.toLowerCase() === 'microsoft' && repositoryName === 'vscode-copilot-release';
1087-
const isPython = owner?.toLowerCase() === 'microsoft' && repositoryName === 'vscode-python';
1093+
const isMicrosoft = owner?.toLowerCase() === 'microsoft';
1094+
const needsTemplate = isVscode || (isMicrosoft && (repositoryName === 'vscode' || repositoryName === 'vscode-python'));
10881095

1089-
if (isVscode) {
1090-
return `&template=bug_report.md`;
1091-
}
1092-
1093-
if (isCopilot) {
1094-
return `&template=bug_report_chat.md`;
1095-
}
1096-
1097-
if (isPython) {
1098-
return `&template=bug_report.md`;
1096+
if (needsTemplate) {
1097+
try {
1098+
const url = new URL(baseUrl);
1099+
url.searchParams.set('template', 'bug_report.md');
1100+
return url.toString();
1101+
} catch {
1102+
// fallback if baseUrl is not a valid URL
1103+
return baseUrl + '&template=bug_report.md';
1104+
}
10991105
}
1100-
1101-
return '';
1106+
return baseUrl;
11021107
}
11031108

11041109
public getIssueUrl(): string {

src/vs/workbench/contrib/issue/electron-browser/issueReporterService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class IssueReporter extends BaseIssueReporterService {
228228
const baseUrl = this.getIssueUrlWithTitle((<HTMLInputElement>this.getElementById('issue-title')).value, issueUrl);
229229
let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`;
230230

231-
url += this.addTemplateToUrl(gitHubDetails?.owner, gitHubDetails?.repositoryName);
231+
url = this.addTemplateToUrl(url, gitHubDetails?.owner, gitHubDetails?.repositoryName);
232232

233233
if (this.data.githubAccessToken && gitHubDetails) {
234234
if (await this.submitToGitHub(issueTitle, issueBody, gitHubDetails)) {
@@ -238,7 +238,8 @@ export class IssueReporter extends BaseIssueReporterService {
238238

239239
try {
240240
if (url.length > MAX_URL_LENGTH || issueBody.length > MAX_GITHUB_API_LENGTH) {
241-
url = await this.writeToClipboard(baseUrl, issueBody) + this.addTemplateToUrl(gitHubDetails?.owner, gitHubDetails?.repositoryName);
241+
url = await this.writeToClipboard(baseUrl, issueBody);
242+
url = this.addTemplateToUrl(url, gitHubDetails?.owner, gitHubDetails?.repositoryName);
242243
}
243244
} catch (_) {
244245
console.error('Writing to clipboard failed');

0 commit comments

Comments
 (0)