@gitkraken/core-gitlens 0.63.0 → 0.64.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 +19 -1
- package/dist/git/watching/provider.d.ts +1 -1
- package/dist/git/watching/watchService.js +6 -1
- package/dist/git/watching/watchService.js.map +1 -1
- package/dist/git-cli/cliGitProvider.js +3 -3
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/integrations/extensionManager.d.ts +6 -0
- package/dist/plus/integrations/extensionManager.js +10 -0
- package/dist/plus/integrations/extensionManager.js.map +1 -0
- package/dist/plus/integrations/index.d.ts +5 -63
- package/dist/plus/integrations/index.js +4 -53
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +14 -2
- package/dist/plus/integrations/integrationService.js +48 -12
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +10 -0
- package/dist/plus/integrations/managerContext.d.ts +69 -0
- package/dist/plus/integrations/managerContext.js +59 -0
- package/dist/plus/integrations/managerContext.js.map +1 -0
- package/dist/plus/integrations/models/gitlabMergeRequestWrites.d.ts +167 -0
- package/dist/plus/integrations/models/gitlabMergeRequestWrites.js +0 -0
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/github.js +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
- package/dist/plus/integrations/providers/gitlab/gitlab.js +3 -3
- package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/issueWrites.d.ts +4 -13
- package/dist/plus/integrations/providers/gitlab/issueWrites.js +33 -136
- package/dist/plus/integrations/providers/gitlab/issueWrites.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.d.ts +30 -0
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.js +569 -0
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab/writeErrors.d.ts +12 -0
- package/dist/plus/integrations/providers/gitlab/writeErrors.js +101 -0
- package/dist/plus/integrations/providers/gitlab/writeErrors.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab/writeTransport.d.ts +47 -0
- package/dist/plus/integrations/providers/gitlab/writeTransport.js +135 -0
- package/dist/plus/integrations/providers/gitlab/writeTransport.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab.d.ts +6 -1
- package/dist/plus/integrations/providers/gitlab.js +9 -1
- package/dist/plus/integrations/providers/gitlab.js.map +1 -1
- package/dist/plus/integrations/reads/sweeps.js +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/docs/integrations.md +77 -0
- package/package.json +1 -1
- package/dist/plus/integrations/providers/gitlab/issueWriteErrors.d.ts +0 -11
- package/dist/plus/integrations/providers/gitlab/issueWriteErrors.js +0 -73
- package/dist/plus/integrations/providers/gitlab/issueWriteErrors.js.map +0 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { isGitLabDecimalId } from "../../models/gitlabIssueWrites.js";
|
|
2
|
+
import { GitLabWriteError, gitLabWriteFailure, validateGitLabWriteFields } from "./writeErrors.js";
|
|
3
|
+
import { isGitLabProjectRef, isGitLabUrl, restId } from "./writeTransport.js";
|
|
4
4
|
import * as l10n from "@vscode/l10n";
|
|
5
5
|
//#region ../plus/integrations/src/providers/gitlab/issueWrites.ts
|
|
6
|
-
const projectPathPattern = /^[\w.-]+(?:\/[\w.-]+)+$/;
|
|
7
|
-
const projectGidPrefix = "gid://gitlab/Project/";
|
|
8
6
|
const issueGidPrefix = "gid://gitlab/Issue/";
|
|
9
7
|
const workItemGidPrefix = "gid://gitlab/WorkItem/";
|
|
10
8
|
const createFields = [{
|
|
@@ -31,24 +29,13 @@ const issuePermissionsQuery = `query IssueWritePermissions($path: ID!, $iid: Str
|
|
|
31
29
|
}
|
|
32
30
|
workItem(id: $id) { id userPermissions { deleteWorkItem } }
|
|
33
31
|
}`;
|
|
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
32
|
function issueReceipt(raw, project, iid, expectedId) {
|
|
46
33
|
const id = restId(raw?.id);
|
|
47
34
|
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
|
|
49
|
-
if (restId(raw.project_id) !== project.id || iid != null && iid !== actualIid || expectedId != null && expectedId !== id) throw new
|
|
50
|
-
if (typeof raw.issue_type !== "string") throw new
|
|
51
|
-
if (raw.issue_type !== "issue") throw new
|
|
35
|
+
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 GitLabWriteError("unknown");
|
|
36
|
+
if (restId(raw.project_id) !== project.id || iid != null && iid !== actualIid || expectedId != null && expectedId !== id) throw new GitLabWriteError("conflict");
|
|
37
|
+
if (typeof raw.issue_type !== "string") throw new GitLabWriteError("unknown");
|
|
38
|
+
if (raw.issue_type !== "issue") throw new GitLabWriteError("unsupported");
|
|
52
39
|
return {
|
|
53
40
|
id,
|
|
54
41
|
iid: actualIid,
|
|
@@ -71,22 +58,12 @@ function transition(permission, currentState, requiredState) {
|
|
|
71
58
|
} : permission;
|
|
72
59
|
}
|
|
73
60
|
function validateFields(action, title, description) {
|
|
74
|
-
|
|
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.") });
|
|
61
|
+
return validateGitLabWriteFields(action, title, description, l10n.t("GitLab quick actions are unavailable in issue descriptions."));
|
|
77
62
|
}
|
|
78
63
|
var GitLabIssueWriter = class {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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;
|
|
64
|
+
transport;
|
|
65
|
+
constructor(transport) {
|
|
66
|
+
this.transport = transport;
|
|
90
67
|
}
|
|
91
68
|
async getCreateOptions(options) {
|
|
92
69
|
const { context, account, policyAllowsWrites } = await this.readProject(options.project);
|
|
@@ -95,7 +72,7 @@ var GitLabIssueWriter = class {
|
|
|
95
72
|
if (unavailable != null) capability = unavailable;
|
|
96
73
|
else {
|
|
97
74
|
const create = (await this.readPermissions(createPermissionsQuery, { path: context.project.fullPath }, context.project)).project?.userPermissions?.createIssue;
|
|
98
|
-
if (typeof create !== "boolean") throw new
|
|
75
|
+
if (typeof create !== "boolean") throw new GitLabWriteError("unknown");
|
|
99
76
|
capability = allowed(create);
|
|
100
77
|
}
|
|
101
78
|
return {
|
|
@@ -107,9 +84,9 @@ var GitLabIssueWriter = class {
|
|
|
107
84
|
}
|
|
108
85
|
async getIssueOptions(options) {
|
|
109
86
|
const { project, iid, expectedIssueId } = options;
|
|
110
|
-
if (!isGitLabDecimalId(iid) || expectedIssueId !== void 0 && !isGitLabDecimalId(expectedIssueId)) throw new
|
|
87
|
+
if (!isGitLabDecimalId(iid) || expectedIssueId !== void 0 && !isGitLabDecimalId(expectedIssueId)) throw new GitLabWriteError("invalid-input");
|
|
111
88
|
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);
|
|
89
|
+
const issue = issueReceipt(await this.transport.read(`/api/v4/projects/${context.project.id}/issues/${iid}`), context.project, iid, expectedIssueId);
|
|
113
90
|
const capabilities = await this.getIssueCapabilities(context.project, issue, this.getWriteRefusal(account, policyAllowsWrites));
|
|
114
91
|
return {
|
|
115
92
|
...context,
|
|
@@ -120,12 +97,12 @@ var GitLabIssueWriter = class {
|
|
|
120
97
|
};
|
|
121
98
|
}
|
|
122
99
|
async resolveTarget(options) {
|
|
123
|
-
if (options.intent !== void 0 && options.intent !== "delete") return
|
|
100
|
+
if (options.intent !== void 0 && options.intent !== "delete") return gitLabWriteFailure("invalid-input");
|
|
124
101
|
const { fields: _fields, capabilities, ...target } = await this.getIssueOptions(options);
|
|
125
|
-
return options.intent === "delete" && !capabilities.delete.allowed ?
|
|
102
|
+
return options.intent === "delete" && !capabilities.delete.allowed ? gitLabWriteFailure(capabilities.delete.reason) : target;
|
|
126
103
|
}
|
|
127
104
|
async write(input) {
|
|
128
|
-
if (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId)) return
|
|
105
|
+
if (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId)) return gitLabWriteFailure("invalid-input");
|
|
129
106
|
if (input.action === "create") {
|
|
130
107
|
const { title, description } = input;
|
|
131
108
|
const invalid = validateFields("create", title, description);
|
|
@@ -134,7 +111,7 @@ var GitLabIssueWriter = class {
|
|
|
134
111
|
...input,
|
|
135
112
|
project: input.projectId
|
|
136
113
|
});
|
|
137
|
-
if (!createCapability.allowed) return
|
|
114
|
+
if (!createCapability.allowed) return gitLabWriteFailure(createCapability.reason);
|
|
138
115
|
return this.mutate("POST", target.project, void 0, {
|
|
139
116
|
title,
|
|
140
117
|
description
|
|
@@ -144,8 +121,8 @@ var GitLabIssueWriter = class {
|
|
|
144
121
|
}));
|
|
145
122
|
}
|
|
146
123
|
const action = input.action;
|
|
147
|
-
if (action !== "edit" && action !== "close" && action !== "reopen") return
|
|
148
|
-
if (!isGitLabDecimalId(input.expectedIssueId)) return
|
|
124
|
+
if (action !== "edit" && action !== "close" && action !== "reopen") return gitLabWriteFailure("invalid-input");
|
|
125
|
+
if (!isGitLabDecimalId(input.expectedIssueId)) return gitLabWriteFailure("invalid-input");
|
|
149
126
|
let fields;
|
|
150
127
|
if (action === "edit") {
|
|
151
128
|
const { title, description } = input;
|
|
@@ -161,7 +138,7 @@ var GitLabIssueWriter = class {
|
|
|
161
138
|
project: input.projectId
|
|
162
139
|
});
|
|
163
140
|
const capability = capabilities[action];
|
|
164
|
-
if (!capability.allowed) return
|
|
141
|
+
if (!capability.allowed) return gitLabWriteFailure(capability.reason);
|
|
165
142
|
const { issue, project } = target;
|
|
166
143
|
return this.mutate("PUT", project, issue.iid, fields, async (response) => {
|
|
167
144
|
const updated = issueReceipt(await response.json(), project, issue.iid, issue.id);
|
|
@@ -177,7 +154,7 @@ var GitLabIssueWriter = class {
|
|
|
177
154
|
});
|
|
178
155
|
}
|
|
179
156
|
async delete(input) {
|
|
180
|
-
if (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId) || !isGitLabDecimalId(input.expectedIssueId)) return
|
|
157
|
+
if (!isGitLabDecimalId(input.projectId) || !isGitLabDecimalId(input.expectedAccountId) || !isGitLabDecimalId(input.expectedIssueId)) return gitLabWriteFailure("invalid-input");
|
|
181
158
|
const result = await this.resolveTarget({
|
|
182
159
|
...input,
|
|
183
160
|
project: input.projectId,
|
|
@@ -187,41 +164,16 @@ var GitLabIssueWriter = class {
|
|
|
187
164
|
return this.mutate("DELETE", result.project, result.issue.iid, void 0, () => result);
|
|
188
165
|
}
|
|
189
166
|
async readProject(project) {
|
|
190
|
-
if (!
|
|
191
|
-
const account = await this.readAccount();
|
|
192
|
-
const
|
|
193
|
-
const
|
|
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;
|
|
167
|
+
if (!isGitLabProjectRef(project)) throw new GitLabWriteError("invalid-input");
|
|
168
|
+
const account = await this.transport.readAccount();
|
|
169
|
+
const read = await this.transport.readProject(project);
|
|
170
|
+
const { raw } = read;
|
|
197
171
|
return {
|
|
198
172
|
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
|
-
},
|
|
173
|
+
context: this.transport.context(account, read.project),
|
|
210
174
|
policyAllowsWrites: !raw.archived && !raw.marked_for_deletion_on && raw.issues_enabled !== false && raw.issues_access_level !== "disabled"
|
|
211
175
|
};
|
|
212
176
|
}
|
|
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
177
|
getWriteRefusal(account, policyAllowsWrites) {
|
|
226
178
|
if (!account.canWrite) return {
|
|
227
179
|
allowed: false,
|
|
@@ -245,10 +197,10 @@ var GitLabIssueWriter = class {
|
|
|
245
197
|
iid: issue.iid,
|
|
246
198
|
id
|
|
247
199
|
}, project);
|
|
248
|
-
if (data.project?.issue?.id !== `${issueGidPrefix}${issue.id}` || data.workItem?.id !== id) throw new
|
|
200
|
+
if (data.project?.issue?.id !== `${issueGidPrefix}${issue.id}` || data.workItem?.id !== id) throw new GitLabWriteError("conflict");
|
|
249
201
|
const { updateIssue, reopenIssue } = data.project.issue.userPermissions ?? {};
|
|
250
202
|
const canDelete = data.workItem.userPermissions?.deleteWorkItem;
|
|
251
|
-
if (typeof updateIssue !== "boolean" || typeof reopenIssue !== "boolean" || typeof canDelete !== "boolean") throw new
|
|
203
|
+
if (typeof updateIssue !== "boolean" || typeof reopenIssue !== "boolean" || typeof canDelete !== "boolean") throw new GitLabWriteError("unknown");
|
|
252
204
|
const edit = allowed(updateIssue);
|
|
253
205
|
return {
|
|
254
206
|
edit,
|
|
@@ -257,66 +209,11 @@ var GitLabIssueWriter = class {
|
|
|
257
209
|
delete: allowed(canDelete)
|
|
258
210
|
};
|
|
259
211
|
}
|
|
260
|
-
|
|
261
|
-
|
|
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();
|
|
212
|
+
readPermissions(query, variables, project) {
|
|
213
|
+
return this.transport.readGraphQL(query, variables, { project });
|
|
280
214
|
}
|
|
281
|
-
|
|
282
|
-
|
|
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);
|
|
215
|
+
mutate(method, project, iid, body, receipt) {
|
|
216
|
+
return this.transport.mutate(method, `/api/v4/projects/${project.id}/issues${iid == null ? "" : `/${iid}`}`, body, method === "POST" ? 201 : method === "PUT" ? 200 : 204, receipt);
|
|
320
217
|
}
|
|
321
218
|
};
|
|
322
219
|
//#endregion
|
|
@@ -1 +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,SA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IAAI;IAAO,QAAQ;IAAW,SAAS;GAAQ;EACzD;EAEA,OAAO;GAAE,IAAI;GAAO,QAAQ;GAAW,SAAS;EAAQ;CACzD;CAEA,gBAAiC;EAChC,OAAO,CAAC,KAAK,UAAU,KAAK,cAAc,KAAK,QAAQ,SAAS,IAAI,KAAK,IAAI;CAC9E;CAEA,QAAgB,MAAc,MAAuC;EACpE,MAAM,UAA+C;GACpD,GAAG;GACH,SAAS;IACR,eAAe,UAAU,KAAK,QAAQ;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"}
|
|
1
|
+
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/gitlab/issueWrites.ts"],"sourcesContent":["import * as l10n from '@vscode/l10n';\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\tGitLabIssueWriteTargetOptions,\n} from '../../models/gitlabIssueWrites.js';\nimport { isGitLabDecimalId } from '../../models/gitlabIssueWrites.js';\nimport { GitLabWriteError, gitLabWriteFailure, validateGitLabWriteFields } from './writeErrors.js';\nimport type {\n\tGitLabRestProject,\n\tGitLabWriteAccount,\n\tGitLabWriteProject,\n\tGitLabWriteTransport,\n} from './writeTransport.js';\nimport { isGitLabProjectRef, isGitLabUrl, restId } from './writeTransport.js';\n\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 = GitLabWriteProject;\ntype RestProject = GitLabRestProject & { issues_access_level?: string; issues_enabled?: boolean };\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 = GitLabWriteAccount;\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 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 GitLabWriteError('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 GitLabWriteError('conflict');\n\t}\n\tif (typeof raw.issue_type !== 'string') throw new GitLabWriteError('unknown');\n\tif (raw.issue_type !== 'issue') throw new GitLabWriteError('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\treturn validateGitLabWriteFields(\n\t\taction,\n\t\ttitle,\n\t\tdescription,\n\t\tl10n.t('GitLab quick actions are unavailable in issue descriptions.'),\n\t);\n}\n\nexport class GitLabIssueWriter {\n\tconstructor(private readonly transport: GitLabWriteTransport) {}\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 GitLabWriteError('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 GitLabWriteError('invalid-input');\n\t\t}\n\n\t\tconst { context, account, policyAllowsWrites } = await this.readProject(project);\n\t\tconst raw = await this.transport.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 gitLabWriteFailure('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? gitLabWriteFailure(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 gitLabWriteFailure('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 gitLabWriteFailure(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 gitLabWriteFailure('invalid-input');\n\t\t}\n\t\tif (!isGitLabDecimalId(input.expectedIssueId)) return gitLabWriteFailure('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 gitLabWriteFailure(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 gitLabWriteFailure('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 (!isGitLabProjectRef(project)) throw new GitLabWriteError('invalid-input');\n\n\t\tconst account = await this.transport.readAccount();\n\t\tconst read = await this.transport.readProject<RestProject>(project);\n\t\tconst { raw } = read;\n\t\treturn {\n\t\t\taccount: account,\n\t\t\tcontext: this.transport.context(account, read.project),\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 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 GitLabWriteError('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 GitLabWriteError('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 readPermissions(query: string, variables: Record<string, string>, project: Project): Promise<Permissions> {\n\t\treturn this.transport.readGraphQL<Permissions>(query, variables, { project: project });\n\t}\n\n\tprivate 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\treturn this.transport.mutate(\n\t\t\tmethod,\n\t\t\t`/api/v4/projects/${project.id}/issues${iid == null ? '' : `/${iid}`}`,\n\t\t\tbody,\n\t\t\tmethod === 'POST' ? 201 : method === 'PUT' ? 200 : 204,\n\t\t\treceipt,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;AA0BA,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,eAAe,CACpB;CAAE,IAAI;CAAS,UAAU;AAAK,GAC9B;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itLabMergeRequestCreateOptions, GitLabMergeRequestCreateOptionsResult, GitLabMergeRequestDeleteOptions, GitLabMergeRequestWriteAddress, GitLabMergeRequestWriteOptions, GitLabMergeRequestWriteOptionsResult, GitLabMergeRequestWriteResult, GitLabMergeRequestWriteTargetOptions, GitLabMergeRequestWriteTargetResult } from "../../models/gitlabMergeRequestWrites.js";
|
|
2
|
+
import { GitLabWriteTransport } from "./writeTransport.js";
|
|
3
|
+
//#region ../plus/integrations/src/providers/gitlab/mergeRequestWrites.d.ts
|
|
4
|
+
export declare class GitLabMergeRequestWriter {
|
|
5
|
+
private readonly transport;
|
|
6
|
+
constructor(transport: GitLabWriteTransport);
|
|
7
|
+
getCreateOptions(options: GitLabMergeRequestCreateOptions): Promise<Extract<GitLabMergeRequestCreateOptionsResult, {
|
|
8
|
+
ok: true;
|
|
9
|
+
}>>;
|
|
10
|
+
getMergeRequestOptions(options: GitLabMergeRequestWriteAddress): Promise<Extract<GitLabMergeRequestWriteOptionsResult, {
|
|
11
|
+
ok: true;
|
|
12
|
+
}>>;
|
|
13
|
+
resolveTarget(options: GitLabMergeRequestWriteTargetOptions): Promise<GitLabMergeRequestWriteTargetResult>;
|
|
14
|
+
write(input: GitLabMergeRequestWriteOptions): Promise<GitLabMergeRequestWriteResult>;
|
|
15
|
+
delete(input: GitLabMergeRequestDeleteOptions): Promise<GitLabMergeRequestWriteResult>;
|
|
16
|
+
private create;
|
|
17
|
+
private writeExisting;
|
|
18
|
+
private merge;
|
|
19
|
+
private toMergeRefusal;
|
|
20
|
+
private readCreateTarget;
|
|
21
|
+
private readMergeRequest;
|
|
22
|
+
private getWriteRefusal;
|
|
23
|
+
private getCapabilities;
|
|
24
|
+
private getMergeCapability;
|
|
25
|
+
private findOpenMergeRequest;
|
|
26
|
+
private readBranchTip;
|
|
27
|
+
private mergeRequestPath;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//# sourceMappingURL=mergeRequestWrites.d.ts.map
|