@codingame/monaco-vscode-issue-service-override 38.1.3 → 39.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { createElement } from '@codingame/monaco-vscode-api/vscode/vs/base/brows
5
5
  import { safeSetInnerHtml } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/domSanitize';
6
6
  import { createStyleSheet } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/domStylesheets';
7
7
  import { Menu, getMenuWidgetCSS, unthemedMenuStyles } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/menu/menu';
8
- import { Disposable, MutableDisposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
8
+ import { Disposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
9
9
  import { isWindows, isLinux } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
10
10
  import Severity from '@codingame/monaco-vscode-api/vscode/vs/base/common/severity';
11
11
  import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
@@ -16,17 +16,15 @@ import { IContextKeyService } from '@codingame/monaco-vscode-api/vscode/vs/platf
16
16
  import { IDialogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/dialogs/common/dialogs.service';
17
17
  import { ExtensionIdentifierSet, ExtensionIdentifier } from '@codingame/monaco-vscode-api/vscode/vs/platform/extensions/common/extensions';
18
18
  import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
19
- import { IGitHubService } from '@codingame/monaco-vscode-api/vscode/vs/platform/github/common/githubService.service';
20
- import { GitHubRequestError } from '@codingame/monaco-vscode-api/vscode/vs/platform/github/common/githubTypes';
21
- import { arrayProperty, asObject, stringProperty, requiredString } from '@codingame/monaco-vscode-api/vscode/vs/platform/github/common/githubResponse';
22
19
  import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
23
20
  import { IOpenerService } from '@codingame/monaco-vscode-api/vscode/vs/platform/opener/common/opener.service';
24
21
  import product from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/product';
25
22
  import { AuxiliaryWindowMode } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
26
23
  import { IAuxiliaryWindowService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.service';
27
24
  import { IHostService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/host/browser/host.service';
25
+ import { IWorkbenchGitHubService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/github/common/githubService.service';
28
26
  import { IssueSource } from '../common/issue.js';
29
- import { normalizeGitHubUrl } from '../common/issueReporterUtil.js';
27
+ import { resolveIssueReporterTarget, getIssueReporterUrlWithTitle } from '../common/issueReporterTarget.js';
30
28
  import BaseHtml from './issueReporterPage.js';
31
29
  import { IssueWebReporter } from './issueReporterService.js';
32
30
  import { IGitHubUploadService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/issue/browser/githubUploadService.service';
@@ -34,9 +32,15 @@ import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/fi
34
32
  import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
35
33
  import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
36
34
  import { LRUCache } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
37
- import { hash } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
35
+ import { hash, hashAsync } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
36
+ import { escapeMarkdownSyntaxTokens } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
37
+ import { escape } from '@codingame/monaco-vscode-api/vscode/vs/base/common/strings';
38
+ import { toErrorMessage } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errorMessage';
38
39
  import { decodeBase64 } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
40
+ import { getIssueReporterScreenshotFile } from './issueReporterMedia.js';
39
41
  import * as issueReporter from './media/issueReporter.css';
42
+ import { abortOnDispose } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
43
+ import { isCancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
40
44
 
41
45
  registerCss(issueReporter, 1);
42
46
  const MAX_URL_LENGTH = 7500;
@@ -74,7 +78,7 @@ function extractIssueData(issueBody) {
74
78
  bodyParts.push(issueBody.slice(bodyStart));
75
79
  return {
76
80
  body: bodyParts.join("\n\n").replace(/\n{3,}/g, "\n\n").trimEnd(),
77
- fileContent: `# ${( localize(18074, "Issue Data"))}\n\n${detailsBlocks.join("\n\n")}\n`
81
+ fileContent: `# ${( localize(20883, "Issue Data"))}\n\n${detailsBlocks.join("\n\n")}\n`
78
82
  };
79
83
  }
80
84
  let IssueFormService = class IssueFormService extends Disposable {
@@ -113,39 +117,26 @@ let IssueFormService = class IssueFormService extends Disposable {
113
117
  this.release = "";
114
118
  this.type = "";
115
119
  this.uploadCache = ( new LRUCache(32));
116
- this.gitHubSearchClient = this._register(( new MutableDisposable()));
120
+ this.disposeSignal = abortOnDispose(this._store);
117
121
  }
118
122
  async searchGitHubIssues(repo, title, signal) {
123
+ signal = AbortSignal.any([signal, this.disposeSignal]);
119
124
  signal.throwIfAborted();
120
- if (this._store.isDisposed) {
121
- throw ( new GitHubRequestError("Issue reporter was disposed", "unknown"));
122
- }
123
- this.gitHubSearchClient.value ??= this.gitHubService.acquireAnonymousClient({
124
- apiBaseUri: "https://api.github.com"
125
- });
126
- const query = encodeURIComponent(`is:issue repo:${repo} ${title}`);
125
+ const lifetime = ( new DisposableStore());
127
126
  try {
128
- const response = await this.gitHubSearchClient.value.object.get(`/search/issues?q=${query}`, signal, {
127
+ const client = lifetime.add(await this.gitHubService.acquireAnonymousApiClient(signal));
128
+ const page = await client.search.issues(`repo:${repo} ${title}`, signal, {
129
129
  caller: "github.query",
130
130
  deadline: Date.now() + 10_000
131
131
  });
132
- const items = arrayProperty(
133
- asObject(response.data, "GitHub issue search response was malformed"),
134
- "items"
135
- );
136
- return items.map(item => {
137
- const issue = asObject(item, "GitHub issue search result was malformed");
138
- return {
139
- html_url: requiredString(issue, "html_url"),
140
- title: requiredString(issue, "title"),
141
- state: stringProperty(issue, "state")
142
- };
143
- });
132
+ return page.items;
144
133
  } catch (error) {
145
134
  if (!signal.aborted) {
146
135
  this.logService.warn("[IssueFormService] GitHub issue search failed", error);
147
136
  }
148
137
  throw error;
138
+ } finally {
139
+ lifetime.dispose();
149
140
  }
150
141
  }
151
142
  async openReporter(data) {
@@ -154,135 +145,236 @@ let IssueFormService = class IssueFormService extends Disposable {
154
145
  }
155
146
  return this.openAuxIssueReporterLegacy(data);
156
147
  }
157
- async submitIssue(host, data, title, body) {
158
- const screenshots = host.getScreenshots();
159
- const recordings = host.getRecordings();
160
- const issueTarget = this.getIssueTarget(data);
148
+ async submitIssue(host, data, title, body, signal = this.disposeSignal) {
149
+ signal = AbortSignal.any([signal, this.disposeSignal]);
150
+ signal.throwIfAborted();
151
+ host.setAttachmentUploadError(undefined);
152
+ signal.throwIfAborted();
153
+ const issueTarget = resolveIssueReporterTarget(data, product);
161
154
  if (!issueTarget?.url) {
155
+ this.logService.error("[IssueFormService] Invalid issue reporting destination.");
156
+ await this.dialogService.error(( localize(
157
+ 20884,
158
+ "The selected issue destination is invalid. No issue data was sent."
159
+ )));
160
+ signal.throwIfAborted();
162
161
  return false;
163
162
  }
164
163
  if (issueTarget.external) {
164
+ signal.throwIfAborted();
165
165
  return this.openerService.open(issueTarget.url, {
166
166
  openExternal: true
167
167
  });
168
168
  }
169
- const gitHubDetails = this.parseGitHubUrl(issueTarget.url);
169
+ const attachments = host.getAttachments();
170
+ const gitHubDetails = issueTarget.repository;
171
+ const hasAttachments = attachments.length > 0;
172
+ if (gitHubDetails && data.getGitHubAccessToken) {
173
+ host.setUploading(true);
174
+ try {
175
+ signal.throwIfAborted();
176
+ const token = await data.getGitHubAccessToken();
177
+ signal.throwIfAborted();
178
+ data.githubAccessToken = token;
179
+ } catch (error) {
180
+ signal.throwIfAborted();
181
+ if (isCancellationError(error)) {
182
+ throw error;
183
+ }
184
+ data.githubAccessToken = "";
185
+ this.logService.error("[IssueFormService] GitHub session lookup failed:", error);
186
+ if (hasAttachments) {
187
+ host.setAttachmentUploadError(( localize(
188
+ 20885,
189
+ "Could not access your GitHub session. Try signing in again, or remove the attachments and add them on GitHub."
190
+ )));
191
+ return false;
192
+ }
193
+ } finally {
194
+ host.setUploading(false);
195
+ }
196
+ }
197
+ signal.throwIfAborted();
198
+ const githubAccessToken = data.githubAccessToken;
170
199
  let repoId;
171
200
  const resolveRepoId = async () => {
201
+ signal.throwIfAborted();
172
202
  if (!gitHubDetails) {
173
203
  return undefined;
174
204
  }
175
- repoId ??= await this.githubUploadService.resolveRepositoryId(gitHubDetails.owner, gitHubDetails.repositoryName, data.githubAccessToken);
205
+ repoId ??= await this.githubUploadService.resolveRepositoryId(gitHubDetails.owner, gitHubDetails.repositoryName, githubAccessToken);
206
+ signal.throwIfAborted();
176
207
  return repoId;
177
208
  };
178
209
  let mediaMarkdown = "";
179
- const hasAttachments = screenshots.length > 0 || recordings.length > 0;
180
- if (hasAttachments && data.githubAccessToken && gitHubDetails) {
210
+ if (hasAttachments && (!githubAccessToken || !gitHubDetails)) {
211
+ host.setAttachmentUploadError(( localize(
212
+ 20886,
213
+ "Attachments could not be uploaded. Sign in to GitHub, or remove the attachments and add them on GitHub."
214
+ )));
215
+ return false;
216
+ }
217
+ if (hasAttachments && githubAccessToken && gitHubDetails) {
181
218
  host.setUploading(true);
219
+ let attachmentName;
182
220
  try {
183
221
  const filesToProcess = [];
184
- for (let i = 0; i < screenshots.length; i++) {
185
- const dataUrl = screenshots[i].annotatedDataUrl ?? screenshots[i].dataUrl;
186
- const bytes = this.dataUrlToBytes(dataUrl);
187
- if (bytes) {
188
- const isJpeg = dataUrl.startsWith("data:image/jpeg");
189
- const extension = isJpeg ? "jpg" : "png";
190
- const contentType = isJpeg ? "image/jpeg" : "image/png";
222
+ for (const attachment of attachments) {
223
+ host.setAttachmentUploadState(attachment, {
224
+ destination: issueTarget.url,
225
+ state: "pending"
226
+ });
227
+ }
228
+ let screenshotNumber = 0;
229
+ for (const attachment of attachments) {
230
+ signal.throwIfAborted();
231
+ if (attachment.kind === "screenshot") {
232
+ screenshotNumber++;
233
+ attachmentName = ( localize(20887, "Screenshot {0}", screenshotNumber));
234
+ const {
235
+ dataUrl,
236
+ name,
237
+ format
238
+ } = getIssueReporterScreenshotFile(attachment.screenshot, screenshotNumber);
239
+ const bytes = this.dataUrlToBytes(dataUrl);
240
+ if (!bytes || format.kind !== "image") {
241
+ throw ( new Error(( localize(20888, "The screenshot could not be read."))));
242
+ }
191
243
  filesToProcess.push({
192
- key: `screenshot:${hash(dataUrl)}`,
193
- name: `screenshot-${i + 1}.${extension}`,
244
+ attachment,
245
+ key: `screenshot:${name}:${hash(dataUrl)}`,
246
+ name,
194
247
  bytes,
248
+ contentType: format.mimeType
249
+ });
250
+ } else {
251
+ const file = attachment.file;
252
+ attachmentName = file.name;
253
+ const fileContent = await this.fileService.readFile(URI.file(file.filePath));
254
+ signal.throwIfAborted();
255
+ const contentHash = await hashAsync(fileContent.value);
256
+ signal.throwIfAborted();
257
+ const contentType = file.mimeType.split(";", 1)[0].trim().toLowerCase();
258
+ filesToProcess.push({
259
+ attachment,
260
+ key: `file:${file.filePath}:${contentHash}`,
261
+ name: file.name,
262
+ bytes: fileContent.value.buffer,
195
263
  contentType
196
264
  });
197
265
  }
198
266
  }
199
- for (let i = 0; i < recordings.length; i++) {
200
- const rec = recordings[i];
201
- const fileContent = await this.fileService.readFile(URI.file(rec.filePath));
202
- const ext = rec.filePath.endsWith(".mp4") ? "mp4" : "webm";
203
- const contentType = ext === "mp4" ? "video/mp4" : "video/webm";
204
- filesToProcess.push({
205
- key: `recording:${rec.filePath}`,
206
- name: `recording-${i + 1}.${ext}`,
207
- bytes: fileContent.value.buffer,
208
- contentType
209
- });
210
- }
211
267
  if (filesToProcess.length > 0) {
212
- for (let i = 0; i < filesToProcess.length; i++) {
213
- host.setAttachmentUploadState(i, "pending");
214
- }
215
268
  const uploadResults = [];
216
- for (let i = 0; i < filesToProcess.length; i++) {
217
- const file = filesToProcess[i];
218
- const cached = this.uploadCache.get(file.key);
269
+ for (const file of filesToProcess) {
270
+ signal.throwIfAborted();
271
+ attachmentName = file.name;
272
+ const cacheKey = `${gitHubDetails.owner.toLowerCase()}/${gitHubDetails.repositoryName.toLowerCase()}:${file.key}`;
273
+ const cached = this.uploadCache.get(cacheKey);
219
274
  if (cached) {
220
275
  uploadResults.push(cached);
221
- host.setAttachmentUploadState(i, "done");
276
+ host.setAttachmentUploadState(file.attachment, {
277
+ destination: issueTarget.url,
278
+ state: "done"
279
+ });
222
280
  continue;
223
281
  }
224
282
  const resolvedRepoId = await resolveRepoId();
225
283
  if (!resolvedRepoId) {
226
284
  throw ( new Error("No GitHub repository resolved for attachment upload."));
227
285
  }
228
- host.setAttachmentUploadState(i, "uploading");
229
- const [result] = await this.githubUploadService.uploadViaMobileApi(data.githubAccessToken, resolvedRepoId, [file]);
286
+ host.setAttachmentUploadState(file.attachment, {
287
+ destination: issueTarget.url,
288
+ state: "uploading"
289
+ });
290
+ signal.throwIfAborted();
291
+ const [result] = await this.githubUploadService.uploadViaMobileApi(githubAccessToken, resolvedRepoId, [file]);
292
+ signal.throwIfAborted();
230
293
  if (!result) {
231
294
  throw ( new Error(`Upload returned no result for ${file.name}.`));
232
295
  }
233
- this.uploadCache.set(file.key, result);
296
+ this.uploadCache.set(cacheKey, result);
234
297
  uploadResults.push(result);
235
- host.setAttachmentUploadState(i, "done");
298
+ host.setAttachmentUploadState(file.attachment, {
299
+ destination: issueTarget.url,
300
+ state: "done"
301
+ });
236
302
  }
237
- mediaMarkdown = `\n\n### ${( localize(18075, "Attachments"))}\n\n`;
238
- for (const r of uploadResults) {
239
- mediaMarkdown += r.contentType.startsWith("video/") ? `${r.assetUrl}\n\n` : `![${r.fileName}](${r.assetUrl})\n\n`;
303
+ mediaMarkdown = `\n\n### ${( localize(20889, "Attachments"))}\n\n`;
304
+ for (let i = 0; i < uploadResults.length; i++) {
305
+ const file = filesToProcess[i];
306
+ const url = ( ( URI.parse(uploadResults[i].assetUrl)).toString()).replace(/\(/g, "%28").replace(/\)/g, "%29");
307
+ const name = escapeMarkdownSyntaxTokens(escape(file.name)).replace(/\r/g, "&#13;").replace(/\n/g, "&#10;");
308
+ mediaMarkdown += file.contentType.startsWith("video/") ? `${url}\n\n` : `${file.contentType.startsWith("image/") ? "!" : ""}[${name}](${url})\n\n`;
240
309
  }
241
310
  }
242
311
  } catch (err) {
312
+ signal.throwIfAborted();
313
+ if (isCancellationError(err)) {
314
+ throw err;
315
+ }
243
316
  this.logService.error("[IssueFormService] Upload failed:", err);
244
- mediaMarkdown = `\n\n### ${( localize(18075, "Attachments"))}\n\n> ${( localize(18076, "Upload failed. Please drag and drop attachments manually."))}\n\n`;
317
+ host.setAttachmentUploadError(attachmentName ? ( localize(
318
+ 20890,
319
+ "Could not upload {0}. Try again, or remove this file and attach it on GitHub.",
320
+ attachmentName
321
+ )) : ( localize(
322
+ 20891,
323
+ "Could not upload attachments. Try again, or remove them and attach them on GitHub."
324
+ )), toErrorMessage(err));
325
+ return false;
245
326
  } finally {
246
327
  host.setUploading(false);
247
328
  }
248
329
  }
330
+ signal.throwIfAborted();
249
331
  const issueBody = body + mediaMarkdown;
250
- const baseUrl = this.getIssueUrlWithTitle(title, issueTarget.url);
332
+ const baseUrl = getIssueReporterUrlWithTitle(title, issueTarget.url);
251
333
  let previewBody = issueBody;
252
334
  let url = this.createIssuePreviewUrl(baseUrl, previewBody, gitHubDetails, data.issueSource);
253
- if (url.length > MAX_URL_LENGTH && data.githubAccessToken && gitHubDetails) {
335
+ if (url.length > MAX_URL_LENGTH && githubAccessToken && gitHubDetails) {
254
336
  const shortenedBody = await this.tryCreateBodyWithIssueDataAttachment(
255
337
  host,
256
338
  issueBody,
257
339
  baseUrl,
258
340
  gitHubDetails,
259
341
  data.issueSource,
260
- data.githubAccessToken,
261
- resolveRepoId
342
+ githubAccessToken,
343
+ resolveRepoId,
344
+ signal
262
345
  );
346
+ signal.throwIfAborted();
263
347
  if (shortenedBody) {
264
348
  previewBody = shortenedBody;
265
349
  url = this.createIssuePreviewUrl(baseUrl, previewBody, gitHubDetails, data.issueSource);
266
350
  }
267
351
  }
268
352
  if (url.length > MAX_URL_LENGTH) {
353
+ signal.throwIfAborted();
269
354
  const shouldWrite = await this.showClipboardDialog();
355
+ signal.throwIfAborted();
270
356
  if (!shouldWrite) {
271
357
  return false;
272
358
  }
273
359
  try {
274
360
  await this.clipboardService.writeText(issueBody);
361
+ signal.throwIfAborted();
275
362
  } catch (error) {
363
+ signal.throwIfAborted();
364
+ if (isCancellationError(error)) {
365
+ throw error;
366
+ }
276
367
  this.logService.error("Writing issue data to clipboard failed", error);
277
368
  return false;
278
369
  }
279
370
  url = this.createIssuePreviewUrl(baseUrl, ( localize(
280
- 18077,
371
+ 20892,
281
372
  "We have written the needed data into your clipboard because it was too large to send. Please paste."
282
373
  )), gitHubDetails, data.issueSource);
283
374
  }
284
375
  const uri = ( URI.parse(url));
285
376
  const skipValidation = uri.scheme === "https" && uri.authority === "github.com";
377
+ signal.throwIfAborted();
286
378
  return this.openerService.open(url, {
287
379
  openExternal: true,
288
380
  skipValidation
@@ -295,8 +387,10 @@ let IssueFormService = class IssueFormService extends Disposable {
295
387
  gitHubDetails,
296
388
  issueSource,
297
389
  githubAccessToken,
298
- resolveRepoId
390
+ resolveRepoId,
391
+ signal
299
392
  ) {
393
+ signal.throwIfAborted();
300
394
  const extracted = extractIssueData(issueBody);
301
395
  if (!extracted) {
302
396
  return undefined;
@@ -307,21 +401,27 @@ let IssueFormService = class IssueFormService extends Disposable {
307
401
  if (!repoId) {
308
402
  return undefined;
309
403
  }
310
- const result = await this.uploadIssueDataFile(githubAccessToken, repoId, extracted.fileContent);
404
+ const result = await this.uploadIssueDataFile(githubAccessToken, repoId, extracted.fileContent, signal);
405
+ signal.throwIfAborted();
311
406
  const bodyWithLink = this.createBodyWithIssueDataLink(extracted.body, result.assetUrl);
312
407
  if (this.createIssuePreviewUrl(baseUrl, bodyWithLink, gitHubDetails, issueSource).length > MAX_URL_LENGTH) {
313
408
  return undefined;
314
409
  }
315
410
  return bodyWithLink;
316
411
  } catch (error) {
412
+ signal.throwIfAborted();
413
+ if (isCancellationError(error)) {
414
+ throw error;
415
+ }
317
416
  this.logService.error("Uploading issue data attachment failed", error);
318
417
  return undefined;
319
418
  } finally {
320
419
  host.setUploading(false);
321
420
  }
322
421
  }
323
- async uploadIssueDataFile(githubAccessToken, repoId, fileContent) {
324
- const key = `${ISSUE_DATA_ATTACHMENT_NAME}:${hash(fileContent)}`;
422
+ async uploadIssueDataFile(githubAccessToken, repoId, fileContent, signal) {
423
+ signal.throwIfAborted();
424
+ const key = `${repoId}:${ISSUE_DATA_ATTACHMENT_NAME}:${hash(fileContent)}`;
325
425
  const cached = this.uploadCache.get(key);
326
426
  if (cached) {
327
427
  return cached;
@@ -333,6 +433,7 @@ let IssueFormService = class IssueFormService extends Disposable {
333
433
  contentType: "text/plain"
334
434
  };
335
435
  const [result] = await this.githubUploadService.uploadViaMobileApi(githubAccessToken, repoId, [file]);
436
+ signal.throwIfAborted();
336
437
  if (!result) {
337
438
  throw ( new Error("Issue data upload did not return a result."));
338
439
  }
@@ -340,7 +441,7 @@ let IssueFormService = class IssueFormService extends Disposable {
340
441
  return result;
341
442
  }
342
443
  createBodyWithIssueDataLink(body, issueDataUrl) {
343
- const attachmentMarkdown = `\n\n### ${( localize(18078, "Additional Issue Data"))}\n\n[${ISSUE_DATA_ATTACHMENT_NAME}](${issueDataUrl})`;
444
+ const attachmentMarkdown = `\n\n### ${( localize(20893, "Additional Issue Data"))}\n\n[${ISSUE_DATA_ATTACHMENT_NAME}](${issueDataUrl})`;
344
445
  const markerIndex = ( body.indexOf(GENERATED_BY_ISSUE_REPORTER_MARKER));
345
446
  if (markerIndex === -1) {
346
447
  return `${body.trimEnd()}${attachmentMarkdown}\n`;
@@ -348,94 +449,15 @@ let IssueFormService = class IssueFormService extends Disposable {
348
449
  return `${body.slice(0, markerIndex).trimEnd()}${attachmentMarkdown}\n\n${body.slice(markerIndex).trimStart()}`;
349
450
  }
350
451
  createIssuePreviewUrl(baseUrl, body, gitHubDetails, issueSource) {
351
- const url = `${baseUrl}&body=${encodeURIComponent(body)}`;
352
- return this.addTemplateToUrl(url, gitHubDetails?.owner, gitHubDetails?.repositoryName, issueSource);
353
- }
354
- getIssueTarget(data) {
355
- const selectedExtension = this.getSelectedExtension(data);
356
- if (data.issueSource === IssueSource.Extension && selectedExtension) {
357
- const extensionUrl = this.getExtensionIssueUrl(selectedExtension);
358
- if (!extensionUrl) {
359
- return undefined;
360
- }
361
- return {
362
- url: extensionUrl,
363
- external: !this.isGitHubUrl(extensionUrl)
364
- };
365
- }
366
- if (data.issueSource === IssueSource.Marketplace) {
367
- const marketplaceIssueUrl = product.reportMarketplaceIssueUrl ?? product.reportIssueUrl;
368
- return marketplaceIssueUrl ? {
369
- url: marketplaceIssueUrl,
370
- external: false
371
- } : undefined;
372
- }
373
- if (data.uri) {
374
- const url = ( URI.revive(data.uri).toString());
375
- return {
376
- url,
377
- external: !this.isGitHubUrl(url)
378
- };
379
- }
380
- if (data.privateUri) {
381
- const url = ( URI.revive(data.privateUri).toString());
382
- return {
383
- url,
384
- external: !this.isGitHubUrl(url)
385
- };
386
- }
387
- return product.reportIssueUrl ? {
388
- url: product.reportIssueUrl,
389
- external: false
390
- } : undefined;
391
- }
392
- getSelectedExtension(data) {
393
- return data.extensionId ? data.enabledExtensions.find(ext => ext.id.toLowerCase() === data.extensionId?.toLowerCase()) : undefined;
394
- }
395
- getExtensionIssueUrl(extension) {
396
- if (extension.uri) {
397
- return ( URI.revive(extension.uri).toString());
398
- }
399
- if (extension.bugsUrl && /^https?:\/\/github\.com\/([^\/]*)\/([^\/]*)\/?(\/issues)?\/?$/.test(extension.bugsUrl)) {
400
- return `${normalizeGitHubUrl(extension.bugsUrl)}/issues/new`;
401
- }
402
- if (extension.repositoryUrl && /^https?:\/\/github\.com\/([^\/]*)\/([^\/]*)\/?$/.test(extension.repositoryUrl)) {
403
- return `${normalizeGitHubUrl(extension.repositoryUrl)}/issues/new`;
404
- }
405
- return extension.bugsUrl || extension.repositoryUrl;
406
- }
407
- isGitHubUrl(url) {
408
- return /^https?:\/\/github\.com\//i.test(url);
409
- }
410
- parseGitHubUrl(url) {
411
- const match = /^https?:\/\/github\.com\/([^\/?#]+)\/([^\/?#]+).*/i.exec(url);
412
- if (!match) {
413
- return undefined;
414
- }
415
- return {
416
- owner: match[1],
417
- repositoryName: match[2]
418
- };
419
- }
420
- getIssueUrlWithTitle(issueTitle, issueUrl) {
421
- if (this.isGitHubUrl(issueUrl) && !/\/issues\/new(?:[?#].*)?$/i.test(issueUrl)) {
422
- issueUrl = `${normalizeGitHubUrl(issueUrl)}/issues/new`;
423
- }
424
- const queryStringPrefix = ( issueUrl.indexOf("?")) === -1 ? "?" : "&";
425
- return `${issueUrl}${queryStringPrefix}title=${encodeURIComponent(issueTitle)}`;
426
- }
427
- addTemplateToUrl(baseUrl, owner, repositoryName, issueSource) {
428
- const needsTemplate = issueSource === IssueSource.VSCode || issueSource === IssueSource.AgentsWindow || (owner?.toLowerCase() === "microsoft" && repositoryName?.toLowerCase() === "vscode");
429
- if (!needsTemplate) {
430
- return baseUrl;
431
- }
432
- try {
433
- const url = ( new URL(baseUrl));
452
+ const url = ( new URL(baseUrl));
453
+ url.searchParams.set("body", body);
454
+ const owner = gitHubDetails?.owner.toLowerCase();
455
+ const repositoryName = gitHubDetails?.repositoryName.toLowerCase();
456
+ const needsTemplate = owner === "microsoft" && (repositoryName === "vscode" || (repositoryName === "vscode-internalbacklog" && (issueSource === IssueSource.VSCode || issueSource === IssueSource.AgentsWindow)));
457
+ if (needsTemplate && !( url.searchParams.has("template"))) {
434
458
  url.searchParams.set("template", "bug_report.md");
435
- return ( url.toString());
436
- } catch {
437
- return `${baseUrl}&template=bug_report.md`;
438
459
  }
460
+ return ( url.toString());
439
461
  }
440
462
  dataUrlToBytes(dataUrl) {
441
463
  const commaIndex = ( dataUrl.indexOf(","));
@@ -555,17 +577,17 @@ let IssueFormService = class IssueFormService extends Disposable {
555
577
  await this.dialogService.prompt({
556
578
  type: Severity.Warning,
557
579
  message: ( localize(
558
- 18079,
580
+ 20894,
559
581
  "Your input will not be saved. Are you sure you want to close this window?"
560
582
  )),
561
583
  buttons: [{
562
- label: ( localize(18080, "&&Yes")),
584
+ label: ( localize(20895, "&&Yes")),
563
585
  run: () => {
564
586
  this.closeReporter();
565
587
  this.issueReporterWindow = null;
566
588
  }
567
589
  }, {
568
- label: ( localize(18081, "Cancel")),
590
+ label: ( localize(20896, "Cancel")),
569
591
  run: () => {}
570
592
  }]
571
593
  });
@@ -575,16 +597,16 @@ let IssueFormService = class IssueFormService extends Disposable {
575
597
  await this.dialogService.prompt({
576
598
  type: Severity.Warning,
577
599
  message: ( localize(
578
- 18082,
600
+ 20897,
579
601
  "There is too much data to send to GitHub directly. The data will be copied to the clipboard, please paste it into the GitHub issue page that is opened."
580
602
  )),
581
603
  buttons: [{
582
- label: ( localize(18083, "&&OK")),
604
+ label: ( localize(20898, "&&OK")),
583
605
  run: () => {
584
606
  result = true;
585
607
  }
586
608
  }, {
587
- label: ( localize(18081, "Cancel")),
609
+ label: ( localize(20896, "Cancel")),
588
610
  run: () => {
589
611
  result = false;
590
612
  }
@@ -605,6 +627,6 @@ let IssueFormService = class IssueFormService extends Disposable {
605
627
  return false;
606
628
  }
607
629
  };
608
- IssueFormService = ( __decorate([( __param(0, IInstantiationService)), ( __param(1, IAuxiliaryWindowService)), ( __param(2, IMenuService)), ( __param(3, IContextKeyService)), ( __param(4, ILogService)), ( __param(5, IDialogService)), ( __param(6, IHostService)), ( __param(7, IOpenerService)), ( __param(8, IFileService)), ( __param(9, IGitHubUploadService)), ( __param(10, IEditorService)), ( __param(11, IClipboardService)), ( __param(12, IGitHubService))], IssueFormService));
630
+ IssueFormService = ( __decorate([( __param(0, IInstantiationService)), ( __param(1, IAuxiliaryWindowService)), ( __param(2, IMenuService)), ( __param(3, IContextKeyService)), ( __param(4, ILogService)), ( __param(5, IDialogService)), ( __param(6, IHostService)), ( __param(7, IOpenerService)), ( __param(8, IFileService)), ( __param(9, IGitHubUploadService)), ( __param(10, IEditorService)), ( __param(11, IClipboardService)), ( __param(12, IWorkbenchGitHubService))], IssueFormService));
609
631
 
610
632
  export { IssueFormService, extractIssueData };
@@ -0,0 +1,36 @@
1
+ import { VSBuffer } from "@codingame/monaco-vscode-api/vscode/vs/base/common/buffer";
2
+ import { CancellationToken } from "@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation";
3
+ import { IIssueReporterScreenshot } from "../common/issue.js";
4
+ export declare const MAX_ISSUE_ATTACHMENTS = 5;
5
+ export declare const MAX_ISSUE_IMAGE_BYTES: number;
6
+ export declare const MAX_ISSUE_VIDEO_BYTES: number;
7
+ export declare const MAX_ISSUE_FILE_BYTES: number;
8
+ export interface IIssueReporterMediaFormat {
9
+ readonly kind: "image" | "video" | "file";
10
+ readonly mimeType: string;
11
+ readonly extension: string;
12
+ readonly maxBytes: number;
13
+ }
14
+ export interface IIssueReporterVideoMetadata {
15
+ readonly width: number;
16
+ readonly height: number;
17
+ readonly durationMs?: number;
18
+ readonly thumbnailDataUrl: string;
19
+ }
20
+ export declare function getIssueReporterMediaFormat(name: string, type?: string): IIssueReporterMediaFormat;
21
+ export declare function getIssueReporterScreenshotFile(screenshot: IIssueReporterScreenshot, screenshotNumber: number): {
22
+ dataUrl: string;
23
+ name: string;
24
+ format: IIssueReporterMediaFormat;
25
+ };
26
+ export declare function validateIssueReporterMediaFile(file: Pick<File, "name" | "type" | "size">): IIssueReporterMediaFormat;
27
+ export declare function readIssueReporterMediaFile(file: File, token: CancellationToken): Promise<{
28
+ format: IIssueReporterMediaFormat;
29
+ bytes: VSBuffer;
30
+ durationMs?: number;
31
+ }>;
32
+ export declare function readIssueReporterImage(dataUrl: string, token: CancellationToken, createImage?: () => HTMLImageElement): Promise<{
33
+ width: number;
34
+ height: number;
35
+ }>;
36
+ export declare function readIssueReporterVideo(source: string, token: CancellationToken, createVideo?: () => HTMLVideoElement): Promise<IIssueReporterVideoMetadata>;