@gitkraken/core-gitlens 0.59.0 → 0.60.1
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.
- package/CHANGELOG.md +15 -1
- package/dist/plus/integrations/index.d.ts +2 -1
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +7 -0
- package/dist/plus/integrations/integrationService.js +36 -0
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +6 -0
- package/dist/plus/integrations/models/gitlabIssueWrites.d.ts +86 -0
- package/dist/plus/integrations/models/gitlabIssueWrites.js +9 -0
- package/dist/plus/integrations/models/gitlabIssueWrites.js.map +1 -0
- package/dist/plus/integrations/models/publicIntegration.d.ts +1 -0
- package/dist/plus/integrations/providers/azurePullRequestWrites.js +2 -1
- package/dist/plus/integrations/providers/azurePullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +4 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.js +4 -0
- package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/issueWriteErrors.d.ts +11 -0
- package/dist/plus/integrations/providers/gitlab/issueWriteErrors.js +73 -0
- package/dist/plus/integrations/providers/gitlab/issueWriteErrors.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab/issueWrites.d.ts +33 -0
- package/dist/plus/integrations/providers/gitlab/issueWrites.js +325 -0
- package/dist/plus/integrations/providers/gitlab/issueWrites.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab.d.ts +7 -1
- package/dist/plus/integrations/providers/gitlab.js +24 -0
- package/dist/plus/integrations/providers/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
- package/dist/plus/integrations/reads/drains.d.ts +1 -0
- package/docs/integrations.md +28 -2
- package/package.json +1 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { sessionExpiry } from "../../authentication/models.js";
|
|
2
|
+
import { gitLabIssueWriteBaseUrl, isGitLabDecimalId } from "../../models/gitlabIssueWrites.js";
|
|
3
|
+
import { GitLabIssueWriteError, gitLabIssueWriteFailure, toGitLabIssueHttpFailure } from "./issueWriteErrors.js";
|
|
4
|
+
import * as l10n from "@vscode/l10n";
|
|
5
|
+
//#region ../plus/integrations/src/providers/gitlab/issueWrites.ts
|
|
6
|
+
const projectPathPattern = /^[\w.-]+(?:\/[\w.-]+)+$/;
|
|
7
|
+
const projectGidPrefix = "gid://gitlab/Project/";
|
|
8
|
+
const issueGidPrefix = "gid://gitlab/Issue/";
|
|
9
|
+
const workItemGidPrefix = "gid://gitlab/WorkItem/";
|
|
10
|
+
const createFields = [{
|
|
11
|
+
id: "title",
|
|
12
|
+
required: true
|
|
13
|
+
}, {
|
|
14
|
+
id: "description",
|
|
15
|
+
required: false
|
|
16
|
+
}];
|
|
17
|
+
const editFields = [{
|
|
18
|
+
id: "title",
|
|
19
|
+
required: false
|
|
20
|
+
}, {
|
|
21
|
+
id: "description",
|
|
22
|
+
required: false
|
|
23
|
+
}];
|
|
24
|
+
const createPermissionsQuery = `query IssueCreatePermissions($path: ID!) {
|
|
25
|
+
project(fullPath: $path) { id userPermissions { createIssue } }
|
|
26
|
+
}`;
|
|
27
|
+
const issuePermissionsQuery = `query IssueWritePermissions($path: ID!, $iid: String!, $id: WorkItemID!) {
|
|
28
|
+
project(fullPath: $path) {
|
|
29
|
+
id
|
|
30
|
+
issue(iid: $iid) { id userPermissions { updateIssue reopenIssue } }
|
|
31
|
+
}
|
|
32
|
+
workItem(id: $id) { id userPermissions { deleteWorkItem } }
|
|
33
|
+
}`;
|
|
34
|
+
function restId(value) {
|
|
35
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? String(value) : void 0;
|
|
36
|
+
}
|
|
37
|
+
function isProjectPath(value) {
|
|
38
|
+
return typeof value === "string" && projectPathPattern.test(value) && value.split("/").every((segment) => segment !== "." && segment !== "..");
|
|
39
|
+
}
|
|
40
|
+
function isGitLabUrl(url) {
|
|
41
|
+
if (typeof url !== "string") return false;
|
|
42
|
+
const parsed = URL.parse(url);
|
|
43
|
+
return parsed?.origin === "https://gitlab.com" && !parsed.username && !parsed.password;
|
|
44
|
+
}
|
|
45
|
+
function issueReceipt(raw, project, iid, expectedId) {
|
|
46
|
+
const id = restId(raw?.id);
|
|
47
|
+
const actualIid = restId(raw?.iid);
|
|
48
|
+
if (id == null || actualIid == null || !isGitLabUrl(raw.web_url) || typeof raw.title !== "string" || raw.description !== null && typeof raw.description !== "string" || raw.state !== "opened" && raw.state !== "closed") throw new GitLabIssueWriteError("unknown");
|
|
49
|
+
if (restId(raw.project_id) !== project.id || iid != null && iid !== actualIid || expectedId != null && expectedId !== id) throw new GitLabIssueWriteError("conflict");
|
|
50
|
+
if (typeof raw.issue_type !== "string") throw new GitLabIssueWriteError("unknown");
|
|
51
|
+
if (raw.issue_type !== "issue") throw new GitLabIssueWriteError("unsupported");
|
|
52
|
+
return {
|
|
53
|
+
id,
|
|
54
|
+
iid: actualIid,
|
|
55
|
+
url: raw.web_url,
|
|
56
|
+
title: raw.title,
|
|
57
|
+
description: raw.description ?? "",
|
|
58
|
+
state: raw.state
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function allowed(value) {
|
|
62
|
+
return value ? { allowed: true } : {
|
|
63
|
+
allowed: false,
|
|
64
|
+
reason: "forbidden"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function transition(permission, currentState, requiredState) {
|
|
68
|
+
return permission.allowed && currentState !== requiredState ? {
|
|
69
|
+
allowed: false,
|
|
70
|
+
reason: "transition-unavailable"
|
|
71
|
+
} : permission;
|
|
72
|
+
}
|
|
73
|
+
function validateFields(action, title, description) {
|
|
74
|
+
if ((action === "create" || title !== void 0) && (typeof title !== "string" || !title.trim())) return gitLabIssueWriteFailure("invalid-input", { title: l10n.t("Title is required") });
|
|
75
|
+
if (description !== void 0 && typeof description !== "string" || title === void 0 && description === void 0) return gitLabIssueWriteFailure("invalid-input");
|
|
76
|
+
if (description != null && /^\/[\w+-]+(?=\s|$)/m.test(description.replaceAll("\r", ""))) return gitLabIssueWriteFailure("provider-policy", { description: l10n.t("GitLab quick actions are unavailable in issue descriptions.") });
|
|
77
|
+
}
|
|
78
|
+
var GitLabIssueWriter = class {
|
|
79
|
+
config;
|
|
80
|
+
scope;
|
|
81
|
+
session;
|
|
82
|
+
isCurrent;
|
|
83
|
+
isRetired;
|
|
84
|
+
constructor(config, scope, session, isCurrent, isRetired) {
|
|
85
|
+
this.config = config;
|
|
86
|
+
this.scope = scope;
|
|
87
|
+
this.session = session;
|
|
88
|
+
this.isCurrent = isCurrent;
|
|
89
|
+
this.isRetired = isRetired;
|
|
90
|
+
}
|
|
91
|
+
async getCreateOptions(options) {
|
|
92
|
+
const { context, account, policyAllowsWrites } = await this.readProject(options.project);
|
|
93
|
+
const unavailable = this.getWriteRefusal(account, policyAllowsWrites);
|
|
94
|
+
let capability;
|
|
95
|
+
if (unavailable != null) capability = unavailable;
|
|
96
|
+
else {
|
|
97
|
+
const create = (await this.readPermissions(createPermissionsQuery, { path: context.project.fullPath }, context.project)).project?.userPermissions?.createIssue;
|
|
98
|
+
if (typeof create !== "boolean") throw new GitLabIssueWriteError("unknown");
|
|
99
|
+
capability = allowed(create);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...context,
|
|
103
|
+
ok: true,
|
|
104
|
+
fields: capability.allowed ? createFields : [],
|
|
105
|
+
createCapability: capability
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async getIssueOptions(options) {
|
|
109
|
+
const { project, iid, expectedIssueId } = options;
|
|
110
|
+
if (!isGitLabDecimalId(iid) || expectedIssueId !== void 0 && !isGitLabDecimalId(expectedIssueId)) throw new GitLabIssueWriteError("invalid-input");
|
|
111
|
+
const { context, account, policyAllowsWrites } = await this.readProject(project);
|
|
112
|
+
const issue = issueReceipt(await this.read(`/api/v4/projects/${context.project.id}/issues/${iid}`), context.project, iid, expectedIssueId);
|
|
113
|
+
const capabilities = await this.getIssueCapabilities(context.project, issue, this.getWriteRefusal(account, policyAllowsWrites));
|
|
114
|
+
return {
|
|
115
|
+
...context,
|
|
116
|
+
ok: true,
|
|
117
|
+
issue,
|
|
118
|
+
fields: capabilities.edit.allowed ? editFields : [],
|
|
119
|
+
capabilities
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async resolveTarget(options) {
|
|
123
|
+
if (options.intent !== void 0 && options.intent !== "delete") return gitLabIssueWriteFailure("invalid-input");
|
|
124
|
+
const { fields: _fields, capabilities, ...target } = await this.getIssueOptions(options);
|
|
125
|
+
return options.intent === "delete" && !capabilities.delete.allowed ? gitLabIssueWriteFailure(capabilities.delete.reason) : target;
|
|
126
|
+
}
|
|
127
|
+
async write(input) {
|
|
128
|
+
if (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId)) return gitLabIssueWriteFailure("invalid-input");
|
|
129
|
+
if (input.action === "create") {
|
|
130
|
+
const { title, description } = input;
|
|
131
|
+
const invalid = validateFields("create", title, description);
|
|
132
|
+
if (invalid != null) return invalid;
|
|
133
|
+
const { fields: _fields, createCapability, ...target } = await this.getCreateOptions({
|
|
134
|
+
...input,
|
|
135
|
+
project: input.projectId
|
|
136
|
+
});
|
|
137
|
+
if (!createCapability.allowed) return gitLabIssueWriteFailure(createCapability.reason);
|
|
138
|
+
return this.mutate("POST", target.project, void 0, {
|
|
139
|
+
title,
|
|
140
|
+
description
|
|
141
|
+
}, async (response) => ({
|
|
142
|
+
...target,
|
|
143
|
+
issue: issueReceipt(await response.json(), target.project)
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
const action = input.action;
|
|
147
|
+
if (action !== "edit" && action !== "close" && action !== "reopen") return gitLabIssueWriteFailure("invalid-input");
|
|
148
|
+
if (!isGitLabDecimalId(input.expectedIssueId)) return gitLabIssueWriteFailure("invalid-input");
|
|
149
|
+
let fields;
|
|
150
|
+
if (action === "edit") {
|
|
151
|
+
const { title, description } = input;
|
|
152
|
+
const invalid = validateFields(action, title, description);
|
|
153
|
+
if (invalid != null) return invalid;
|
|
154
|
+
fields = {
|
|
155
|
+
title,
|
|
156
|
+
description
|
|
157
|
+
};
|
|
158
|
+
} else fields = { state_event: action };
|
|
159
|
+
const { fields: _fields, capabilities, ...target } = await this.getIssueOptions({
|
|
160
|
+
...input,
|
|
161
|
+
project: input.projectId
|
|
162
|
+
});
|
|
163
|
+
const capability = capabilities[action];
|
|
164
|
+
if (!capability.allowed) return gitLabIssueWriteFailure(capability.reason);
|
|
165
|
+
const { issue, project } = target;
|
|
166
|
+
return this.mutate("PUT", project, issue.iid, fields, async (response) => {
|
|
167
|
+
const updated = issueReceipt(await response.json(), project, issue.iid, issue.id);
|
|
168
|
+
if (action === "close" && updated.state !== "closed" || action === "reopen" && updated.state !== "opened") return {
|
|
169
|
+
ok: false,
|
|
170
|
+
reason: "unknown",
|
|
171
|
+
applied: "maybe"
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
...target,
|
|
175
|
+
issue: updated
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async delete(input) {
|
|
180
|
+
if (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId) || !isGitLabDecimalId(input.expectedIssueId)) return gitLabIssueWriteFailure("invalid-input");
|
|
181
|
+
const result = await this.resolveTarget({
|
|
182
|
+
...input,
|
|
183
|
+
project: input.projectId,
|
|
184
|
+
intent: "delete"
|
|
185
|
+
});
|
|
186
|
+
if (!result.ok) return result;
|
|
187
|
+
return this.mutate("DELETE", result.project, result.issue.iid, void 0, () => result);
|
|
188
|
+
}
|
|
189
|
+
async readProject(project) {
|
|
190
|
+
if (!isGitLabDecimalId(project) && !isProjectPath(project)) throw new GitLabIssueWriteError("invalid-input");
|
|
191
|
+
const account = await this.readAccount();
|
|
192
|
+
const raw = await this.read(`/api/v4/projects/${encodeURIComponent(project)}`);
|
|
193
|
+
const id = restId(raw?.id);
|
|
194
|
+
if (id == null || !isProjectPath(raw.path_with_namespace) || !isGitLabUrl(raw.web_url) || typeof raw.archived !== "boolean") throw new GitLabIssueWriteError("unknown");
|
|
195
|
+
if (isGitLabDecimalId(project) ? id !== project : raw.path_with_namespace.toLowerCase() !== project.toLowerCase()) throw new GitLabIssueWriteError("conflict");
|
|
196
|
+
const { providerId, connectionId, baseUrl } = this.scope;
|
|
197
|
+
return {
|
|
198
|
+
account,
|
|
199
|
+
context: {
|
|
200
|
+
providerId,
|
|
201
|
+
connectionId,
|
|
202
|
+
baseUrl,
|
|
203
|
+
accountId: account.id,
|
|
204
|
+
project: {
|
|
205
|
+
id,
|
|
206
|
+
fullPath: raw.path_with_namespace,
|
|
207
|
+
url: raw.web_url
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
policyAllowsWrites: !raw.archived && !raw.marked_for_deletion_on && raw.issues_enabled !== false && raw.issues_access_level !== "disabled"
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async readAccount() {
|
|
214
|
+
const personal = this.session.type === "pat";
|
|
215
|
+
const raw = await this.read(personal ? "/api/v4/personal_access_tokens/self" : "/oauth/token/info");
|
|
216
|
+
const id = restId(personal ? raw?.user_id : raw?.resource_owner_id);
|
|
217
|
+
const scopes = personal ? raw?.scopes : raw?.scope;
|
|
218
|
+
if (id == null || !Array.isArray(scopes) || !scopes.every((s) => typeof s === "string")) throw new GitLabIssueWriteError("unknown");
|
|
219
|
+
if (this.scope.expectedAccountId !== void 0 && this.scope.expectedAccountId !== id) throw new GitLabIssueWriteError("no-connection");
|
|
220
|
+
return {
|
|
221
|
+
id,
|
|
222
|
+
canWrite: scopes.includes("api")
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
getWriteRefusal(account, policyAllowsWrites) {
|
|
226
|
+
if (!account.canWrite) return {
|
|
227
|
+
allowed: false,
|
|
228
|
+
reason: "insufficient-scope"
|
|
229
|
+
};
|
|
230
|
+
if (!policyAllowsWrites) return {
|
|
231
|
+
allowed: false,
|
|
232
|
+
reason: "provider-policy"
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async getIssueCapabilities(project, issue, unavailable) {
|
|
236
|
+
if (unavailable != null) return {
|
|
237
|
+
edit: unavailable,
|
|
238
|
+
close: unavailable,
|
|
239
|
+
reopen: unavailable,
|
|
240
|
+
delete: unavailable
|
|
241
|
+
};
|
|
242
|
+
const id = `${workItemGidPrefix}${issue.id}`;
|
|
243
|
+
const data = await this.readPermissions(issuePermissionsQuery, {
|
|
244
|
+
path: project.fullPath,
|
|
245
|
+
iid: issue.iid,
|
|
246
|
+
id
|
|
247
|
+
}, project);
|
|
248
|
+
if (data.project?.issue?.id !== `${issueGidPrefix}${issue.id}` || data.workItem?.id !== id) throw new GitLabIssueWriteError("conflict");
|
|
249
|
+
const { updateIssue, reopenIssue } = data.project.issue.userPermissions ?? {};
|
|
250
|
+
const canDelete = data.workItem.userPermissions?.deleteWorkItem;
|
|
251
|
+
if (typeof updateIssue !== "boolean" || typeof reopenIssue !== "boolean" || typeof canDelete !== "boolean") throw new GitLabIssueWriteError("unknown");
|
|
252
|
+
const edit = allowed(updateIssue);
|
|
253
|
+
return {
|
|
254
|
+
edit,
|
|
255
|
+
close: transition(edit, issue.state, "opened"),
|
|
256
|
+
reopen: transition(allowed(updateIssue && reopenIssue), issue.state, "closed"),
|
|
257
|
+
delete: allowed(canDelete)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
async readPermissions(query, variables, project) {
|
|
261
|
+
const reply = await this.read("/api/graphql", {
|
|
262
|
+
method: "POST",
|
|
263
|
+
body: JSON.stringify({
|
|
264
|
+
query,
|
|
265
|
+
variables
|
|
266
|
+
})
|
|
267
|
+
});
|
|
268
|
+
if (reply?.data == null || reply.errors?.length) throw new GitLabIssueWriteError("unknown");
|
|
269
|
+
if (reply.data.project?.id !== `${projectGidPrefix}${project.id}`) throw new GitLabIssueWriteError("conflict");
|
|
270
|
+
return reply.data;
|
|
271
|
+
}
|
|
272
|
+
async read(path, init) {
|
|
273
|
+
if (!this.canUseSession()) throw new GitLabIssueWriteError("no-connection");
|
|
274
|
+
const response = await this.request(path, init);
|
|
275
|
+
if (!response.ok) {
|
|
276
|
+
const failure = await toGitLabIssueHttpFailure(response, false);
|
|
277
|
+
throw new GitLabIssueWriteError(failure.reason);
|
|
278
|
+
}
|
|
279
|
+
return await response.json();
|
|
280
|
+
}
|
|
281
|
+
async mutate(method, project, iid, body, receipt) {
|
|
282
|
+
if (!await this.isCurrent() || !this.canUseSession()) return gitLabIssueWriteFailure("no-connection");
|
|
283
|
+
const path = `/api/v4/projects/${project.id}/issues${iid == null ? "" : `/${iid}`}`;
|
|
284
|
+
const status = method === "POST" ? 201 : method === "PUT" ? 200 : 204;
|
|
285
|
+
try {
|
|
286
|
+
const response = await this.request(path, {
|
|
287
|
+
method,
|
|
288
|
+
body: body == null ? void 0 : JSON.stringify(body)
|
|
289
|
+
});
|
|
290
|
+
if (!response.ok) return await toGitLabIssueHttpFailure(response, true);
|
|
291
|
+
if (response.status === status) return await receipt(response);
|
|
292
|
+
} catch {
|
|
293
|
+
return {
|
|
294
|
+
ok: false,
|
|
295
|
+
reason: "unknown",
|
|
296
|
+
applied: "maybe"
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
ok: false,
|
|
301
|
+
reason: "unknown",
|
|
302
|
+
applied: "maybe"
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
canUseSession() {
|
|
306
|
+
return !this.isRetired() && sessionExpiry(this.session.expiresAt) > Date.now();
|
|
307
|
+
}
|
|
308
|
+
request(path, init) {
|
|
309
|
+
const request = {
|
|
310
|
+
...init,
|
|
311
|
+
headers: {
|
|
312
|
+
Authorization: `Bearer ${this.session.accessToken}`,
|
|
313
|
+
...init?.body != null && { "Content-Type": "application/json" }
|
|
314
|
+
},
|
|
315
|
+
redirect: "error",
|
|
316
|
+
credentials: "omit",
|
|
317
|
+
cache: "no-store"
|
|
318
|
+
};
|
|
319
|
+
return this.config.fetch(`${gitLabIssueWriteBaseUrl}${path}`, request);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
//#endregion
|
|
323
|
+
export { GitLabIssueWriter };
|
|
324
|
+
|
|
325
|
+
//# sourceMappingURL=issueWrites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/gitlab/issueWrites.ts"],"sourcesContent":["import * as l10n from '@vscode/l10n';\nimport type { ProviderAuthenticationSession } from '../../authentication/models.js';\nimport { sessionExpiry } from '../../authentication/models.js';\nimport type {\n\tGitLabIssueCreateOptions,\n\tGitLabIssueCreateOptionsResult,\n\tGitLabIssueDeleteOptions,\n\tGitLabIssueReceipt,\n\tGitLabIssueWriteAddress,\n\tGitLabIssueWriteCapability,\n\tGitLabIssueWriteContext,\n\tGitLabIssueWriteFailure,\n\tGitLabIssueWriteField,\n\tGitLabIssueWriteOptions,\n\tGitLabIssueWriteOptionsResult,\n\tGitLabIssueWriteResult,\n\tGitLabIssueWriteScope,\n\tGitLabIssueWriteTargetOptions,\n} from '../../models/gitlabIssueWrites.js';\nimport { gitLabIssueWriteBaseUrl, isGitLabDecimalId } from '../../models/gitlabIssueWrites.js';\nimport type { ProviderApiConfig } from '../apiConfig.js';\nimport { GitLabIssueWriteError, gitLabIssueWriteFailure, toGitLabIssueHttpFailure } from './issueWriteErrors.js';\n\nconst projectPathPattern = /^[\\w.-]+(?:\\/[\\w.-]+)+$/;\nconst projectGidPrefix = 'gid://gitlab/Project/';\nconst issueGidPrefix = 'gid://gitlab/Issue/';\nconst workItemGidPrefix = 'gid://gitlab/WorkItem/';\nconst createFields = [\n\t{ id: 'title', required: true },\n\t{ id: 'description', required: false },\n] as const satisfies readonly GitLabIssueWriteField[];\nconst editFields = [\n\t{ id: 'title', required: false },\n\t{ id: 'description', required: false },\n] as const satisfies readonly GitLabIssueWriteField[];\n\nconst createPermissionsQuery = `query IssueCreatePermissions($path: ID!) {\n\tproject(fullPath: $path) { id userPermissions { createIssue } }\n}`;\nconst issuePermissionsQuery = `query IssueWritePermissions($path: ID!, $iid: String!, $id: WorkItemID!) {\n\tproject(fullPath: $path) {\n\t\tid\n\t\tissue(iid: $iid) { id userPermissions { updateIssue reopenIssue } }\n\t}\n\tworkItem(id: $id) { id userPermissions { deleteWorkItem } }\n}`;\n\ntype Project = GitLabIssueWriteContext['project'];\ntype RestProject = {\n\tid: unknown;\n\tpath_with_namespace: string;\n\tweb_url: string;\n\tarchived: boolean;\n\tissues_access_level?: string;\n\tissues_enabled?: boolean;\n\tmarked_for_deletion_on?: string | null;\n};\ntype RestIssue = {\n\tid: unknown;\n\tproject_id: unknown;\n\tiid: unknown;\n\tweb_url: string;\n\ttitle: string;\n\tdescription: string | null;\n\tstate: GitLabIssueReceipt['state'];\n\tissue_type: string;\n};\ntype Account = { id: string; canWrite: boolean };\ntype Permissions = {\n\tproject?: {\n\t\tid?: string;\n\t\tuserPermissions?: { createIssue?: boolean };\n\t\tissue?: { id?: string; userPermissions?: { updateIssue?: boolean; reopenIssue?: boolean } };\n\t};\n\tworkItem?: { id?: string; userPermissions?: { deleteWorkItem?: boolean } };\n};\ntype IssueOptionsSuccess = Extract<GitLabIssueWriteOptionsResult, { ok: true }>;\n\nfunction restId(value: unknown): string | undefined {\n\treturn typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? String(value) : undefined;\n}\n\nfunction isProjectPath(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tprojectPathPattern.test(value) &&\n\t\tvalue.split('/').every(segment => segment !== '.' && segment !== '..')\n\t);\n}\n\nfunction isGitLabUrl(url: unknown): url is string {\n\tif (typeof url !== 'string') return false;\n\n\tconst parsed = URL.parse(url);\n\treturn parsed?.origin === gitLabIssueWriteBaseUrl && !parsed.username && !parsed.password;\n}\n\nfunction issueReceipt(raw: RestIssue, project: Project, iid?: string, expectedId?: string): GitLabIssueReceipt {\n\tconst id = restId(raw?.id);\n\tconst actualIid = restId(raw?.iid);\n\tif (\n\t\tid == null ||\n\t\tactualIid == null ||\n\t\t!isGitLabUrl(raw.web_url) ||\n\t\ttypeof raw.title !== 'string' ||\n\t\t(raw.description !== null && typeof raw.description !== 'string') ||\n\t\t(raw.state !== 'opened' && raw.state !== 'closed')\n\t) {\n\t\tthrow new GitLabIssueWriteError('unknown');\n\t}\n\tif (\n\t\trestId(raw.project_id) !== project.id ||\n\t\t(iid != null && iid !== actualIid) ||\n\t\t(expectedId != null && expectedId !== id)\n\t) {\n\t\tthrow new GitLabIssueWriteError('conflict');\n\t}\n\tif (typeof raw.issue_type !== 'string') throw new GitLabIssueWriteError('unknown');\n\tif (raw.issue_type !== 'issue') throw new GitLabIssueWriteError('unsupported');\n\n\treturn {\n\t\tid: id,\n\t\tiid: actualIid,\n\t\turl: raw.web_url,\n\t\ttitle: raw.title,\n\t\tdescription: raw.description ?? '',\n\t\tstate: raw.state,\n\t};\n}\n\nfunction allowed(value: boolean): GitLabIssueWriteCapability {\n\treturn value ? { allowed: true } : { allowed: false, reason: 'forbidden' };\n}\n\nfunction transition(\n\tpermission: GitLabIssueWriteCapability,\n\tcurrentState: GitLabIssueReceipt['state'],\n\trequiredState: GitLabIssueReceipt['state'],\n): GitLabIssueWriteCapability {\n\treturn permission.allowed && currentState !== requiredState\n\t\t? { allowed: false, reason: 'transition-unavailable' }\n\t\t: permission;\n}\n\nfunction validateFields(\n\taction: 'create' | 'edit',\n\ttitle: string | undefined,\n\tdescription: string | undefined,\n): GitLabIssueWriteFailure | undefined {\n\tif ((action === 'create' || title !== undefined) && (typeof title !== 'string' || !title.trim())) {\n\t\treturn gitLabIssueWriteFailure('invalid-input', { title: l10n.t('Title is required') });\n\t}\n\tif (\n\t\t(description !== undefined && typeof description !== 'string') ||\n\t\t(title === undefined && description === undefined)\n\t) {\n\t\treturn gitLabIssueWriteFailure('invalid-input');\n\t}\n\t// SEE: GitLab REST interprets slash commands in issue descriptions, including commands that modify other fields.\n\tif (description != null && /^\\/[\\w+-]+(?=\\s|$)/m.test(description.replaceAll('\\r', ''))) {\n\t\treturn gitLabIssueWriteFailure('provider-policy', {\n\t\t\tdescription: l10n.t('GitLab quick actions are unavailable in issue descriptions.'),\n\t\t});\n\t}\n\n\treturn undefined;\n}\n\nexport class GitLabIssueWriter {\n\tconstructor(\n\t\tprivate readonly config: Pick<ProviderApiConfig, 'fetch'>,\n\t\tprivate readonly scope: GitLabIssueWriteScope,\n\t\tprivate readonly session: ProviderAuthenticationSession,\n\t\tprivate readonly isCurrent: () => Promise<boolean>,\n\t\tprivate readonly isRetired: () => boolean,\n\t) {}\n\n\tasync getCreateOptions(\n\t\toptions: GitLabIssueCreateOptions,\n\t): Promise<Extract<GitLabIssueCreateOptionsResult, { ok: true }>> {\n\t\tconst { context, account, policyAllowsWrites } = await this.readProject(options.project);\n\t\tconst unavailable = this.getWriteRefusal(account, policyAllowsWrites);\n\t\tlet capability: GitLabIssueWriteCapability;\n\t\tif (unavailable != null) {\n\t\t\tcapability = unavailable;\n\t\t} else {\n\t\t\tconst data = await this.readPermissions(\n\t\t\t\tcreatePermissionsQuery,\n\t\t\t\t{ path: context.project.fullPath },\n\t\t\t\tcontext.project,\n\t\t\t);\n\t\t\tconst create = data.project?.userPermissions?.createIssue;\n\t\t\tif (typeof create !== 'boolean') throw new GitLabIssueWriteError('unknown');\n\n\t\t\tcapability = allowed(create);\n\t\t}\n\n\t\treturn { ...context, ok: true, fields: capability.allowed ? createFields : [], createCapability: capability };\n\t}\n\n\tasync getIssueOptions(options: GitLabIssueWriteAddress): Promise<IssueOptionsSuccess> {\n\t\tconst { project, iid, expectedIssueId } = options;\n\t\tif (!isGitLabDecimalId(iid) || (expectedIssueId !== undefined && !isGitLabDecimalId(expectedIssueId))) {\n\t\t\tthrow new GitLabIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst { context, account, policyAllowsWrites } = await this.readProject(project);\n\t\tconst raw = await this.read<RestIssue>(`/api/v4/projects/${context.project.id}/issues/${iid}`);\n\t\tconst issue = issueReceipt(raw, context.project, iid, expectedIssueId);\n\t\tconst capabilities = await this.getIssueCapabilities(\n\t\t\tcontext.project,\n\t\t\tissue,\n\t\t\tthis.getWriteRefusal(account, policyAllowsWrites),\n\t\t);\n\t\treturn {\n\t\t\t...context,\n\t\t\tok: true,\n\t\t\tissue: issue,\n\t\t\tfields: capabilities.edit.allowed ? editFields : [],\n\t\t\tcapabilities: capabilities,\n\t\t};\n\t}\n\n\tasync resolveTarget(options: GitLabIssueWriteTargetOptions): Promise<GitLabIssueWriteResult> {\n\t\tif (options.intent !== undefined && options.intent !== 'delete') {\n\t\t\treturn gitLabIssueWriteFailure('invalid-input');\n\t\t}\n\n\t\tconst { fields: _fields, capabilities, ...target } = await this.getIssueOptions(options);\n\t\treturn options.intent === 'delete' && !capabilities.delete.allowed\n\t\t\t? gitLabIssueWriteFailure(capabilities.delete.reason)\n\t\t\t: target;\n\t}\n\n\tasync write(input: GitLabIssueWriteOptions): Promise<GitLabIssueWriteResult> {\n\t\tif (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId)) {\n\t\t\treturn gitLabIssueWriteFailure('invalid-input');\n\t\t}\n\n\t\tif (input.action === 'create') {\n\t\t\tconst { title, description } = input;\n\t\t\tconst invalid = validateFields('create', title, description);\n\t\t\tif (invalid != null) return invalid;\n\n\t\t\tconst {\n\t\t\t\tfields: _fields,\n\t\t\t\tcreateCapability,\n\t\t\t\t...target\n\t\t\t} = await this.getCreateOptions({ ...input, project: input.projectId });\n\t\t\tif (!createCapability.allowed) return gitLabIssueWriteFailure(createCapability.reason);\n\n\t\t\treturn this.mutate(\n\t\t\t\t'POST',\n\t\t\t\ttarget.project,\n\t\t\t\tundefined,\n\t\t\t\t{ title: title, description: description },\n\t\t\t\tasync response => ({\n\t\t\t\t\t...target,\n\t\t\t\t\tissue: issueReceipt((await response.json()) as RestIssue, target.project),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst action = input.action;\n\t\tif (action !== 'edit' && action !== 'close' && action !== 'reopen') {\n\t\t\treturn gitLabIssueWriteFailure('invalid-input');\n\t\t}\n\t\tif (!isGitLabDecimalId(input.expectedIssueId)) return gitLabIssueWriteFailure('invalid-input');\n\n\t\tlet fields: Record<string, unknown>;\n\t\tif (action === 'edit') {\n\t\t\tconst { title, description } = input;\n\t\t\tconst invalid = validateFields(action, title, description);\n\t\t\tif (invalid != null) return invalid;\n\n\t\t\tfields = { title: title, description: description };\n\t\t} else {\n\t\t\tfields = { state_event: action };\n\t\t}\n\n\t\tconst {\n\t\t\tfields: _fields,\n\t\t\tcapabilities,\n\t\t\t...target\n\t\t} = await this.getIssueOptions({ ...input, project: input.projectId });\n\t\tconst capability = capabilities[action];\n\t\tif (!capability.allowed) return gitLabIssueWriteFailure(capability.reason);\n\n\t\tconst { issue, project } = target;\n\t\treturn this.mutate('PUT', project, issue.iid, fields, async response => {\n\t\t\tconst updated = issueReceipt((await response.json()) as RestIssue, project, issue.iid, issue.id);\n\t\t\tif (\n\t\t\t\t(action === 'close' && updated.state !== 'closed') ||\n\t\t\t\t(action === 'reopen' && updated.state !== 'opened')\n\t\t\t) {\n\t\t\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t\t\t}\n\n\t\t\treturn { ...target, issue: updated };\n\t\t});\n\t}\n\n\tasync delete(input: GitLabIssueDeleteOptions): Promise<GitLabIssueWriteResult> {\n\t\tif (\n\t\t\t!isGitLabDecimalId(input.projectId) ||\n\t\t\t!isGitLabDecimalId(input.expectedAccountId) ||\n\t\t\t!isGitLabDecimalId(input.expectedIssueId)\n\t\t) {\n\t\t\treturn gitLabIssueWriteFailure('invalid-input');\n\t\t}\n\n\t\tconst result = await this.resolveTarget({ ...input, project: input.projectId, intent: 'delete' });\n\t\tif (!result.ok) return result;\n\n\t\treturn this.mutate('DELETE', result.project, result.issue.iid, undefined, () => result);\n\t}\n\n\tprivate async readProject(\n\t\tproject: string,\n\t): Promise<{ context: GitLabIssueWriteContext; account: Account; policyAllowsWrites: boolean }> {\n\t\tif (!isGitLabDecimalId(project) && !isProjectPath(project)) throw new GitLabIssueWriteError('invalid-input');\n\n\t\tconst account = await this.readAccount();\n\t\tconst raw = await this.read<RestProject>(`/api/v4/projects/${encodeURIComponent(project)}`);\n\t\tconst id = restId(raw?.id);\n\t\tif (\n\t\t\tid == null ||\n\t\t\t!isProjectPath(raw.path_with_namespace) ||\n\t\t\t!isGitLabUrl(raw.web_url) ||\n\t\t\ttypeof raw.archived !== 'boolean'\n\t\t) {\n\t\t\tthrow new GitLabIssueWriteError('unknown');\n\t\t}\n\t\tif (\n\t\t\tisGitLabDecimalId(project)\n\t\t\t\t? id !== project\n\t\t\t\t: raw.path_with_namespace.toLowerCase() !== project.toLowerCase()\n\t\t) {\n\t\t\tthrow new GitLabIssueWriteError('conflict');\n\t\t}\n\n\t\tconst { providerId, connectionId, baseUrl } = this.scope;\n\t\treturn {\n\t\t\taccount: account,\n\t\t\tcontext: {\n\t\t\t\tproviderId: providerId,\n\t\t\t\tconnectionId: connectionId,\n\t\t\t\tbaseUrl: baseUrl,\n\t\t\t\taccountId: account.id,\n\t\t\t\tproject: { id: id, fullPath: raw.path_with_namespace, url: raw.web_url },\n\t\t\t},\n\t\t\tpolicyAllowsWrites:\n\t\t\t\t!raw.archived &&\n\t\t\t\t!raw.marked_for_deletion_on &&\n\t\t\t\traw.issues_enabled !== false &&\n\t\t\t\traw.issues_access_level !== 'disabled',\n\t\t};\n\t}\n\n\tprivate async readAccount(): Promise<Account> {\n\t\tconst personal = this.session.type === 'pat';\n\t\tconst raw = await this.read<{\n\t\t\tresource_owner_id?: unknown;\n\t\t\tuser_id?: unknown;\n\t\t\tscope?: unknown;\n\t\t\tscopes?: unknown;\n\t\t}>(personal ? '/api/v4/personal_access_tokens/self' : '/oauth/token/info');\n\t\tconst id = restId(personal ? raw?.user_id : raw?.resource_owner_id);\n\t\tconst scopes = personal ? raw?.scopes : raw?.scope;\n\t\tif (id == null || !Array.isArray(scopes) || !scopes.every(s => typeof s === 'string')) {\n\t\t\tthrow new GitLabIssueWriteError('unknown');\n\t\t}\n\t\tif (this.scope.expectedAccountId !== undefined && this.scope.expectedAccountId !== id) {\n\t\t\tthrow new GitLabIssueWriteError('no-connection');\n\t\t}\n\n\t\treturn { id: id, canWrite: scopes.includes('api') };\n\t}\n\n\tprivate getWriteRefusal(\n\t\taccount: Account,\n\t\tpolicyAllowsWrites: boolean,\n\t): Extract<GitLabIssueWriteCapability, { allowed: false }> | undefined {\n\t\tif (!account.canWrite) return { allowed: false, reason: 'insufficient-scope' };\n\t\tif (!policyAllowsWrites) return { allowed: false, reason: 'provider-policy' };\n\n\t\treturn undefined;\n\t}\n\n\tprivate async getIssueCapabilities(\n\t\tproject: Project,\n\t\tissue: GitLabIssueReceipt,\n\t\tunavailable: GitLabIssueWriteCapability | undefined,\n\t): Promise<IssueOptionsSuccess['capabilities']> {\n\t\tif (unavailable != null) {\n\t\t\treturn { edit: unavailable, close: unavailable, reopen: unavailable, delete: unavailable };\n\t\t}\n\n\t\tconst id = `${workItemGidPrefix}${issue.id}`;\n\t\tconst data = await this.readPermissions(\n\t\t\tissuePermissionsQuery,\n\t\t\t{ path: project.fullPath, iid: issue.iid, id: id },\n\t\t\tproject,\n\t\t);\n\t\tif (data.project?.issue?.id !== `${issueGidPrefix}${issue.id}` || data.workItem?.id !== id) {\n\t\t\tthrow new GitLabIssueWriteError('conflict');\n\t\t}\n\n\t\tconst { updateIssue, reopenIssue } = data.project.issue.userPermissions ?? {};\n\t\tconst canDelete = data.workItem.userPermissions?.deleteWorkItem;\n\t\tif (typeof updateIssue !== 'boolean' || typeof reopenIssue !== 'boolean' || typeof canDelete !== 'boolean') {\n\t\t\tthrow new GitLabIssueWriteError('unknown');\n\t\t}\n\n\t\tconst edit = allowed(updateIssue);\n\t\treturn {\n\t\t\tedit: edit,\n\t\t\tclose: transition(edit, issue.state, 'opened'),\n\t\t\treopen: transition(allowed(updateIssue && reopenIssue), issue.state, 'closed'),\n\t\t\tdelete: allowed(canDelete),\n\t\t};\n\t}\n\n\tprivate async readPermissions(\n\t\tquery: string,\n\t\tvariables: Record<string, string>,\n\t\tproject: Project,\n\t): Promise<Permissions> {\n\t\tconst reply = await this.read<{ data?: Permissions; errors?: readonly unknown[] }>('/api/graphql', {\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify({ query: query, variables: variables }),\n\t\t});\n\t\tif (reply?.data == null || reply.errors?.length) throw new GitLabIssueWriteError('unknown');\n\t\tif (reply.data.project?.id !== `${projectGidPrefix}${project.id}`) throw new GitLabIssueWriteError('conflict');\n\n\t\treturn reply.data;\n\t}\n\n\tprivate async read<T>(path: string, init?: RequestInit): Promise<T> {\n\t\tif (!this.canUseSession()) throw new GitLabIssueWriteError('no-connection');\n\n\t\tconst response = await this.request(path, init);\n\t\tif (!response.ok) {\n\t\t\tconst failure = await toGitLabIssueHttpFailure(response, false);\n\t\t\tthrow new GitLabIssueWriteError(failure.reason);\n\t\t}\n\n\t\treturn (await response.json()) as T;\n\t}\n\n\tprivate async mutate(\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\tproject: Project,\n\t\tiid: string | undefined,\n\t\tbody: Record<string, unknown> | undefined,\n\t\treceipt: (response: Response) => GitLabIssueWriteResult | Promise<GitLabIssueWriteResult>,\n\t): Promise<GitLabIssueWriteResult> {\n\t\tif (!(await this.isCurrent()) || !this.canUseSession()) return gitLabIssueWriteFailure('no-connection');\n\n\t\tconst path = `/api/v4/projects/${project.id}/issues${iid == null ? '' : `/${iid}`}`;\n\t\tconst status = method === 'POST' ? 201 : method === 'PUT' ? 200 : 204;\n\t\ttry {\n\t\t\tconst response = await this.request(path, {\n\t\t\t\tmethod: method,\n\t\t\t\tbody: body == null ? undefined : JSON.stringify(body),\n\t\t\t});\n\t\t\tif (!response.ok) return await toGitLabIssueHttpFailure(response, true);\n\t\t\tif (response.status === status) return await receipt(response);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t\t}\n\n\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t}\n\n\tprivate canUseSession(): boolean {\n\t\treturn !this.isRetired() && sessionExpiry(this.session.expiresAt) > Date.now();\n\t}\n\n\tprivate request(path: string, init?: RequestInit): Promise<Response> {\n\t\tconst request: RequestInit & { cache: 'no-store' } = {\n\t\t\t...init,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.session.accessToken}`,\n\t\t\t\t...(init?.body != null && { 'Content-Type': 'application/json' }),\n\t\t\t},\n\t\t\tredirect: 'error',\n\t\t\tcredentials: 'omit',\n\t\t\tcache: 'no-store',\n\t\t};\n\t\treturn this.config.fetch(`${gitLabIssueWriteBaseUrl}${path}`, request);\n\t}\n}\n"],"mappings":";;;;;AAuBA,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,eAAe,CACpB;CAAE,IAAI;CAAS,UAAU;AAAK,GAC9B;CAAE,IAAI;CAAe,UAAU;AAAM,CACtC;AACA,MAAM,aAAa,CAClB;CAAE,IAAI;CAAS,UAAU;AAAM,GAC/B;CAAE,IAAI;CAAe,UAAU;AAAM,CACtC;AAEA,MAAM,yBAAyB;;;AAG/B,MAAM,wBAAwB;;;;;;;AAuC9B,SAAS,OAAO,OAAoC;CACnD,OAAO,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,KAAA;AAChG;AAEA,SAAS,cAAc,OAAiC;CACvD,OACC,OAAO,UAAU,YACjB,mBAAmB,KAAK,KAAK,KAC7B,MAAM,MAAM,GAAG,CAAC,CAAC,OAAM,YAAW,YAAY,OAAO,YAAY,IAAI;AAEvE;AAEA,SAAS,YAAY,KAA6B;CACjD,IAA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;IACtC,GAAI,MAAM,QAAQ,QAAQ,EAAE,gBAAgB,mBAAmB;GAChE;GACA,UAAU;GACV,aAAa;GACb,OAAO;EACR;EACA,OAAO,KAAK,OAAO,MAAM,GAAG,0BAA0B,QAAQ,OAAO;CACtE;AACD"}
|
|
@@ -7,9 +7,10 @@ import { Account } from "../../../git/models/author.js";
|
|
|
7
7
|
import { DefaultBranch } from "../../../git/models/defaultBranch.js";
|
|
8
8
|
import { RepositoryMetadata } from "../../../git/models/repositoryMetadata.js";
|
|
9
9
|
import { PullRequestUrlIdentity } from "../../../git/utils/pullRequest.utils.js";
|
|
10
|
-
import { ProviderAuthenticationSession } from "../authentication/models.js";
|
|
10
|
+
import { ConfiguredIntegrationDescriptor, ProviderAuthenticationSession } from "../authentication/models.js";
|
|
11
11
|
import { GitCloudHostIntegrationId, GitSelfManagedHostIntegrationId } from "../constants.js";
|
|
12
12
|
import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
|
|
13
|
+
import { GitLabIssueWriteScope } from "../models/gitlabIssueWrites.js";
|
|
13
14
|
import { IssueEtagFields, IssueEtagInclude, PullRequestEtagFields, PullRequestEtagInclude } from "../reads/etag.js";
|
|
14
15
|
import { ProviderOrganization } from "../results.js";
|
|
15
16
|
import { SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/publicIntegration.js";
|
|
@@ -19,6 +20,7 @@ import { AccountWideIssuesResult, SearchMyIssuesOptions } from "../models/issueR
|
|
|
19
20
|
import "../models/integration.js";
|
|
20
21
|
import { ProviderApiPagedResult, ProviderHierarchyResult, ProviderPullRequest, ProviderRepository } from "./models.js";
|
|
21
22
|
import { GitHostIntegration } from "../models/gitHostIntegration.js";
|
|
23
|
+
import { GitLabIssueWriter } from "./gitlab/issueWrites.js";
|
|
22
24
|
import { IntegrationConnectionChangeEvent } from "../integrationService.js";
|
|
23
25
|
import { IntegrationAuthenticationService } from "../authentication/integrationAuthenticationService.js";
|
|
24
26
|
import { GitLabIntegrationIds } from "./gitlab/gitlab.utils.js";
|
|
@@ -209,6 +211,10 @@ export declare class GitLabIntegration extends GitLabIntegrationBase<GitCloudHos
|
|
|
209
211
|
readonly name: string;
|
|
210
212
|
get domain(): string;
|
|
211
213
|
protected apiBaseUrlFor(_session: ProviderAuthenticationSession): string;
|
|
214
|
+
getIssueWriter(scope: GitLabIssueWriteScope, connection: ConfiguredIntegrationDescriptor, isSelectionCurrent: () => boolean): Promise<{
|
|
215
|
+
writer: GitLabIssueWriter;
|
|
216
|
+
isCurrent: () => Promise<boolean>;
|
|
217
|
+
} | undefined>;
|
|
212
218
|
access(): Promise<boolean>;
|
|
213
219
|
}
|
|
214
220
|
export declare class GitLabSelfHostedIntegration extends GitLabIntegrationBase<GitSelfManagedHostIntegrationId.CloudGitLabSelfHosted> {
|
|
@@ -8,6 +8,7 @@ import { toCollectionScopeFailure } from "../collectionMetadata.js";
|
|
|
8
8
|
import "../providerFilters.js";
|
|
9
9
|
import { collectProviderPagedResult, mergeCollectionMetadata, readEtagFieldsByRepository, resolveBranchPullRequests } from "./utils/providerPaging.js";
|
|
10
10
|
import { providersMetadata } from "./metadata.js";
|
|
11
|
+
import { baseUrlFromDomain, matchesInstallationOrigin } from "../utils/domain.utils.js";
|
|
11
12
|
import { toTokenWithInfo } from "../authentication/models.js";
|
|
12
13
|
import { ProviderPullRequestReviewState, fromProviderPullRequest, getProviderPullRequestIdentity, toIssueShape, toProviderPullRequestStates } from "./models.js";
|
|
13
14
|
import { getGitLabPullRequestIdentityFromMaybeUrl, matchesGitLabOrgNamespace } from "./gitlab/gitlab.utils.js";
|
|
@@ -15,6 +16,10 @@ import { fromGitLabMergeRequestProvidersApi, toGitLabIssueEtagFields, toGitLabPu
|
|
|
15
16
|
import { GitHostIntegration } from "../models/gitHostIntegration.js";
|
|
16
17
|
import * as l10n from "@vscode/l10n";
|
|
17
18
|
//#region ../plus/integrations/src/providers/gitlab.ts
|
|
19
|
+
function isGitLabIssueWriteInstallation(connection, protocol) {
|
|
20
|
+
const baseUrl = "https://gitlab.com";
|
|
21
|
+
return [connection.baseUrl, connection.domain].every((value) => value == null || matchesInstallationOrigin(value, baseUrl) && baseUrlFromDomain(value, protocol) === baseUrl);
|
|
22
|
+
}
|
|
18
23
|
const metadata = providersMetadata["gitlab"];
|
|
19
24
|
const authProvider = Object.freeze({
|
|
20
25
|
id: metadata.id,
|
|
@@ -575,6 +580,25 @@ var GitLabIntegration = class extends GitLabIntegrationBase {
|
|
|
575
580
|
apiBaseUrlFor(_session) {
|
|
576
581
|
return "https://gitlab.com/api";
|
|
577
582
|
}
|
|
583
|
+
async getIssueWriter(scope, connection, isSelectionCurrent) {
|
|
584
|
+
if (!isSelectionCurrent() || !isGitLabIssueWriteInstallation(connection)) return void 0;
|
|
585
|
+
const { cloud } = connection;
|
|
586
|
+
const session = await this.resolveReadSessionOrThrow(scope.connectionId, void 0, cloud);
|
|
587
|
+
if (session?.id !== scope.connectionId || session.cloud !== cloud || !session.accessToken) return void 0;
|
|
588
|
+
if (!isGitLabIssueWriteInstallation(session, session.protocol)) return void 0;
|
|
589
|
+
const tracked = this.trackWriteSession(session, {
|
|
590
|
+
cloud,
|
|
591
|
+
observeHostChanges: true
|
|
592
|
+
});
|
|
593
|
+
const isRetired = () => !isSelectionCurrent() || !this.isIntegrationAccessEnabled() || tracked.isRetired();
|
|
594
|
+
const isCurrent = async () => !isRetired() && await tracked() && !isRetired();
|
|
595
|
+
const api = await this.authenticationService.apis.gitlab;
|
|
596
|
+
if (api == null || isRetired()) return void 0;
|
|
597
|
+
return {
|
|
598
|
+
writer: api.getIssueWriter(scope, session, isCurrent, isRetired),
|
|
599
|
+
isCurrent
|
|
600
|
+
};
|
|
601
|
+
}
|
|
578
602
|
access() {
|
|
579
603
|
return Promise.resolve(true);
|
|
580
604
|
}
|