@leitwerk-dev/gitlab 0.3.1 → 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 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/external.d.ts +23 -1
- 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 -0
- 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 -6
- package/src/delivery-tools.ts +4 -4
- package/src/external.ts +90 -19
- package/src/index.ts +58 -10
- package/src/issue-watcher.ts +10 -1
- 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 -23
- package/dist/chunk-TQIZKDAM.js +0 -1160
- package/dist/chunk-TQIZKDAM.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,7 +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
|
-
|
|
28
|
+
integration?: GitLabIntegration,
|
|
26
29
|
): {
|
|
27
30
|
/** @public */
|
|
28
31
|
profile: string;
|
|
@@ -32,7 +35,7 @@ export function resolveGitLabRepositoryBinding(
|
|
|
32
35
|
if (!ctx.project || ctx.project.instanceId !== ctx.process.id)
|
|
33
36
|
throw new Error("An authorized GitLab process project is required");
|
|
34
37
|
const binding = ctx.project.metadata?.gitlab as
|
|
35
|
-
| { profile?: unknown; projectId?: unknown }
|
|
38
|
+
| { profile?: unknown; projectId?: unknown; origin?: unknown }
|
|
36
39
|
| undefined;
|
|
37
40
|
if (
|
|
38
41
|
!binding ||
|
|
@@ -43,12 +46,18 @@ export function resolveGitLabRepositoryBinding(
|
|
|
43
46
|
binding.projectId <= 0
|
|
44
47
|
)
|
|
45
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");
|
|
46
55
|
return { profile: binding.profile, projectId: binding.projectId };
|
|
47
56
|
}
|
|
48
57
|
/** @public */
|
|
49
58
|
export function resolveGitLabBinding(
|
|
50
59
|
ctx: Pick<IntegrationToolExecutionContext, "project" | "process">,
|
|
51
|
-
|
|
60
|
+
integration?: GitLabIntegration,
|
|
52
61
|
): {
|
|
53
62
|
/** @public */
|
|
54
63
|
profile: string;
|
|
@@ -57,12 +66,37 @@ export function resolveGitLabBinding(
|
|
|
57
66
|
/** @public */
|
|
58
67
|
iid: number;
|
|
59
68
|
} {
|
|
60
|
-
const repository = resolveGitLabRepositoryBinding(ctx);
|
|
69
|
+
const repository = resolveGitLabRepositoryBinding(ctx, integration);
|
|
61
70
|
const iid = (ctx.project?.metadata?.gitlab as { iid?: unknown })?.iid;
|
|
62
71
|
if (typeof iid !== "number" || !Number.isSafeInteger(iid) || iid <= 0)
|
|
63
72
|
throw new Error("Invalid GitLab project binding: a merge request is required");
|
|
64
73
|
return { ...repository, iid };
|
|
65
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
|
+
}
|
|
66
100
|
/** @internal */
|
|
67
101
|
export async function ensureGitLabComment(input: {
|
|
68
102
|
/** @internal */
|
|
@@ -83,16 +117,22 @@ export async function ensureGitLabComment(input: {
|
|
|
83
117
|
discussionId?: string;
|
|
84
118
|
/** @internal */
|
|
85
119
|
signal?: AbortSignal;
|
|
86
|
-
/** @
|
|
120
|
+
/** Revalidated inside the durable write immediately before mutation. @internal */
|
|
121
|
+
beforeWrite?: () => Promise<void>;
|
|
87
122
|
}): Promise<{
|
|
88
123
|
/** @internal */
|
|
89
124
|
marker: string;
|
|
90
125
|
}> {
|
|
91
126
|
const { client, writes, instanceId, projectId, iid, writeKey, signal } = input;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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);
|
|
96
136
|
const find = async () => {
|
|
97
137
|
const notes = input.discussionId
|
|
98
138
|
? (await client.getDiscussion(projectId, iid, input.discussionId, signal)).notes
|
|
@@ -103,7 +143,8 @@ export async function ensureGitLabComment(input: {
|
|
|
103
143
|
{ writeType: "gitlab.comment", dedupKey: digest },
|
|
104
144
|
{
|
|
105
145
|
reconcile: () => existingRemote(async () => (await find()) ?? null),
|
|
106
|
-
execute: () => {
|
|
146
|
+
execute: async () => {
|
|
147
|
+
await input.beforeWrite?.();
|
|
107
148
|
const body = `${input.body}\n\n${marker}`;
|
|
108
149
|
return input.discussionId
|
|
109
150
|
? client.replyToDiscussion(projectId, iid, input.discussionId, body, signal)
|
|
@@ -114,6 +155,187 @@ export async function ensureGitLabComment(input: {
|
|
|
114
155
|
);
|
|
115
156
|
return { marker };
|
|
116
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
|
+
}
|
|
117
339
|
/** @public */
|
|
118
340
|
export async function ensureGitLabSeenReaction(input: {
|
|
119
341
|
/** @public */
|
|
@@ -130,11 +352,11 @@ export async function ensureGitLabSeenReaction(input: {
|
|
|
130
352
|
noteId: number;
|
|
131
353
|
/** @public */
|
|
132
354
|
signal?: AbortSignal;
|
|
355
|
+
/** @public */
|
|
356
|
+
beforeWrite?: () => Promise<void>;
|
|
133
357
|
}): Promise<void> {
|
|
134
358
|
const { client, writes, instanceId, projectId, iid, noteId, signal } = input;
|
|
135
|
-
const digest =
|
|
136
|
-
.update(JSON.stringify([client.baseUrl, projectId, iid, instanceId, "eyes", noteId]))
|
|
137
|
-
.digest("hex");
|
|
359
|
+
const digest = hashIdentity([client.baseUrl, projectId, iid, instanceId, "eyes", noteId]);
|
|
138
360
|
await writes.ensure(
|
|
139
361
|
{ writeType: "gitlab.reaction", dedupKey: digest },
|
|
140
362
|
{
|
|
@@ -148,13 +370,101 @@ export async function ensureGitLabSeenReaction(input: {
|
|
|
148
370
|
) ?? null
|
|
149
371
|
);
|
|
150
372
|
}),
|
|
151
|
-
execute: () =>
|
|
373
|
+
execute: async () => {
|
|
374
|
+
await input.beforeWrite?.();
|
|
375
|
+
return client.addNoteReaction(projectId, iid, noteId, "eyes", signal);
|
|
376
|
+
},
|
|
152
377
|
toMetadata: (reaction) => ({ projectId, iid, noteId, reactionId: reaction.id, name: "eyes" }),
|
|
153
378
|
},
|
|
154
379
|
);
|
|
155
380
|
}
|
|
156
381
|
/** @internal */
|
|
157
|
-
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
|
+
});
|
|
158
468
|
for (const [name, description, required] of [
|
|
159
469
|
["gitlab_observe_merge_request", "Read the current MR source revision and its latest CI", []],
|
|
160
470
|
["gitlab_get_changes", "Read the MR changes", []],
|
|
@@ -166,11 +476,22 @@ export function registerGitLabTools(api: ServerExtensionAPI, integration: GitLab
|
|
|
166
476
|
["pipelineId", "jobId"],
|
|
167
477
|
],
|
|
168
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
|
+
],
|
|
169
485
|
[
|
|
170
486
|
"gitlab_reply",
|
|
171
487
|
"Post a retry-safe reply in an MR discussion",
|
|
172
488
|
["body", "writeKey", "discussionId"],
|
|
173
489
|
],
|
|
490
|
+
[
|
|
491
|
+
"gitlab_resolve_discussion",
|
|
492
|
+
"Resolve a retry-safe MR inline discussion",
|
|
493
|
+
["writeKey", "discussionId"],
|
|
494
|
+
],
|
|
174
495
|
] as const) {
|
|
175
496
|
api.tool<Record<string, unknown>>({
|
|
176
497
|
name,
|
|
@@ -183,30 +504,68 @@ export function registerGitLabTools(api: ServerExtensionAPI, integration: GitLab
|
|
|
183
504
|
body: { type: "string" },
|
|
184
505
|
writeKey: { type: "string" },
|
|
185
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" },
|
|
186
513
|
},
|
|
187
514
|
[...required],
|
|
188
515
|
),
|
|
189
516
|
async execute(ctx, args) {
|
|
190
517
|
if (name === "gitlab_get_identity")
|
|
191
518
|
return integration
|
|
192
|
-
.client(resolveGitLabRepositoryBinding(ctx).profile)
|
|
519
|
+
.client(resolveGitLabRepositoryBinding(ctx, integration).profile)
|
|
193
520
|
.resolveGitIdentity(ctx.signal);
|
|
194
|
-
const b = resolveGitLabBinding(ctx);
|
|
521
|
+
const b = resolveGitLabBinding(ctx, integration);
|
|
195
522
|
const client = integration.client(b.profile);
|
|
196
523
|
if (name === "gitlab_observe_merge_request")
|
|
197
524
|
return observeMergeRequest(client, b.projectId, b.iid, ctx.signal);
|
|
198
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
|
+
}
|
|
199
557
|
if (name === "gitlab_comment" || name === "gitlab_reply")
|
|
200
558
|
return ensureGitLabComment({
|
|
201
|
-
|
|
202
|
-
writes: ctx.externalWrites,
|
|
203
|
-
instanceId: ctx.process.id,
|
|
204
|
-
projectId: b.projectId,
|
|
205
|
-
iid: b.iid,
|
|
559
|
+
...writeContext,
|
|
206
560
|
writeKey: stringArg(args, "writeKey"),
|
|
207
561
|
body: stringArg(args, "body"),
|
|
208
562
|
...(name === "gitlab_reply" ? { discussionId: stringArg(args, "discussionId") } : {}),
|
|
209
|
-
|
|
563
|
+
});
|
|
564
|
+
if (name === "gitlab_resolve_discussion")
|
|
565
|
+
return ensureGitLabResolveDiscussion({
|
|
566
|
+
...writeContext,
|
|
567
|
+
writeKey: stringArg(args, "writeKey"),
|
|
568
|
+
discussionId: stringArg(args, "discussionId"),
|
|
210
569
|
});
|
|
211
570
|
const observation = await observeMergeRequest(client, b.projectId, b.iid, ctx.signal);
|
|
212
571
|
if (!observation.pipeline || observation.pipeline.id !== numberArg(args, "pipelineId"))
|