Skip to content

fix copilot and signed out urls #252438

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

Open
wants to merge 1 commit into
base: release/1.101
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 23 additions & 18 deletions src/vs/workbench/contrib/issue/browser/baseIssueReporterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ export class BaseIssueReporterService extends Disposable {

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

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

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

public addTemplateToUrl(owner?: string, repositoryName?: string): string {
public addTemplateToUrl(baseUrl: string, owner?: string, repositoryName?: string): string {
const isVscode = this.issueReporterModel.getData().fileOnProduct;
const isCopilot = owner?.toLowerCase() === 'microsoft' && repositoryName === 'vscode-copilot-release';
const isPython = owner?.toLowerCase() === 'microsoft' && repositoryName === 'vscode-python';
const isMicrosoft = owner?.toLowerCase() === 'microsoft';
const needsTemplate = isVscode || (isMicrosoft && (repositoryName === 'vscode' || repositoryName === 'vscode-python'));

if (isVscode) {
return `&template=bug_report.md`;
}

if (isCopilot) {
return `&template=bug_report_chat.md`;
}

if (isPython) {
return `&template=bug_report.md`;
if (needsTemplate) {
try {
const url = new URL(baseUrl);
url.searchParams.set('template', 'bug_report.md');
return url.toString();
} catch {
// fallback if baseUrl is not a valid URL
return baseUrl + '&template=bug_report.md';
}
}

return '';
return baseUrl;
}

public getIssueUrl(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class IssueReporter extends BaseIssueReporterService {
const baseUrl = this.getIssueUrlWithTitle((<HTMLInputElement>this.getElementById('issue-title')).value, issueUrl);
let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`;

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

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

try {
if (url.length > MAX_URL_LENGTH || issueBody.length > MAX_GITHUB_API_LENGTH) {
url = await this.writeToClipboard(baseUrl, issueBody) + this.addTemplateToUrl(gitHubDetails?.owner, gitHubDetails?.repositoryName);
url = await this.writeToClipboard(baseUrl, issueBody);
url = this.addTemplateToUrl(url, gitHubDetails?.owner, gitHubDetails?.repositoryName);
}
} catch (_) {
console.error('Writing to clipboard failed');
Expand Down
Loading