@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.
Files changed (56) hide show
  1. package/README.md +154 -1
  2. package/dist/capability.d.ts +3 -0
  3. package/dist/capability.d.ts.map +1 -1
  4. package/dist/chunk-YPCOVBQS.js +2343 -0
  5. package/dist/chunk-YPCOVBQS.js.map +1 -0
  6. package/dist/client.d.ts +99 -7
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/external.d.ts +24 -4
  9. package/dist/external.d.ts.map +1 -1
  10. package/dist/index.d.ts +8 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +512 -10
  13. package/dist/index.js.map +1 -1
  14. package/dist/issue-watcher.d.ts +2 -2
  15. package/dist/issue-watcher.d.ts.map +1 -1
  16. package/dist/launch.d.ts +40 -0
  17. package/dist/launch.d.ts.map +1 -0
  18. package/dist/maintenance-labels.d.ts +30 -0
  19. package/dist/maintenance-labels.d.ts.map +1 -0
  20. package/dist/maintenance.d.ts +132 -0
  21. package/dist/maintenance.d.ts.map +1 -0
  22. package/dist/publication-maintenance.d.ts +7 -0
  23. package/dist/publication-maintenance.d.ts.map +1 -0
  24. package/dist/publication.d.ts +37 -0
  25. package/dist/publication.d.ts.map +1 -0
  26. package/dist/repository-catalog.d.ts +16 -0
  27. package/dist/repository-catalog.d.ts.map +1 -0
  28. package/dist/setup.d.ts +8 -2
  29. package/dist/setup.d.ts.map +1 -1
  30. package/dist/testing.d.ts +10 -1
  31. package/dist/testing.d.ts.map +1 -1
  32. package/dist/testing.js +125 -5
  33. package/dist/testing.js.map +1 -1
  34. package/dist/ticket-creation.d.ts +5 -0
  35. package/dist/ticket-creation.d.ts.map +1 -0
  36. package/dist/tools.d.ts +100 -3
  37. package/dist/tools.d.ts.map +1 -1
  38. package/package.json +7 -7
  39. package/src/capability.ts +3 -0
  40. package/src/client.ts +275 -12
  41. package/src/delivery-tools.ts +4 -4
  42. package/src/external.ts +91 -24
  43. package/src/index.ts +58 -10
  44. package/src/issue-watcher.ts +16 -14
  45. package/src/launch.ts +63 -0
  46. package/src/maintenance-labels.ts +129 -0
  47. package/src/maintenance.ts +759 -0
  48. package/src/publication-maintenance.ts +288 -0
  49. package/src/publication.ts +234 -0
  50. package/src/repository-catalog.ts +94 -0
  51. package/src/setup.ts +115 -6
  52. package/src/testing.ts +143 -4
  53. package/src/ticket-creation.ts +145 -0
  54. package/src/tools.ts +382 -26
  55. package/dist/chunk-H4JCQNDY.js +0 -1162
  56. package/dist/chunk-H4JCQNDY.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,24 +1,504 @@
1
1
  import {
2
+ GITLAB_ACTIVE_LABEL,
3
+ GITLAB_DONE_LABEL,
4
+ GITLAB_MAINTAINED_KIND,
2
5
  GitLabClient,
6
+ GitLabError,
7
+ createGitLabRepositoryCatalog,
8
+ ensureGitLabComment,
3
9
  ensureGitLabSeenReaction,
10
+ gitLabActivationStatus,
11
+ gitLabCommentMarker,
4
12
  gitLabFeedbackReadyAt,
5
13
  gitlabExternal,
6
14
  gitlabIntegration,
7
15
  gitlabIssueExternalId,
8
16
  gitlabIssueWatcherSource,
17
+ gitlabMaintenance,
18
+ gitlabMaintenanceSource,
9
19
  gitlabRepositoryCredentials,
10
20
  observationKey,
11
21
  observeMergeRequest,
12
22
  parseGitLabProfiles,
13
23
  parseGitLabSelection,
14
24
  pendingGitLabFeedback,
25
+ readGitLabLabels,
26
+ registerGitLabMaintainedProcess,
15
27
  resolveGitLabBinding,
28
+ resolveGitLabRepositoryBinding,
16
29
  selectGitLabProjects,
17
30
  setupGitLabIntegration
18
- } from "./chunk-H4JCQNDY.js";
31
+ } from "./chunk-YPCOVBQS.js";
32
+
33
+ // src/index.ts
34
+ import { coreHostCapabilities, parseTicketCreationConfig } from "@leitwerk-dev/process-sdk";
35
+
36
+ // src/launch.ts
37
+ import { repositoryHttpsUrl } from "@leitwerk-dev/process-sdk";
38
+ async function resolveGitLabLaunchProject(client, profile, repository, workBranch, key = "repo", transport = "ssh") {
39
+ const repoLocator = transport === "ssh" ? repository.ssh_url_to_repo : repository.http_url_to_repo;
40
+ if (!repoLocator)
41
+ throw new Error(`GitLab repository has no ${transport.toUpperCase()} clone URL`);
42
+ if (transport === "https" && repositoryHttpsUrl(repoLocator).origin !== client.baseUrl)
43
+ throw new Error("GitLab repository origin does not match its profile");
44
+ const split = repository.path_with_namespace.lastIndexOf("/");
45
+ if (split < 1) throw new Error("Invalid GitLab project path");
46
+ const params = {
47
+ /** @internal */
48
+ gitlabProfile: profile,
49
+ /** @internal */
50
+ gitlabOrigin: client.baseUrl,
51
+ /** @internal */
52
+ projectId: repository.id,
53
+ /** @internal */
54
+ owner: repository.path_with_namespace.slice(0, split),
55
+ /** @internal */
56
+ repo: repository.path_with_namespace.slice(split + 1),
57
+ /** @internal */
58
+ repoLocator,
59
+ /** @internal */
60
+ baseBranch: repository.default_branch,
61
+ /** @internal */
62
+ workBranch
63
+ };
64
+ const identity = await client.resolveGitIdentity();
65
+ return {
66
+ /** @internal */
67
+ params,
68
+ /** @internal */
69
+ project: {
70
+ /** @internal */
71
+ key,
72
+ /** @internal */
73
+ repoLocator: params.repoLocator,
74
+ /** @internal */
75
+ baseBranch: params.baseBranch,
76
+ /** @internal */
77
+ workBranch,
78
+ /** @internal */
79
+ settingsRepository: {
80
+ /** @internal */
81
+ origin: client.baseUrl,
82
+ /** @internal */
83
+ repositoryId: repository.id,
84
+ /** @internal */
85
+ aliases: [
86
+ repository.http_url_to_repo,
87
+ ...repository.ssh_url_to_repo ? [repository.ssh_url_to_repo] : []
88
+ ]
89
+ },
90
+ /** @internal */
91
+ metadata: {
92
+ /** @internal */
93
+ gitlab: {
94
+ /** @internal */
95
+ origin: client.baseUrl,
96
+ /** @internal */
97
+ profile,
98
+ /** @internal */
99
+ projectId: repository.id
100
+ },
101
+ /** @internal */
102
+ "leitwerk.gitIdentity": {
103
+ /** @internal */
104
+ provider: "gitlab",
105
+ /** @internal */
106
+ profile,
107
+ /** @internal */
108
+ login: identity.username,
109
+ /** @internal */
110
+ name: identity.name,
111
+ /** @internal */
112
+ email: identity.email
113
+ }
114
+ }
115
+ }
116
+ };
117
+ }
118
+
119
+ // src/publication.ts
120
+ import {
121
+ resolvePullRequestGitIdentity
122
+ } from "@leitwerk-dev/coding/repository-change-publication";
123
+
124
+ // src/publication-maintenance.ts
125
+ import {
126
+ applyPublicationEvidence,
127
+ createPublicationSelection,
128
+ patchPublicationState,
129
+ publicationFinished,
130
+ readPublicationState,
131
+ requirePublicationParams
132
+ } from "@leitwerk-dev/coding/repository-change-publication";
133
+ import { conflictKey } from "@leitwerk-dev/coding/repository-rebase";
134
+ function registerGitLabPublicationMaintenance(api, process, adapter) {
135
+ const namespace = (key) => adapter.repositories ? `${adapter.namespace}:${key}` : adapter.namespace;
136
+ const current = (ctx, key) => readPublicationState(ctx.state, namespace(key));
137
+ const params = (ctx, key) => requirePublicationParams(
138
+ adapter.repositories?.(ctx.params).find((repository) => repository.key === key)?.params ?? ctx.params
139
+ );
140
+ const patch = (ctx, key, value) => patchPublicationState(ctx.state, namespace(key), value);
141
+ const selection = createPublicationSelection(() => adapter.namespace);
142
+ const select = (state, key) => adapter.repositories ? selection.select(state, key) : state;
143
+ const repositories = (ctx) => adapter.repositories?.(ctx.params) ?? [{ key: "repo", params: ctx.params }];
144
+ const results = (ctx) => repositories(ctx).map(({ key }) => ({ key, current: current(ctx, key) }));
145
+ const workerContext = (ctx, key) => ({
146
+ ...ctx,
147
+ params: params(ctx, key),
148
+ state: select(ctx.state, key),
149
+ repo: {
150
+ get: (name) => {
151
+ const project = ctx.projects.find(
152
+ (project2) => project2.key === (name === "repo" ? key : name)
153
+ );
154
+ if (!project) throw new Error("Maintained process project is unavailable");
155
+ return { ...project, fsPath: "", workBranch: project.workBranch ?? project.baseBranch };
156
+ }
157
+ },
158
+ callIntegrationTool: (name, args) => ctx.callIntegrationTool(name, { ...args, projectKey: key })
159
+ });
160
+ registerGitLabMaintainedProcess(api, {
161
+ processId: process.id,
162
+ paramsCodec: process.paramsCodec,
163
+ stateCodec: process.stateCodec,
164
+ destinations: {
165
+ feedback: "maintenance_feedback",
166
+ conflict: "maintenance_conflict",
167
+ ci: "maintenance_ci"
168
+ },
169
+ idleTurnId: adapter.ids.deliver,
170
+ currentBinding: (ctx) => adapter.repositories ? selection.activeKey(ctx.state) : "repo",
171
+ settings: (ctx, binding) => ({
172
+ cursor: current(ctx, binding.projectKey).conversationCursor,
173
+ quietPeriodMs: 12e4,
174
+ pollInterval: "30s"
175
+ }),
176
+ observe(ctx, binding, observed) {
177
+ const key = binding.projectKey;
178
+ let value = current(ctx, key);
179
+ const p = params(ctx, key);
180
+ if (publicationFinished(value)) return { state: ctx.state };
181
+ if (ctx.process.selectedTurnId === adapter.ids.deliver && !ctx.process.currentExecution && !value.delivery.adjustment && !value.delivery.feedbackResult) {
182
+ if (value.feedbackIds.length) return { state: select(ctx.state, key), action: "feedback" };
183
+ if (value.conflict && value.repairReason === "rebase")
184
+ return { state: select(ctx.state, key), action: "conflict" };
185
+ if (value.repairPending && value.repairReason === "ci" && value.pipeline)
186
+ return { state: select(ctx.state, key), action: "ci" };
187
+ }
188
+ let evidence;
189
+ if (value.pendingEvidence) {
190
+ evidence = value.pendingEvidence;
191
+ value = { ...value, pendingEvidence: null };
192
+ } else {
193
+ if (value.delivery.adjustment || value.delivery.feedbackResult || value.feedbackIds.length || !value.headSha || !value.prNumber)
194
+ return { state: ctx.state };
195
+ let event = observed;
196
+ if (!observed.targetIntegrated && observed.mr.sha === value.headSha && observed.targetHead && (observed.mr.has_conflicts || ["conflict", "need_rebase"].includes(observed.mr.detailed_merge_status ?? ""))) {
197
+ if (observed.mr.source_project_id !== binding.projectId || observed.mr.target_project_id !== binding.projectId || observed.mr.source_branch !== p.workBranch || observed.mr.target_branch !== p.baseBranch)
198
+ throw new Error("GitLab maintenance branch binding changed");
199
+ const conflict = {
200
+ owner: p.owner,
201
+ repo: p.repo,
202
+ prNumber: value.prNumber,
203
+ headBranch: p.workBranch,
204
+ baseBranch: p.baseBranch,
205
+ headSha: value.headSha,
206
+ baseSha: observed.targetHead,
207
+ url: observed.mr.web_url
208
+ };
209
+ if (conflictKey(conflict) !== value.lastConflictKey) event = { ...observed, conflict };
210
+ }
211
+ evidence = gitlabPublicationEvidenceForRequest(value, event);
212
+ }
213
+ if (evidence.kind === "terminal")
214
+ return {
215
+ state: patch(ctx, key, {
216
+ delivery: { terminalPullRequest: evidence.request }
217
+ })
218
+ };
219
+ const dispatch = (action, operator = false) => ({
220
+ state: select(
221
+ patch(ctx, key, {
222
+ ...applyPublicationEvidence(p, value, evidence, !operator),
223
+ repairPending: !operator,
224
+ // Dispatch does not consume feedback; publication/no-change acknowledgement does.
225
+ ...evidence.kind === "feedback" ? { conversationCursor: value.conversationCursor } : {}
226
+ }),
227
+ key
228
+ ),
229
+ action
230
+ });
231
+ if (evidence.kind === "feedback" || evidence.kind === "conflict")
232
+ return dispatch(evidence.kind);
233
+ if (evidence.kind === "failure" && (value.pipeline?.status !== "failed" || value.pipeline.number !== evidence.pipeline.number || (value.pipeline.project_id ?? binding.projectId) !== (evidence.pipeline.project_id ?? binding.projectId))) {
234
+ const operator = value.ciRecoveryCycles >= 3;
235
+ return dispatch(operator ? "maintenance_operator" : "ci", operator);
236
+ }
237
+ return {
238
+ state: patch(ctx, key, {
239
+ ...value,
240
+ observationKey: observed.observationKey,
241
+ pipeline: observed.pipeline ? { ...observed.pipeline, number: observed.pipeline.id } : null,
242
+ ...observed.pipeline?.status === "success" ? { ciRecoveryCycles: 0 } : {}
243
+ })
244
+ };
245
+ },
246
+ stopped: (ctx, binding) => {
247
+ const value = current(ctx, binding.projectKey);
248
+ let state = patch(ctx, binding.projectKey, {
249
+ stopped: true,
250
+ prNumber: value.prNumber ?? binding.iid,
251
+ prUrl: value.prUrl ?? ctx.projects.find((project) => project.key === binding.projectKey)?.externalUrl ?? null,
252
+ repairPending: false,
253
+ feedbackIds: [],
254
+ pendingEvidence: null,
255
+ delivery: { adjustment: null, feedbackResult: null }
256
+ });
257
+ const activeKey = selection.activeKey(ctx.state);
258
+ if (ctx.process.currentExecution && ctx.process.selectedTurnId === adapter.ids.ciRepair && activeKey && activeKey !== binding.projectKey)
259
+ state = patch({ ...ctx, state }, activeKey, { repairPending: true });
260
+ return state;
261
+ },
262
+ terminal: (ctx, binding, observed) => patch(ctx, binding.projectKey, {
263
+ repairPending: false,
264
+ pendingEvidence: null,
265
+ delivery: { terminalPullRequest: gitlabPublicationRequest(observed.mr) }
266
+ }),
267
+ messages(ctx, binding) {
268
+ const value = current(ctx, binding.projectKey);
269
+ const outcome = value.delivery.feedbackResult;
270
+ if (!outcome) return [];
271
+ return [
272
+ ...new Map(
273
+ value.feedbackIds.map((note) => {
274
+ if (!note.discussionId) throw new Error("GitLab feedback discussion is missing");
275
+ return [
276
+ note.discussionId,
277
+ {
278
+ discussionId: note.discussionId,
279
+ writeKey: `gitlab:${ctx.process.id}:feedback-reply:${note.id}:${value.headSha}:${outcome.published ? "published" : "no-change"}`,
280
+ body: outcome.published ? `Addressed in ${value.headSha?.slice(0, 8) ?? "the current revision"}.` : `No repository change was needed. ${outcome.summary}`
281
+ }
282
+ ];
283
+ })
284
+ ).values()
285
+ ];
286
+ },
287
+ settled(ctx, binding) {
288
+ const value = current(ctx, binding.projectKey);
289
+ if (!value.delivery.feedbackResult) return ctx.state;
290
+ return patch(ctx, binding.projectKey, {
291
+ conversationCursor: Math.max(
292
+ value.conversationCursor,
293
+ ...value.feedbackIds.map((note) => note.id)
294
+ ),
295
+ feedbackIds: [],
296
+ delivery: { stage: "awaiting", adjustment: null, feedbackResult: null }
297
+ });
298
+ },
299
+ cancelled: (ctx) => Promise.resolve(
300
+ adapter.sourceCancelled?.(
301
+ workerContext(ctx, adapter.repositories?.(ctx.params)[0]?.key ?? "repo")
302
+ ) ?? false
303
+ ),
304
+ completion(ctx) {
305
+ const observed = results(ctx);
306
+ if (!observed.every(({ current: current2 }) => publicationFinished(current2))) return void 0;
307
+ const changed = observed.filter(({ current: current2 }) => !current2.noChanges);
308
+ return changed.length > 0 && changed.every(({ current: current2 }) => !current2.delivery.terminalPullRequest?.merged) ? "aborted" : "completed";
309
+ },
310
+ async complete(ctx) {
311
+ const observed = results(ctx);
312
+ if (adapter.reconcileAll)
313
+ await adapter.reconcileAll(
314
+ workerContext(ctx, observed[0].key),
315
+ observed,
316
+ !observed.every(({ current: current2 }) => publicationFinished(current2))
317
+ );
318
+ else
319
+ for (const { key, current: current2 } of observed)
320
+ if (current2.delivery.terminalPullRequest)
321
+ await adapter.reconcileTerminal(
322
+ workerContext(ctx, key),
323
+ current2,
324
+ current2.delivery.terminalPullRequest
325
+ );
326
+ }
327
+ });
328
+ }
329
+
330
+ // src/publication.ts
331
+ var gitlabPublicationRequest = (mr) => ({
332
+ number: mr.iid,
333
+ html_url: mr.web_url,
334
+ merged: mr.state === "merged",
335
+ merge_commit_sha: mr.merge_commit_sha
336
+ });
337
+ var callFor = (ctx) => (name, args = {}) => ctx.callIntegrationTool(name, { projectKey: "repo", ...args });
338
+ function gitlabPublicationSource(params, current) {
339
+ if (!current.prNumber || !current.headSha)
340
+ throw new Error("Merge request delivery state is incomplete");
341
+ return {
342
+ profile: params.gitlabProfile,
343
+ origin: params.gitlabOrigin,
344
+ projectId: params.projectId,
345
+ iid: current.prNumber,
346
+ pollInterval: "30s",
347
+ afterKey: current.observationKey,
348
+ feedback: { afterId: current.conversationCursor, quietPeriodMs: 12e4 },
349
+ delivery: {
350
+ headSha: current.headSha,
351
+ owner: params.owner,
352
+ repo: params.repo,
353
+ headBranch: params.workBranch,
354
+ baseBranch: params.baseBranch,
355
+ lastConflictKey: current.lastConflictKey
356
+ }
357
+ };
358
+ }
359
+ function gitlabPublicationEvidenceForRequest(state, event) {
360
+ const current = state;
361
+ if (!current.prNumber || !current.headSha)
362
+ throw new Error("Merge request delivery state is incomplete");
363
+ const key = { observationKey: event.observationKey };
364
+ if (event.mr.iid !== current.prNumber) throw new Error("Stale GitLab merge request evidence");
365
+ if (event.mr.state === "merged" || event.mr.state === "closed")
366
+ return { kind: "terminal", request: gitlabPublicationRequest(event.mr), ...key };
367
+ if (event.mr.sha !== current.headSha) return { kind: "observed", ...key };
368
+ if (event.conflict) return { kind: "conflict", conflict: event.conflict, ...key };
369
+ if (event.feedback?.length)
370
+ return {
371
+ kind: "feedback",
372
+ // Leave concurrent CI evidence available after feedback that needs no code change.
373
+ feedbackIds: event.feedback.map((n) => ({
374
+ kind: "inline",
375
+ id: n.id,
376
+ discussionId: n.discussionId
377
+ })),
378
+ conversationCursor: Math.max(current.conversationCursor, ...event.feedback.map((n) => n.id)),
379
+ reviewCursor: 0,
380
+ inlineCursor: 0
381
+ };
382
+ if (event.pipeline?.status === "failed")
383
+ return { kind: "failure", pipeline: { ...event.pipeline, number: event.pipeline.id }, ...key };
384
+ return { kind: "observed", ...key };
385
+ }
386
+ function createGitLabPublicationAdapter(sources, namespace = "gitlabRepoChange", describeRequest = (ctx) => ({
387
+ /** @internal */
388
+ title: ctx.process.title ?? "Leitwerk change",
389
+ /** @internal */
390
+ body: `${ctx.params.origin === "issue" ? `Implements ${ctx.params.issueUrl}
391
+
392
+ ` : ""}Leitwerk process: ${ctx.process.id}`
393
+ })) {
394
+ async function finalizeIssue(ctx, pr) {
395
+ if (ctx.params.origin !== "issue") return;
396
+ const call = callFor(ctx);
397
+ await call("gitlab_finalize_source_issue", {
398
+ issueNumber: ctx.params.issueNumber,
399
+ merged: pr?.merged ?? false,
400
+ triggerLabel: ctx.params.triggerLabel,
401
+ doneLabel: ctx.params.doneLabel,
402
+ writeKey: `gitlab:${ctx.process.id}:${pr?.merged ? "complete-source-issue" : pr ? "remove-source-trigger" : "no-changes-trigger"}`
403
+ });
404
+ await call("gitlab_add_issue_comment", {
405
+ issueNumber: ctx.params.issueNumber,
406
+ body: !pr ? "No repository changes were needed. No merge request was opened." : pr.merged ? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.` : `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
407
+ writeKey: `gitlab:${ctx.process.id}:${pr ? `${pr.merged ? "merged" : "closed"}-mr-comment` : "no-changes-comment"}`
408
+ });
409
+ }
410
+ const adapter = {
411
+ maintenance: {
412
+ source: gitlabMaintenanceSource(),
413
+ ownershipTool: "gitlab_assert_maintenance",
414
+ register: (api, process) => registerGitLabPublicationMaintenance(api, process, adapter)
415
+ },
416
+ namespace,
417
+ label: "GitLab MR",
418
+ ids: {
419
+ deliver: "deliver_change",
420
+ feedback: "revise_from_merge_request_feedback",
421
+ ciRepair: "repair_gitlab_pipeline",
422
+ operator: "ci_operator_action"
423
+ },
424
+ sources,
425
+ tools: {
426
+ delivery: [
427
+ "gitlab_assert_maintenance",
428
+ "gitlab_ensure_merge_request",
429
+ "gitlab_observe_merge_request",
430
+ "gitlab_comment",
431
+ "gitlab_reply",
432
+ "gitlab_get_identity",
433
+ "gitlab_acknowledge_feedback",
434
+ "gitlab_add_issue_comment",
435
+ "gitlab_finalize_source_issue"
436
+ ],
437
+ feedback: [
438
+ "gitlab_observe_merge_request",
439
+ "gitlab_get_changes",
440
+ "gitlab_list_merge_request_feedback"
441
+ ],
442
+ ci: ["gitlab_observe_merge_request", "gitlab_list_failed_jobs", "gitlab_get_job_trace"]
443
+ },
444
+ identity: (ctx) => {
445
+ if (!ctx.params.gitlabProfile) throw new Error("GitLab repository binding is not resolved");
446
+ return resolvePullRequestGitIdentity(ctx, "gitlab", ctx.params.gitlabProfile, false);
447
+ },
448
+ async ensureRequest(ctx) {
449
+ return gitlabPublicationRequest(
450
+ await callFor(ctx)("gitlab_ensure_merge_request", describeRequest(ctx))
451
+ );
452
+ },
453
+ async observeTerminal(ctx, current) {
454
+ const project = ctx.projects.find((project2) => project2.key === ctx.repo.get("repo").key);
455
+ if (!current.prNumber && !project?.metadata?.gitlab?.iid)
456
+ return null;
457
+ const { mr } = await callFor(ctx)("gitlab_observe_merge_request");
458
+ return mr.state === "opened" ? null : gitlabPublicationRequest(mr);
459
+ },
460
+ reconcileTerminal: (ctx, _current, pr) => finalizeIssue(ctx, pr),
461
+ unchanged: (ctx) => finalizeIssue(ctx, null),
462
+ async linkIssue(ctx, current) {
463
+ if (ctx.params.origin === "issue")
464
+ await callFor(ctx)("gitlab_add_issue_comment", {
465
+ issueNumber: ctx.params.issueNumber,
466
+ body: `Leitwerk opened merge request ${current.prUrl}.`,
467
+ writeKey: `gitlab:${ctx.process.id}:source-mr-link:${current.prNumber}`
468
+ });
469
+ },
470
+ async acknowledge(ctx, current) {
471
+ for (const feedback of current.feedbackIds)
472
+ await callFor(ctx)("gitlab_acknowledge_feedback", { noteId: feedback.id });
473
+ },
474
+ async reply(ctx, current) {
475
+ for (const feedback of current.feedbackIds) {
476
+ if (!feedback.discussionId) throw new Error("GitLab feedback discussion is missing");
477
+ await callFor(ctx)("gitlab_reply", {
478
+ discussionId: feedback.discussionId,
479
+ body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
480
+ writeKey: `gitlab:${ctx.process.id}:feedback-reply:${feedback.id}:${current.headSha}`
481
+ });
482
+ }
483
+ },
484
+ async head(ctx) {
485
+ return (await callFor(ctx)("gitlab_observe_merge_request")).mr.sha;
486
+ },
487
+ async afterRebase(ctx, current) {
488
+ await callFor(ctx)("gitlab_comment", {
489
+ body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
490
+ writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
491
+ });
492
+ },
493
+ commitMessage: (kind) => kind === "feedback" ? "fix: address GitLab review feedback" : "fix: repair GitLab pipeline",
494
+ prompt(kind, current) {
495
+ return kind === "feedback" ? `Address the unseen GitLab feedback for MR !${current.prNumber}: ${JSON.stringify(current.feedbackIds)}. Read the full discussions with gitlab_list_merge_request_feedback, inspect the checkout, and make only justified changes. Call changes_ready when ready to publish, no_changes with an explicit diagnosis when no change is needed, or cannot_repair for operator action.` : `Diagnose GitLab pipeline ${current.pipeline?.number} for head ${current.headSha}. Read gitlab_list_failed_jobs with pipelineId and bounded gitlab_get_job_trace before making repository repairs. Call changes_ready to publish, no_changes with a justified diagnosis, or cannot_repair when operator action is needed.`;
496
+ }
497
+ };
498
+ return adapter;
499
+ }
19
500
 
20
501
  // src/index.ts
21
- import { coreHostCapabilities } from "@leitwerk-dev/process-sdk";
22
502
  var manifest = {
23
503
  /** @internal */
24
504
  id: "gitlab",
@@ -30,14 +510,18 @@ var extension = {
30
510
  setupServer(api, config) {
31
511
  const profiles = parseGitLabProfiles(config);
32
512
  const clients = new Map([...profiles].map(([id, profile]) => [id, new GitLabClient(profile)]));
33
- setupGitLabIntegration(api, {
34
- profiles: () => [...profiles.keys()],
35
- client: (profile) => {
36
- const client = clients.get(profile);
37
- if (!client) throw new Error(`Unknown GitLab profile '${profile}'`);
38
- return client;
39
- }
40
- });
513
+ setupGitLabIntegration(
514
+ api,
515
+ {
516
+ profiles: () => [...profiles.keys()],
517
+ client: (profile) => {
518
+ const client = clients.get(profile);
519
+ if (!client) throw new Error(`Unknown GitLab profile '${profile}'`);
520
+ return client;
521
+ }
522
+ },
523
+ { ticketCreation: parseTicketCreationConfig(config, "GitLab") }
524
+ );
41
525
  const deps = api.get(coreHostCapabilities.serverSetup);
42
526
  if (!deps || Array.isArray(deps)) return;
43
527
  deps.repositoryCredentials.register({
@@ -51,19 +535,37 @@ var extension = {
51
535
  };
52
536
  var index_default = extension;
53
537
  export {
538
+ GITLAB_ACTIVE_LABEL,
539
+ GITLAB_DONE_LABEL,
540
+ GITLAB_MAINTAINED_KIND,
541
+ GitLabError,
542
+ createGitLabPublicationAdapter,
543
+ createGitLabRepositoryCatalog,
54
544
  index_default as default,
545
+ ensureGitLabComment,
55
546
  ensureGitLabSeenReaction,
547
+ gitLabActivationStatus,
548
+ gitLabCommentMarker,
56
549
  gitLabFeedbackReadyAt,
57
550
  gitlabExternal,
58
551
  gitlabIntegration,
59
552
  gitlabIssueExternalId,
60
553
  gitlabIssueWatcherSource,
554
+ gitlabMaintenance,
555
+ gitlabMaintenanceSource,
556
+ gitlabPublicationEvidenceForRequest,
557
+ gitlabPublicationRequest,
558
+ gitlabPublicationSource,
61
559
  gitlabRepositoryCredentials,
62
560
  observationKey,
63
561
  observeMergeRequest,
64
562
  parseGitLabSelection,
65
563
  pendingGitLabFeedback,
564
+ readGitLabLabels,
565
+ registerGitLabMaintainedProcess,
66
566
  resolveGitLabBinding,
567
+ resolveGitLabLaunchProject,
568
+ resolveGitLabRepositoryBinding,
67
569
  selectGitLabProjects
68
570
  };
69
571
  //# sourceMappingURL=index.js.map