mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
handle large github issue error (#233613)
* handle large github issue things * inline added something that was kinda cool but doesn't work in all scenarios very cool and demure tho
This commit is contained in:
@@ -20,6 +20,10 @@ import { IIssueFormService, IssueReporterData, IssueType } from '../common/issue
|
||||
// ref https://github.com/microsoft/vscode/issues/159191
|
||||
const MAX_URL_LENGTH = 7500;
|
||||
|
||||
// Github API and issues on web has a limit of 65536. We chose 65500 to play it safe.
|
||||
// ref https://github.com/github/issues/issues/12858
|
||||
const MAX_GITHUB_API_LENGTH = 65500;
|
||||
|
||||
|
||||
export class IssueReporter extends BaseIssueReporterService {
|
||||
private readonly processMainService: IProcessMainService;
|
||||
@@ -85,6 +89,10 @@ export class IssueReporter extends BaseIssueReporterService {
|
||||
}
|
||||
|
||||
public override async submitToGitHub(issueTitle: string, issueBody: string, gitHubDetails: { owner: string; repositoryName: string }): Promise<boolean> {
|
||||
if (issueBody.length > MAX_GITHUB_API_LENGTH) {
|
||||
console.error('Issue body is too long.');
|
||||
return false;
|
||||
}
|
||||
const url = `https://api.github.com/repos/${gitHubDetails.owner}/${gitHubDetails.repositoryName}/issues`;
|
||||
const init = {
|
||||
method: 'POST',
|
||||
@@ -174,16 +182,20 @@ export class IssueReporter extends BaseIssueReporterService {
|
||||
let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`;
|
||||
|
||||
if (this.data.githubAccessToken && gitHubDetails) {
|
||||
return this.submitToGitHub(issueTitle, issueBody, gitHubDetails);
|
||||
} else if (url.length > MAX_URL_LENGTH) {
|
||||
try {
|
||||
url = await this.writeToClipboard(baseUrl, issueBody);
|
||||
} catch (_) {
|
||||
console.error('Writing to clipboard failed');
|
||||
return false;
|
||||
if (await this.submitToGitHub(issueTitle, issueBody, gitHubDetails)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (url.length > MAX_URL_LENGTH || issueBody.length > MAX_GITHUB_API_LENGTH) {
|
||||
url = await this.writeToClipboard(baseUrl, issueBody);
|
||||
}
|
||||
} catch (_) {
|
||||
console.error('Writing to clipboard failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
await this.nativeHostService.openExternal(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user