@codingame/monaco-vscode-issue-service-override 38.1.2 → 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.
@@ -0,0 +1,157 @@
1
+
2
+ import { distinct } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
3
+ import { isEqual } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
4
+ import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
5
+ import { IssueSource } from './issue.js';
6
+ import { normalizeGitHubUrl } from './issueReporterUtil.js';
7
+
8
+ const issueReporterRepositoryPattern = "^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38}/(?!\\.{1,2}$)[a-zA-Z0-9_.-]{1,100}$(?![\\r\\n])";
9
+ const repositoryNameRegex = ( new RegExp(issueReporterRepositoryPattern));
10
+ function parseIssueReporterRepositories(value) {
11
+ if (value === undefined) {
12
+ return [];
13
+ }
14
+ if (!Array.isArray(value) || ( value.some(entry => typeof entry !== "string" || !repositoryNameRegex.test(entry)))) {
15
+ throw ( new Error(
16
+ "Additional issue repositories must be an array of GitHub repositories in owner/repo format."
17
+ ));
18
+ }
19
+ return distinct(value, entry => entry.toLowerCase());
20
+ }
21
+ function parseGitHubRepository(url) {
22
+ const match = /^https?:\/\/github\.com\/(?<owner>[^/?#]+)\/(?<repository>[^/?#]+)(?<path>[^?#]*)/i.exec(url);
23
+ if (!match?.groups || url.includes("\\") || ( match.groups.path.split("/").some(segment => segment === "." || segment === ".." || segment.includes("%")))) {
24
+ return undefined;
25
+ }
26
+ const {
27
+ owner,
28
+ repository
29
+ } = match.groups;
30
+ const repositoryName = !match.groups.path || match.groups.path === "/" ? repository.replace(/\.git$/, "") : repository;
31
+ return repositoryNameRegex.test(`${owner}/${repositoryName}`) ? {
32
+ owner,
33
+ repositoryName
34
+ } : undefined;
35
+ }
36
+ function isPublicVSCodeIssueUrl(url) {
37
+ const repository = url ? parseGitHubRepository(url) : undefined;
38
+ return repository?.owner.toLowerCase() === "microsoft" && repository.repositoryName.toLowerCase() === "vscode";
39
+ }
40
+ function getExtensionIssueUrl(extension) {
41
+ if (extension.uri) {
42
+ return ( URI.revive(extension.uri).toString(true));
43
+ }
44
+ if (extension.bugsUrl && /^https?:\/\/github\.com\/([^/]*)\/([^/]*)\/?(\/issues)?\/?$/.test(extension.bugsUrl)) {
45
+ return `${normalizeGitHubUrl(extension.bugsUrl)}/issues/new`;
46
+ }
47
+ if (extension.repositoryUrl && /^https?:\/\/github\.com\/([^/]*)\/([^/]*)\/?$/.test(extension.repositoryUrl)) {
48
+ return `${normalizeGitHubUrl(extension.repositoryUrl)}/issues/new`;
49
+ }
50
+ return extension.bugsUrl || extension.repositoryUrl;
51
+ }
52
+ function createIssueReporterTarget(url, privateUrl) {
53
+ if (!url || !/^https?:\/\//i.test(url) || url.includes("\\")) {
54
+ return undefined;
55
+ }
56
+ let parsed;
57
+ try {
58
+ parsed = ( new URL(url));
59
+ } catch {
60
+ return undefined;
61
+ }
62
+ if (parsed.username || parsed.password) {
63
+ return undefined;
64
+ }
65
+ const repository = parseGitHubRepository(url);
66
+ if (parsed.hostname.toLowerCase() === "github.com" && !repository) {
67
+ return undefined;
68
+ }
69
+ const isPublic = isPublicVSCodeIssueUrl(url) || (repository?.owner.toLowerCase() === "microsoft" && repository.repositoryName.toLowerCase() === "vsmarketplace");
70
+ const privateRepository = privateUrl ? parseGitHubRepository(privateUrl) : undefined;
71
+ const isPrivate = !isPublic && ((repository?.owner.toLowerCase() === "microsoft" && repository.repositoryName.toLowerCase() === "vscode-internalbacklog") || (!!privateUrl && (repository && privateRepository ? repository.owner.toLowerCase() === privateRepository.owner.toLowerCase() && repository.repositoryName.toLowerCase() === privateRepository.repositoryName.toLowerCase() : isEqual(( URI.parse(url)), ( URI.parse(privateUrl))))));
72
+ return {
73
+ url,
74
+ repository,
75
+ isPrivate,
76
+ isPublic,
77
+ external: !repository
78
+ };
79
+ }
80
+ function getDefaultIssueReporterTarget(data, product) {
81
+ let url;
82
+ let privateUrl;
83
+ if (data.issueSource === IssueSource.Extension) {
84
+ const extension = data.enabledExtensions.find(
85
+ extension => extension.id.toLowerCase() === data.extensionId?.toLowerCase()
86
+ );
87
+ if (!extension) {
88
+ return undefined;
89
+ }
90
+ url = getExtensionIssueUrl(extension);
91
+ privateUrl = URI.revive(extension.privateUri)?.toString(true);
92
+ } else if (data.issueSource === IssueSource.Marketplace) {
93
+ url = product.reportMarketplaceIssueUrl ?? product.reportIssueUrl;
94
+ } else {
95
+ privateUrl = URI.revive(data.privateUri)?.toString(true);
96
+ url = URI.revive(data.uri)?.toString(true) ?? product.reportIssueUrl;
97
+ }
98
+ const target = createIssueReporterTarget(url, privateUrl);
99
+ return target && {
100
+ ...target,
101
+ external: target.external && (data.issueSource === IssueSource.Extension || (data.issueSource !== IssueSource.Marketplace && !!data.uri))
102
+ };
103
+ }
104
+ function supportsRepositorySelection(data, target) {
105
+ return data.issueSource !== IssueSource.Extension && data.issueSource !== IssueSource.Marketplace && !!target && isPublicVSCodeIssueUrl(target.url);
106
+ }
107
+ function getIssueReporterRepositoryChoices(data, product) {
108
+ const defaultTarget = getDefaultIssueReporterTarget(data, product);
109
+ if (!defaultTarget) {
110
+ return [];
111
+ }
112
+ if (!supportsRepositorySelection(data, defaultTarget)) {
113
+ return [defaultTarget];
114
+ }
115
+ let repositories;
116
+ try {
117
+ repositories = parseIssueReporterRepositories(data.additionalRepositories);
118
+ } catch {
119
+ return [];
120
+ }
121
+ const choices = [defaultTarget];
122
+ const privateUrl = URI.revive(data.privateUri)?.toString(true);
123
+ const privateTarget = createIssueReporterTarget(privateUrl, privateUrl);
124
+ if (privateTarget?.repository && privateTarget.isPrivate) {
125
+ choices.push(privateTarget);
126
+ }
127
+ for (const repository of repositories) {
128
+ choices.push(createIssueReporterTarget(`https://github.com/${repository}/issues/new`));
129
+ }
130
+ return distinct(
131
+ choices,
132
+ target => `${target.repository.owner}/${target.repository.repositoryName}`.toLowerCase()
133
+ );
134
+ }
135
+ function resolveIssueReporterTarget(data, product) {
136
+ const defaultTarget = getDefaultIssueReporterTarget(data, product);
137
+ if (data.issueRepository === undefined || !supportsRepositorySelection(data, defaultTarget)) {
138
+ return defaultTarget;
139
+ }
140
+ if (!repositoryNameRegex.test(data.issueRepository)) {
141
+ return undefined;
142
+ }
143
+ return getIssueReporterRepositoryChoices(data, product).find(
144
+ target => `${target.repository?.owner}/${target.repository?.repositoryName}`.toLowerCase() === data.issueRepository.toLowerCase()
145
+ );
146
+ }
147
+ function getIssueReporterUrlWithTitle(issueTitle, issueUrl) {
148
+ const repository = parseGitHubRepository(issueUrl);
149
+ const url = ( new URL(issueUrl));
150
+ if (repository) {
151
+ url.pathname = `/${repository.owner}/${repository.repositoryName}/issues/new`;
152
+ }
153
+ url.searchParams.set("title", issueTitle);
154
+ return ( url.toString());
155
+ }
156
+
157
+ export { getIssueReporterRepositoryChoices, getIssueReporterUrlWithTitle, isPublicVSCodeIssueUrl, issueReporterRepositoryPattern, parseGitHubRepository, parseIssueReporterRepositories, resolveIssueReporterTarget };