@leitwerk-dev/gitlab 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -1
- package/dist/capability.d.ts +3 -0
- package/dist/capability.d.ts.map +1 -1
- package/dist/chunk-YPCOVBQS.js +2343 -0
- package/dist/chunk-YPCOVBQS.js.map +1 -0
- package/dist/client.d.ts +99 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/external.d.ts +24 -4
- package/dist/external.d.ts.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +512 -10
- package/dist/index.js.map +1 -1
- package/dist/issue-watcher.d.ts +2 -2
- package/dist/issue-watcher.d.ts.map +1 -1
- package/dist/launch.d.ts +40 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/maintenance-labels.d.ts +30 -0
- package/dist/maintenance-labels.d.ts.map +1 -0
- package/dist/maintenance.d.ts +132 -0
- package/dist/maintenance.d.ts.map +1 -0
- package/dist/publication-maintenance.d.ts +7 -0
- package/dist/publication-maintenance.d.ts.map +1 -0
- package/dist/publication.d.ts +37 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/repository-catalog.d.ts +16 -0
- package/dist/repository-catalog.d.ts.map +1 -0
- package/dist/setup.d.ts +8 -2
- package/dist/setup.d.ts.map +1 -1
- package/dist/testing.d.ts +10 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +125 -5
- package/dist/testing.js.map +1 -1
- package/dist/ticket-creation.d.ts +5 -0
- package/dist/ticket-creation.d.ts.map +1 -0
- package/dist/tools.d.ts +100 -3
- package/dist/tools.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/capability.ts +3 -0
- package/src/client.ts +275 -12
- package/src/delivery-tools.ts +4 -4
- package/src/external.ts +91 -24
- package/src/index.ts +58 -10
- package/src/issue-watcher.ts +16 -14
- package/src/launch.ts +63 -0
- package/src/maintenance-labels.ts +129 -0
- package/src/maintenance.ts +759 -0
- package/src/publication-maintenance.ts +288 -0
- package/src/publication.ts +234 -0
- package/src/repository-catalog.ts +94 -0
- package/src/setup.ts +115 -6
- package/src/testing.ts +143 -4
- package/src/ticket-creation.ts +145 -0
- package/src/tools.ts +382 -26
- package/dist/chunk-H4JCQNDY.js +0 -1162
- package/dist/chunk-H4JCQNDY.js.map +0 -1
package/src/tools.ts
CHANGED
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
import type { GitLabIntegration } from "./capability.js";
|
|
12
12
|
import { type GitLabClientLike, GitLabError, observeMergeRequest } from "./client.js";
|
|
13
13
|
|
|
14
|
+
const hashIdentity = (identity: readonly unknown[]) =>
|
|
15
|
+
createHash("sha256").update(JSON.stringify(identity)).digest("hex");
|
|
16
|
+
|
|
14
17
|
async function existingRemote<T>(read: () => Promise<T>): Promise<T | null> {
|
|
15
18
|
try {
|
|
16
19
|
return await read();
|
|
@@ -22,8 +25,7 @@ async function existingRemote<T>(read: () => Promise<T>): Promise<T | null> {
|
|
|
22
25
|
/** @public */
|
|
23
26
|
export function resolveGitLabRepositoryBinding(
|
|
24
27
|
ctx: Pick<IntegrationToolExecutionContext, "project" | "process">,
|
|
25
|
-
|
|
26
|
-
/** @public */
|
|
28
|
+
integration?: GitLabIntegration,
|
|
27
29
|
): {
|
|
28
30
|
/** @public */
|
|
29
31
|
profile: string;
|
|
@@ -33,7 +35,7 @@ export function resolveGitLabRepositoryBinding(
|
|
|
33
35
|
if (!ctx.project || ctx.project.instanceId !== ctx.process.id)
|
|
34
36
|
throw new Error("An authorized GitLab process project is required");
|
|
35
37
|
const binding = ctx.project.metadata?.gitlab as
|
|
36
|
-
| { profile?: unknown; projectId?: unknown }
|
|
38
|
+
| { profile?: unknown; projectId?: unknown; origin?: unknown }
|
|
37
39
|
| undefined;
|
|
38
40
|
if (
|
|
39
41
|
!binding ||
|
|
@@ -44,13 +46,18 @@ export function resolveGitLabRepositoryBinding(
|
|
|
44
46
|
binding.projectId <= 0
|
|
45
47
|
)
|
|
46
48
|
throw new Error("Invalid GitLab project binding");
|
|
49
|
+
if (
|
|
50
|
+
binding.origin !== undefined &&
|
|
51
|
+
integration &&
|
|
52
|
+
integration.client(binding.profile).baseUrl !== binding.origin
|
|
53
|
+
)
|
|
54
|
+
throw new Error("GitLab profile installation changed from the pinned repository");
|
|
47
55
|
return { profile: binding.profile, projectId: binding.projectId };
|
|
48
56
|
}
|
|
49
57
|
/** @public */
|
|
50
58
|
export function resolveGitLabBinding(
|
|
51
59
|
ctx: Pick<IntegrationToolExecutionContext, "project" | "process">,
|
|
52
|
-
|
|
53
|
-
/** @public */
|
|
60
|
+
integration?: GitLabIntegration,
|
|
54
61
|
): {
|
|
55
62
|
/** @public */
|
|
56
63
|
profile: string;
|
|
@@ -59,12 +66,37 @@ export function resolveGitLabBinding(
|
|
|
59
66
|
/** @public */
|
|
60
67
|
iid: number;
|
|
61
68
|
} {
|
|
62
|
-
const repository = resolveGitLabRepositoryBinding(ctx);
|
|
69
|
+
const repository = resolveGitLabRepositoryBinding(ctx, integration);
|
|
63
70
|
const iid = (ctx.project?.metadata?.gitlab as { iid?: unknown })?.iid;
|
|
64
71
|
if (typeof iid !== "number" || !Number.isSafeInteger(iid) || iid <= 0)
|
|
65
72
|
throw new Error("Invalid GitLab project binding: a merge request is required");
|
|
66
73
|
return { ...repository, iid };
|
|
67
74
|
}
|
|
75
|
+
/** Stable marker shared by retry-safe comment creation and later updates. @public */
|
|
76
|
+
export function gitLabCommentMarker(input: {
|
|
77
|
+
/** @public */
|
|
78
|
+
baseUrl: string;
|
|
79
|
+
/** @public */
|
|
80
|
+
projectId: number;
|
|
81
|
+
/** @public */
|
|
82
|
+
iid: number;
|
|
83
|
+
/** @public */
|
|
84
|
+
instanceId: string;
|
|
85
|
+
/** @public */
|
|
86
|
+
writeKey: string;
|
|
87
|
+
/** @public */
|
|
88
|
+
discussionId?: string;
|
|
89
|
+
}): string {
|
|
90
|
+
const identity: (string | number)[] = [
|
|
91
|
+
input.baseUrl,
|
|
92
|
+
input.projectId,
|
|
93
|
+
input.iid,
|
|
94
|
+
input.instanceId,
|
|
95
|
+
input.writeKey,
|
|
96
|
+
];
|
|
97
|
+
if (input.discussionId) identity.push(input.discussionId);
|
|
98
|
+
return `<!-- leitwerk:gitlab:${hashIdentity(identity)} -->`;
|
|
99
|
+
}
|
|
68
100
|
/** @internal */
|
|
69
101
|
export async function ensureGitLabComment(input: {
|
|
70
102
|
/** @internal */
|
|
@@ -85,17 +117,22 @@ export async function ensureGitLabComment(input: {
|
|
|
85
117
|
discussionId?: string;
|
|
86
118
|
/** @internal */
|
|
87
119
|
signal?: AbortSignal;
|
|
88
|
-
/** @
|
|
89
|
-
|
|
120
|
+
/** Revalidated inside the durable write immediately before mutation. @internal */
|
|
121
|
+
beforeWrite?: () => Promise<void>;
|
|
90
122
|
}): Promise<{
|
|
91
123
|
/** @internal */
|
|
92
124
|
marker: string;
|
|
93
125
|
}> {
|
|
94
126
|
const { client, writes, instanceId, projectId, iid, writeKey, signal } = input;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
127
|
+
const marker = gitLabCommentMarker({
|
|
128
|
+
baseUrl: client.baseUrl,
|
|
129
|
+
projectId,
|
|
130
|
+
iid,
|
|
131
|
+
instanceId,
|
|
132
|
+
writeKey,
|
|
133
|
+
discussionId: input.discussionId,
|
|
134
|
+
});
|
|
135
|
+
const digest = marker.slice("<!-- leitwerk:gitlab:".length, -4);
|
|
99
136
|
const find = async () => {
|
|
100
137
|
const notes = input.discussionId
|
|
101
138
|
? (await client.getDiscussion(projectId, iid, input.discussionId, signal)).notes
|
|
@@ -106,7 +143,8 @@ export async function ensureGitLabComment(input: {
|
|
|
106
143
|
{ writeType: "gitlab.comment", dedupKey: digest },
|
|
107
144
|
{
|
|
108
145
|
reconcile: () => existingRemote(async () => (await find()) ?? null),
|
|
109
|
-
execute: () => {
|
|
146
|
+
execute: async () => {
|
|
147
|
+
await input.beforeWrite?.();
|
|
110
148
|
const body = `${input.body}\n\n${marker}`;
|
|
111
149
|
return input.discussionId
|
|
112
150
|
? client.replyToDiscussion(projectId, iid, input.discussionId, body, signal)
|
|
@@ -117,6 +155,187 @@ export async function ensureGitLabComment(input: {
|
|
|
117
155
|
);
|
|
118
156
|
return { marker };
|
|
119
157
|
}
|
|
158
|
+
/** Idempotently replace a retry-safe top-level comment while retaining its marker. @public */
|
|
159
|
+
export async function updateGitLabComment(input: {
|
|
160
|
+
/** @public */
|
|
161
|
+
client: GitLabClientLike;
|
|
162
|
+
/** @public */
|
|
163
|
+
instanceId: string;
|
|
164
|
+
/** @public */
|
|
165
|
+
projectId: number;
|
|
166
|
+
/** @public */
|
|
167
|
+
iid: number;
|
|
168
|
+
/** @public */
|
|
169
|
+
writeKey: string;
|
|
170
|
+
/** @public */
|
|
171
|
+
body: string;
|
|
172
|
+
/** @public */
|
|
173
|
+
signal?: AbortSignal;
|
|
174
|
+
/** @public */
|
|
175
|
+
beforeWrite?: () => Promise<void>;
|
|
176
|
+
}): Promise<{
|
|
177
|
+
/** @public */
|
|
178
|
+
marker: string;
|
|
179
|
+
}> {
|
|
180
|
+
const { client, instanceId, projectId, iid, writeKey, body, signal } = input;
|
|
181
|
+
const marker = gitLabCommentMarker({
|
|
182
|
+
baseUrl: client.baseUrl,
|
|
183
|
+
projectId,
|
|
184
|
+
iid,
|
|
185
|
+
instanceId,
|
|
186
|
+
writeKey,
|
|
187
|
+
});
|
|
188
|
+
const note = (await client.listNotes(projectId, iid, signal)).find((item) =>
|
|
189
|
+
item.body.includes(marker),
|
|
190
|
+
);
|
|
191
|
+
if (!note) throw new Error("GitLab comment to update was not found");
|
|
192
|
+
const next = `${body}\n\n${marker}`;
|
|
193
|
+
if (note.body !== next) {
|
|
194
|
+
await input.beforeWrite?.();
|
|
195
|
+
await client.updateNote(projectId, iid, note.id, next, signal);
|
|
196
|
+
}
|
|
197
|
+
return { marker };
|
|
198
|
+
}
|
|
199
|
+
/** @internal */
|
|
200
|
+
export async function ensureGitLabInlineComment(input: {
|
|
201
|
+
/** @internal */
|
|
202
|
+
client: GitLabClientLike;
|
|
203
|
+
/** @internal */
|
|
204
|
+
writes: ExternalWrites;
|
|
205
|
+
/** @internal */
|
|
206
|
+
instanceId: string;
|
|
207
|
+
/** @internal */
|
|
208
|
+
projectId: number;
|
|
209
|
+
/** @internal */
|
|
210
|
+
iid: number;
|
|
211
|
+
/** @internal */
|
|
212
|
+
writeKey: string;
|
|
213
|
+
/** @internal */
|
|
214
|
+
body: string;
|
|
215
|
+
/** @internal */
|
|
216
|
+
path: string;
|
|
217
|
+
/** @internal */
|
|
218
|
+
line: number;
|
|
219
|
+
/** @internal */
|
|
220
|
+
side: "new" | "old";
|
|
221
|
+
/** @internal */
|
|
222
|
+
baseSha: string;
|
|
223
|
+
/** @internal */
|
|
224
|
+
startSha: string;
|
|
225
|
+
/** @internal */
|
|
226
|
+
headSha: string;
|
|
227
|
+
/** @internal */
|
|
228
|
+
signal?: AbortSignal;
|
|
229
|
+
}): Promise<{ marker: string; discussionId: string }> {
|
|
230
|
+
const {
|
|
231
|
+
client,
|
|
232
|
+
writes,
|
|
233
|
+
instanceId,
|
|
234
|
+
projectId,
|
|
235
|
+
iid,
|
|
236
|
+
writeKey,
|
|
237
|
+
body,
|
|
238
|
+
path,
|
|
239
|
+
line,
|
|
240
|
+
side,
|
|
241
|
+
baseSha,
|
|
242
|
+
startSha,
|
|
243
|
+
headSha,
|
|
244
|
+
signal,
|
|
245
|
+
} = input;
|
|
246
|
+
const marker = gitLabCommentMarker({
|
|
247
|
+
baseUrl: client.baseUrl,
|
|
248
|
+
projectId,
|
|
249
|
+
iid,
|
|
250
|
+
instanceId,
|
|
251
|
+
writeKey,
|
|
252
|
+
});
|
|
253
|
+
const digest = marker.slice("<!-- leitwerk:gitlab:".length, -4);
|
|
254
|
+
const find = async () => {
|
|
255
|
+
const discussions = await client.listDiscussions(projectId, iid, signal);
|
|
256
|
+
return discussions.find((discussion) =>
|
|
257
|
+
discussion.notes.some((note) => note.body.includes(marker)),
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
const diff = (await client.getChanges(projectId, iid, signal)).find((candidate) =>
|
|
261
|
+
side === "new" ? candidate.new_path === path : candidate.old_path === path,
|
|
262
|
+
);
|
|
263
|
+
if (!diff) throw new Error("GitLab inline comment path is not in the merge request diff");
|
|
264
|
+
await writes.ensure(
|
|
265
|
+
{ writeType: "gitlab.discussion", dedupKey: digest },
|
|
266
|
+
{
|
|
267
|
+
reconcile: () => existingRemote(async () => (await find()) ?? null),
|
|
268
|
+
execute: () =>
|
|
269
|
+
client.addDiscussion(
|
|
270
|
+
projectId,
|
|
271
|
+
iid,
|
|
272
|
+
`${body}\n\n${marker}`,
|
|
273
|
+
{
|
|
274
|
+
position_type: "text",
|
|
275
|
+
base_sha: baseSha,
|
|
276
|
+
start_sha: startSha,
|
|
277
|
+
head_sha: headSha,
|
|
278
|
+
old_path: diff.old_path,
|
|
279
|
+
new_path: diff.new_path,
|
|
280
|
+
...(side === "new" ? { new_line: line } : { old_line: line }),
|
|
281
|
+
},
|
|
282
|
+
signal,
|
|
283
|
+
),
|
|
284
|
+
toMetadata: (discussion) => ({
|
|
285
|
+
projectId,
|
|
286
|
+
iid,
|
|
287
|
+
discussionId: discussion.id,
|
|
288
|
+
marker,
|
|
289
|
+
}),
|
|
290
|
+
},
|
|
291
|
+
);
|
|
292
|
+
const discussion = await find();
|
|
293
|
+
if (!discussion) throw new Error("GitLab inline discussion is unavailable after create");
|
|
294
|
+
return { marker, discussionId: discussion.id };
|
|
295
|
+
}
|
|
296
|
+
/** @public */
|
|
297
|
+
export async function ensureGitLabResolveDiscussion(input: {
|
|
298
|
+
/** @public */
|
|
299
|
+
client: GitLabClientLike;
|
|
300
|
+
/** @public */
|
|
301
|
+
writes: ExternalWrites;
|
|
302
|
+
/** @public */
|
|
303
|
+
instanceId: string;
|
|
304
|
+
/** @internal */
|
|
305
|
+
projectId: number;
|
|
306
|
+
/** @internal */
|
|
307
|
+
iid: number;
|
|
308
|
+
/** @public */
|
|
309
|
+
writeKey: string;
|
|
310
|
+
/** @public */
|
|
311
|
+
discussionId: string;
|
|
312
|
+
/** @public */
|
|
313
|
+
signal?: AbortSignal;
|
|
314
|
+
}): Promise<{ discussionId: string; resolved: boolean }> {
|
|
315
|
+
const { client, writes, instanceId, projectId, iid, writeKey, discussionId, signal } = input;
|
|
316
|
+
const digest = hashIdentity([
|
|
317
|
+
client.baseUrl,
|
|
318
|
+
projectId,
|
|
319
|
+
iid,
|
|
320
|
+
instanceId,
|
|
321
|
+
"resolve",
|
|
322
|
+
writeKey,
|
|
323
|
+
discussionId,
|
|
324
|
+
]);
|
|
325
|
+
await writes.ensure(
|
|
326
|
+
{ writeType: "gitlab.discussion.resolve", dedupKey: digest },
|
|
327
|
+
{
|
|
328
|
+
reconcile: () =>
|
|
329
|
+
existingRemote(async () => {
|
|
330
|
+
const discussion = await client.getDiscussion(projectId, iid, discussionId, signal);
|
|
331
|
+
return discussion.notes.some((note) => note.resolved) ? discussion : null;
|
|
332
|
+
}),
|
|
333
|
+
execute: () => client.resolveDiscussion(projectId, iid, discussionId, true, signal),
|
|
334
|
+
toMetadata: () => ({ projectId, iid, discussionId, resolved: true }),
|
|
335
|
+
},
|
|
336
|
+
);
|
|
337
|
+
return { discussionId, resolved: true };
|
|
338
|
+
}
|
|
120
339
|
/** @public */
|
|
121
340
|
export async function ensureGitLabSeenReaction(input: {
|
|
122
341
|
/** @public */
|
|
@@ -133,11 +352,11 @@ export async function ensureGitLabSeenReaction(input: {
|
|
|
133
352
|
noteId: number;
|
|
134
353
|
/** @public */
|
|
135
354
|
signal?: AbortSignal;
|
|
355
|
+
/** @public */
|
|
356
|
+
beforeWrite?: () => Promise<void>;
|
|
136
357
|
}): Promise<void> {
|
|
137
358
|
const { client, writes, instanceId, projectId, iid, noteId, signal } = input;
|
|
138
|
-
const digest =
|
|
139
|
-
.update(JSON.stringify([client.baseUrl, projectId, iid, instanceId, "eyes", noteId]))
|
|
140
|
-
.digest("hex");
|
|
359
|
+
const digest = hashIdentity([client.baseUrl, projectId, iid, instanceId, "eyes", noteId]);
|
|
141
360
|
await writes.ensure(
|
|
142
361
|
{ writeType: "gitlab.reaction", dedupKey: digest },
|
|
143
362
|
{
|
|
@@ -151,13 +370,101 @@ export async function ensureGitLabSeenReaction(input: {
|
|
|
151
370
|
) ?? null
|
|
152
371
|
);
|
|
153
372
|
}),
|
|
154
|
-
execute: () =>
|
|
373
|
+
execute: async () => {
|
|
374
|
+
await input.beforeWrite?.();
|
|
375
|
+
return client.addNoteReaction(projectId, iid, noteId, "eyes", signal);
|
|
376
|
+
},
|
|
155
377
|
toMetadata: (reaction) => ({ projectId, iid, noteId, reactionId: reaction.id, name: "eyes" }),
|
|
156
378
|
},
|
|
157
379
|
);
|
|
158
380
|
}
|
|
159
381
|
/** @internal */
|
|
160
|
-
export function registerGitLabTools(
|
|
382
|
+
export function registerGitLabTools(
|
|
383
|
+
api: ServerExtensionAPI,
|
|
384
|
+
integration: GitLabIntegration,
|
|
385
|
+
beforeWrite?: (ctx: IntegrationToolExecutionContext) => Promise<void>,
|
|
386
|
+
) {
|
|
387
|
+
for (const name of [
|
|
388
|
+
"gitlab_inspect_project",
|
|
389
|
+
"gitlab_repository_tree",
|
|
390
|
+
"gitlab_repository_file",
|
|
391
|
+
"gitlab_code_search",
|
|
392
|
+
] as const)
|
|
393
|
+
api.tool<Record<string, unknown>>({
|
|
394
|
+
name,
|
|
395
|
+
description:
|
|
396
|
+
name === "gitlab_code_search"
|
|
397
|
+
? "Search blobs in a bound GitLab repository at a full commit. Follow nextPage until null, then read matching files for complete evidence. Search failure is not an empty result."
|
|
398
|
+
: "Inspect a bound GitLab repository. Use the returned commit ID as ref for subsequent tree/file reads.",
|
|
399
|
+
parameters:
|
|
400
|
+
name === "gitlab_code_search"
|
|
401
|
+
? projectParameters(
|
|
402
|
+
{
|
|
403
|
+
ref: { type: "string" },
|
|
404
|
+
search: { type: "string" },
|
|
405
|
+
page: { type: "integer", minimum: 1 },
|
|
406
|
+
perPage: { type: "integer", minimum: 1, maximum: 100 },
|
|
407
|
+
},
|
|
408
|
+
["ref", "search"],
|
|
409
|
+
)
|
|
410
|
+
: projectParameters(
|
|
411
|
+
{ ref: { type: "string" }, path: { type: "string" } },
|
|
412
|
+
name === "gitlab_inspect_project"
|
|
413
|
+
? []
|
|
414
|
+
: name === "gitlab_repository_tree"
|
|
415
|
+
? ["ref"]
|
|
416
|
+
: ["ref", "path"],
|
|
417
|
+
),
|
|
418
|
+
async execute(ctx, args) {
|
|
419
|
+
const binding = resolveGitLabRepositoryBinding(ctx, integration);
|
|
420
|
+
const client = integration.client(binding.profile);
|
|
421
|
+
if (name === "gitlab_inspect_project")
|
|
422
|
+
return {
|
|
423
|
+
project: await client.getProject(binding.projectId, ctx.signal),
|
|
424
|
+
branch: await client.getBranch(binding.projectId, ctx.project!.baseBranch, ctx.signal),
|
|
425
|
+
};
|
|
426
|
+
const ref = stringArg(args, "ref");
|
|
427
|
+
if (!/^[a-f0-9]{40,64}$/i.test(ref))
|
|
428
|
+
throw new Error("Repository reads require a commit ID returned by inspection");
|
|
429
|
+
if (name === "gitlab_code_search") {
|
|
430
|
+
if (!client.searchRepositoryCode)
|
|
431
|
+
throw new Error("GitLab code search unavailable; no search was performed");
|
|
432
|
+
return client.searchRepositoryCode(
|
|
433
|
+
binding.projectId,
|
|
434
|
+
ref,
|
|
435
|
+
stringArg(args, "search"),
|
|
436
|
+
args.page === undefined ? 1 : numberArg(args, "page"),
|
|
437
|
+
args.perPage === undefined ? 20 : numberArg(args, "perPage"),
|
|
438
|
+
ctx.signal,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
if (name === "gitlab_repository_tree") {
|
|
442
|
+
if (!client.listRepositoryTree) throw new Error("Repository tree inspection unavailable");
|
|
443
|
+
return client.listRepositoryTree(
|
|
444
|
+
binding.projectId,
|
|
445
|
+
ref,
|
|
446
|
+
typeof args.path === "string" ? args.path : "",
|
|
447
|
+
ctx.signal,
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
if (!client.getRepositoryFile) throw new Error("Repository file inspection unavailable");
|
|
451
|
+
const file = await client.getRepositoryFile(
|
|
452
|
+
binding.projectId,
|
|
453
|
+
ref,
|
|
454
|
+
stringArg(args, "path"),
|
|
455
|
+
ctx.signal,
|
|
456
|
+
);
|
|
457
|
+
return {
|
|
458
|
+
...file,
|
|
459
|
+
content:
|
|
460
|
+
file.encoding === "base64"
|
|
461
|
+
? Buffer.from(file.content, "base64").toString("utf8")
|
|
462
|
+
: file.content,
|
|
463
|
+
encoding: "utf8",
|
|
464
|
+
revision: ref,
|
|
465
|
+
};
|
|
466
|
+
},
|
|
467
|
+
});
|
|
161
468
|
for (const [name, description, required] of [
|
|
162
469
|
["gitlab_observe_merge_request", "Read the current MR source revision and its latest CI", []],
|
|
163
470
|
["gitlab_get_changes", "Read the MR changes", []],
|
|
@@ -169,11 +476,22 @@ export function registerGitLabTools(api: ServerExtensionAPI, integration: GitLab
|
|
|
169
476
|
["pipelineId", "jobId"],
|
|
170
477
|
],
|
|
171
478
|
["gitlab_comment", "Post a retry-safe MR comment", ["body", "writeKey"]],
|
|
479
|
+
["gitlab_update_comment", "Update a retry-safe MR comment", ["body", "writeKey"]],
|
|
480
|
+
[
|
|
481
|
+
"gitlab_inline_comment",
|
|
482
|
+
"Post a retry-safe MR inline discussion",
|
|
483
|
+
["body", "writeKey", "path", "line", "side", "baseSha", "startSha", "headSha"],
|
|
484
|
+
],
|
|
172
485
|
[
|
|
173
486
|
"gitlab_reply",
|
|
174
487
|
"Post a retry-safe reply in an MR discussion",
|
|
175
488
|
["body", "writeKey", "discussionId"],
|
|
176
489
|
],
|
|
490
|
+
[
|
|
491
|
+
"gitlab_resolve_discussion",
|
|
492
|
+
"Resolve a retry-safe MR inline discussion",
|
|
493
|
+
["writeKey", "discussionId"],
|
|
494
|
+
],
|
|
177
495
|
] as const) {
|
|
178
496
|
api.tool<Record<string, unknown>>({
|
|
179
497
|
name,
|
|
@@ -186,30 +504,68 @@ export function registerGitLabTools(api: ServerExtensionAPI, integration: GitLab
|
|
|
186
504
|
body: { type: "string" },
|
|
187
505
|
writeKey: { type: "string" },
|
|
188
506
|
discussionId: { type: "string" },
|
|
507
|
+
path: { type: "string" },
|
|
508
|
+
line: { type: "integer" },
|
|
509
|
+
side: { type: "string" },
|
|
510
|
+
baseSha: { type: "string" },
|
|
511
|
+
startSha: { type: "string" },
|
|
512
|
+
headSha: { type: "string" },
|
|
189
513
|
},
|
|
190
514
|
[...required],
|
|
191
515
|
),
|
|
192
516
|
async execute(ctx, args) {
|
|
193
517
|
if (name === "gitlab_get_identity")
|
|
194
518
|
return integration
|
|
195
|
-
.client(resolveGitLabRepositoryBinding(ctx).profile)
|
|
519
|
+
.client(resolveGitLabRepositoryBinding(ctx, integration).profile)
|
|
196
520
|
.resolveGitIdentity(ctx.signal);
|
|
197
|
-
const b = resolveGitLabBinding(ctx);
|
|
521
|
+
const b = resolveGitLabBinding(ctx, integration);
|
|
198
522
|
const client = integration.client(b.profile);
|
|
199
523
|
if (name === "gitlab_observe_merge_request")
|
|
200
524
|
return observeMergeRequest(client, b.projectId, b.iid, ctx.signal);
|
|
201
525
|
if (name === "gitlab_get_changes") return client.getChanges(b.projectId, b.iid, ctx.signal);
|
|
526
|
+
const writeContext = {
|
|
527
|
+
client,
|
|
528
|
+
writes: ctx.externalWrites,
|
|
529
|
+
instanceId: ctx.process.id,
|
|
530
|
+
projectId: b.projectId,
|
|
531
|
+
iid: b.iid,
|
|
532
|
+
signal: ctx.signal,
|
|
533
|
+
};
|
|
534
|
+
if (name === "gitlab_update_comment")
|
|
535
|
+
return updateGitLabComment({
|
|
536
|
+
...writeContext,
|
|
537
|
+
beforeWrite: beforeWrite ? () => beforeWrite(ctx) : undefined,
|
|
538
|
+
writeKey: stringArg(args, "writeKey"),
|
|
539
|
+
body: stringArg(args, "body"),
|
|
540
|
+
});
|
|
541
|
+
if (name === "gitlab_inline_comment") {
|
|
542
|
+
const side = stringArg(args, "side");
|
|
543
|
+
if (side !== "new" && side !== "old")
|
|
544
|
+
throw new Error("GitLab inline comment side must be new or old");
|
|
545
|
+
return ensureGitLabInlineComment({
|
|
546
|
+
...writeContext,
|
|
547
|
+
writeKey: stringArg(args, "writeKey"),
|
|
548
|
+
body: stringArg(args, "body"),
|
|
549
|
+
path: stringArg(args, "path"),
|
|
550
|
+
line: numberArg(args, "line"),
|
|
551
|
+
side,
|
|
552
|
+
baseSha: stringArg(args, "baseSha"),
|
|
553
|
+
startSha: stringArg(args, "startSha"),
|
|
554
|
+
headSha: stringArg(args, "headSha"),
|
|
555
|
+
});
|
|
556
|
+
}
|
|
202
557
|
if (name === "gitlab_comment" || name === "gitlab_reply")
|
|
203
558
|
return ensureGitLabComment({
|
|
204
|
-
|
|
205
|
-
writes: ctx.externalWrites,
|
|
206
|
-
instanceId: ctx.process.id,
|
|
207
|
-
projectId: b.projectId,
|
|
208
|
-
iid: b.iid,
|
|
559
|
+
...writeContext,
|
|
209
560
|
writeKey: stringArg(args, "writeKey"),
|
|
210
561
|
body: stringArg(args, "body"),
|
|
211
562
|
...(name === "gitlab_reply" ? { discussionId: stringArg(args, "discussionId") } : {}),
|
|
212
|
-
|
|
563
|
+
});
|
|
564
|
+
if (name === "gitlab_resolve_discussion")
|
|
565
|
+
return ensureGitLabResolveDiscussion({
|
|
566
|
+
...writeContext,
|
|
567
|
+
writeKey: stringArg(args, "writeKey"),
|
|
568
|
+
discussionId: stringArg(args, "discussionId"),
|
|
213
569
|
});
|
|
214
570
|
const observation = await observeMergeRequest(client, b.projectId, b.iid, ctx.signal);
|
|
215
571
|
if (!observation.pipeline || observation.pipeline.id !== numberArg(args, "pipelineId"))
|