@leitwerk-dev/gitlab 0.3.1 → 0.4.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.
Files changed (56) hide show
  1. package/README.md +174 -1
  2. package/dist/capability.d.ts +3 -0
  3. package/dist/capability.d.ts.map +1 -1
  4. package/dist/chunk-23NUGZ3Q.js +2429 -0
  5. package/dist/chunk-23NUGZ3Q.js.map +1 -0
  6. package/dist/client.d.ts +116 -2
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/external.d.ts +23 -1
  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 +519 -10
  13. package/dist/index.js.map +1 -1
  14. package/dist/issue-watcher.d.ts +2 -0
  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 +122 -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 +39 -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 +14 -1
  31. package/dist/testing.d.ts.map +1 -1
  32. package/dist/testing.js +158 -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 +144 -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 +321 -7
  41. package/src/delivery-tools.ts +4 -4
  42. package/src/external.ts +90 -19
  43. package/src/index.ts +57 -10
  44. package/src/issue-watcher.ts +10 -1
  45. package/src/launch.ts +63 -0
  46. package/src/maintenance-labels.ts +129 -0
  47. package/src/maintenance.ts +721 -0
  48. package/src/publication-maintenance.ts +290 -0
  49. package/src/publication.ts +254 -0
  50. package/src/repository-catalog.ts +94 -0
  51. package/src/setup.ts +115 -6
  52. package/src/testing.ts +178 -4
  53. package/src/ticket-creation.ts +145 -0
  54. package/src/tools.ts +508 -23
  55. package/dist/chunk-TQIZKDAM.js +0 -1160
  56. package/dist/chunk-TQIZKDAM.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,24 +1,511 @@
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-TQIZKDAM.js";
31
+ } from "./chunk-23NUGZ3Q.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 reconciliationContext = (ctx, key) => ({
146
+ ...ctx,
147
+ params: params(ctx, key),
148
+ state: select(ctx.state, key),
149
+ callIntegrationTool: (name, args) => ctx.callIntegrationTool(name, { ...args, projectKey: key })
150
+ });
151
+ registerGitLabMaintainedProcess(api, {
152
+ processId: process.id,
153
+ paramsCodec: process.paramsCodec,
154
+ stateCodec: process.stateCodec,
155
+ idleTurnId: adapter.ids.deliver,
156
+ currentBinding: (ctx) => adapter.repositories ? selection.activeKey(ctx.state) : "repo",
157
+ settings: (ctx, binding) => ({
158
+ cursor: current(ctx, binding.projectKey).conversationCursor,
159
+ quietPeriodMs: 12e4,
160
+ pollInterval: "30s"
161
+ }),
162
+ observe(ctx, binding, observed) {
163
+ const key = binding.projectKey;
164
+ let value = current(ctx, key);
165
+ const p = params(ctx, key);
166
+ if (publicationFinished(value)) return { state: ctx.state };
167
+ if (observed.mr.state === "opened")
168
+ assertGitLabBranchBinding(observed.mr, p, binding.projectId);
169
+ if (!ctx.process.currentExecution && !value.delivery.adjustment && observed.mr.sha !== value.headSha) {
170
+ value = {
171
+ ...value,
172
+ workBaselineSha: value.workBaselineSha ?? value.headSha,
173
+ lastPublishedHeadSha: value.lastPublishedHeadSha ?? value.headSha,
174
+ headSha: observed.mr.sha,
175
+ pipeline: null,
176
+ conflict: null,
177
+ lastConflictKey: null,
178
+ // A result verified against an older tree cannot acknowledge a rewritten source.
179
+ delivery: { ...value.delivery, feedbackResult: null }
180
+ };
181
+ ctx = { ...ctx, state: patch(ctx, key, value) };
182
+ }
183
+ if (ctx.process.selectedTurnId === adapter.ids.deliver && !ctx.process.currentExecution && !value.delivery.adjustment && !value.delivery.feedbackResult) {
184
+ if (value.feedbackIds.length)
185
+ return { state: select(ctx.state, key), action: "maintenance_feedback" };
186
+ if (value.conflict && value.repairReason === "rebase")
187
+ return { state: select(ctx.state, key), action: "maintenance_conflict" };
188
+ if (value.repairPending && value.repairReason === "ci" && value.pipeline)
189
+ return { state: select(ctx.state, key), action: "maintenance_ci" };
190
+ }
191
+ let evidence;
192
+ if (value.pendingEvidence) {
193
+ evidence = value.pendingEvidence;
194
+ value = { ...value, pendingEvidence: null };
195
+ } else {
196
+ if (value.delivery.adjustment || value.delivery.feedbackResult || value.feedbackIds.length || !value.headSha || !value.prNumber)
197
+ return { state: ctx.state };
198
+ let event = observed;
199
+ if (!observed.targetIntegrated && observed.mr.sha === value.headSha && observed.targetHead && (observed.mr.has_conflicts || ["conflict", "need_rebase"].includes(observed.mr.detailed_merge_status ?? ""))) {
200
+ assertGitLabBranchBinding(observed.mr, p, binding.projectId);
201
+ const conflict = {
202
+ owner: p.owner,
203
+ repo: p.repo,
204
+ prNumber: value.prNumber,
205
+ headBranch: p.workBranch,
206
+ baseBranch: p.baseBranch,
207
+ headSha: value.headSha,
208
+ baseSha: observed.targetHead,
209
+ url: observed.mr.web_url
210
+ };
211
+ if (conflictKey(conflict) !== value.lastConflictKey) event = { ...observed, conflict };
212
+ }
213
+ evidence = gitlabPublicationEvidenceForRequest(value, event);
214
+ }
215
+ if (evidence.kind === "terminal")
216
+ return {
217
+ state: patch(ctx, key, {
218
+ delivery: { terminalPullRequest: evidence.request }
219
+ })
220
+ };
221
+ const dispatch = (action, operator = false) => ({
222
+ state: select(
223
+ patch(ctx, key, {
224
+ ...applyPublicationEvidence(p, value, evidence, !operator),
225
+ repairPending: !operator,
226
+ // Dispatch does not consume feedback; publication/no-change acknowledgement does.
227
+ ...evidence.kind === "feedback" ? { conversationCursor: value.conversationCursor } : {}
228
+ }),
229
+ key
230
+ ),
231
+ action
232
+ });
233
+ if (evidence.kind === "feedback" || evidence.kind === "conflict")
234
+ return dispatch(`maintenance_${evidence.kind}`);
235
+ 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))) {
236
+ const operator = value.ciRecoveryCycles >= 3;
237
+ return dispatch(operator ? "maintenance_operator" : "maintenance_ci", operator);
238
+ }
239
+ return {
240
+ state: patch(ctx, key, {
241
+ ...value,
242
+ observationKey: observed.observationKey,
243
+ pipeline: observed.pipeline ? { ...observed.pipeline, number: observed.pipeline.id } : null,
244
+ ...observed.pipeline?.status === "success" ? { ciRecoveryCycles: 0 } : {}
245
+ })
246
+ };
247
+ },
248
+ stopped: (ctx, binding) => {
249
+ const value = current(ctx, binding.projectKey);
250
+ let state = patch(ctx, binding.projectKey, {
251
+ stopped: true,
252
+ prNumber: value.prNumber ?? binding.iid,
253
+ prUrl: value.prUrl ?? ctx.projects.find((project) => project.key === binding.projectKey)?.externalUrl ?? null,
254
+ repairPending: false,
255
+ feedbackIds: [],
256
+ pendingEvidence: null,
257
+ delivery: { adjustment: null, feedbackResult: null }
258
+ });
259
+ const activeKey = selection.activeKey(ctx.state);
260
+ if (ctx.process.currentExecution && ctx.process.selectedTurnId === adapter.ids.ciRepair && activeKey && activeKey !== binding.projectKey)
261
+ state = patch({ ...ctx, state }, activeKey, { repairPending: true });
262
+ return state;
263
+ },
264
+ terminal: (ctx, binding, observed) => patch(ctx, binding.projectKey, {
265
+ repairPending: false,
266
+ pendingEvidence: null,
267
+ delivery: { terminalPullRequest: gitlabPublicationRequest(observed.mr) }
268
+ }),
269
+ messages(ctx, binding) {
270
+ const value = current(ctx, binding.projectKey);
271
+ const outcome = value.delivery.feedbackResult;
272
+ if (!outcome) return [];
273
+ return [
274
+ ...new Map(
275
+ value.feedbackIds.map((note) => {
276
+ if (!note.discussionId) throw new Error("GitLab feedback discussion is missing");
277
+ return [
278
+ note.discussionId,
279
+ {
280
+ discussionId: note.discussionId,
281
+ writeKey: `gitlab:${ctx.process.id}:feedback-reply:${note.id}:${value.headSha}:${outcome.published ? "published" : "no-change"}`,
282
+ body: outcome.published ? `Addressed in ${value.headSha?.slice(0, 8) ?? "the current revision"}.` : `No repository change was needed. ${outcome.summary}`
283
+ }
284
+ ];
285
+ })
286
+ ).values()
287
+ ];
288
+ },
289
+ settled(ctx, binding) {
290
+ const value = current(ctx, binding.projectKey);
291
+ if (!value.delivery.feedbackResult) return ctx.state;
292
+ return patch(ctx, binding.projectKey, {
293
+ conversationCursor: Math.max(
294
+ value.conversationCursor,
295
+ ...value.feedbackIds.map((note) => note.id)
296
+ ),
297
+ feedbackIds: [],
298
+ delivery: { stage: "awaiting", adjustment: null, feedbackResult: null }
299
+ });
300
+ },
301
+ cancelled: (ctx) => Promise.resolve(
302
+ adapter.sourceCancelled?.(
303
+ reconciliationContext(ctx, adapter.repositories?.(ctx.params)[0]?.key ?? "repo")
304
+ ) ?? false
305
+ ),
306
+ completion(ctx) {
307
+ const observed = results(ctx);
308
+ if (!observed.every(({ current: current2 }) => publicationFinished(current2))) return void 0;
309
+ const changed = observed.filter(({ current: current2 }) => !current2.noChanges);
310
+ return changed.length > 0 && changed.every(({ current: current2 }) => !current2.delivery.terminalPullRequest?.merged) ? "aborted" : "completed";
311
+ },
312
+ async complete(ctx) {
313
+ const observed = results(ctx);
314
+ if (adapter.reconcileAll)
315
+ await adapter.reconcileAll(
316
+ reconciliationContext(ctx, observed[0].key),
317
+ observed,
318
+ !observed.every(({ current: current2 }) => publicationFinished(current2))
319
+ );
320
+ else
321
+ for (const { key, current: current2 } of observed)
322
+ if (current2.delivery.terminalPullRequest)
323
+ await adapter.reconcileTerminal(
324
+ reconciliationContext(ctx, key),
325
+ current2,
326
+ current2.delivery.terminalPullRequest
327
+ );
328
+ }
329
+ });
330
+ }
331
+
332
+ // src/publication.ts
333
+ function assertGitLabBranchBinding(mr, params, projectId = params.projectId) {
334
+ if (mr.source_project_id !== projectId || mr.target_project_id !== projectId || mr.source_branch !== params.workBranch || mr.target_branch !== params.baseBranch)
335
+ throw new Error("GitLab maintenance branch binding changed");
336
+ }
337
+ var gitlabPublicationRequest = (mr) => ({
338
+ number: mr.iid,
339
+ html_url: mr.web_url,
340
+ merged: mr.state === "merged",
341
+ merge_commit_sha: mr.merge_commit_sha
342
+ });
343
+ var callFor = (ctx) => (name, args = {}) => ctx.callIntegrationTool(name, { projectKey: "repo", ...args });
344
+ function gitlabPublicationSource(params, current) {
345
+ if (!current.prNumber || !current.headSha)
346
+ throw new Error("Merge request delivery state is incomplete");
347
+ return {
348
+ profile: params.gitlabProfile,
349
+ origin: params.gitlabOrigin,
350
+ projectId: params.projectId,
351
+ iid: current.prNumber,
352
+ pollInterval: "30s",
353
+ afterKey: current.observationKey,
354
+ feedback: { afterId: current.conversationCursor, quietPeriodMs: 12e4 },
355
+ delivery: {
356
+ headSha: current.headSha,
357
+ owner: params.owner,
358
+ repo: params.repo,
359
+ headBranch: params.workBranch,
360
+ baseBranch: params.baseBranch,
361
+ lastConflictKey: current.lastConflictKey
362
+ }
363
+ };
364
+ }
365
+ function gitlabPublicationEvidenceForRequest(state, event) {
366
+ const current = state;
367
+ if (!current.prNumber || !current.headSha)
368
+ throw new Error("Merge request delivery state is incomplete");
369
+ const key = { observationKey: event.observationKey, remoteHeadSha: event.mr.sha };
370
+ if (event.mr.iid !== current.prNumber) throw new Error("Stale GitLab merge request evidence");
371
+ if (event.mr.state === "merged" || event.mr.state === "closed")
372
+ return { kind: "terminal", request: gitlabPublicationRequest(event.mr), ...key };
373
+ if (event.conflict) return { kind: "conflict", conflict: event.conflict, ...key };
374
+ if (event.feedback?.length)
375
+ return {
376
+ kind: "feedback",
377
+ // Leave concurrent CI evidence available after feedback that needs no code change.
378
+ feedbackIds: event.feedback.map((n) => ({
379
+ kind: "inline",
380
+ id: n.id,
381
+ discussionId: n.discussionId
382
+ })),
383
+ conversationCursor: Math.max(current.conversationCursor, ...event.feedback.map((n) => n.id)),
384
+ reviewCursor: 0,
385
+ inlineCursor: 0,
386
+ remoteHeadSha: event.mr.sha
387
+ };
388
+ if (event.pipeline?.status === "failed" && (event.pipeline.sha === event.mr.sha || event.pipelineSourceHead === event.mr.sha))
389
+ return { kind: "failure", pipeline: { ...event.pipeline, number: event.pipeline.id }, ...key };
390
+ return { kind: "observed", ...key };
391
+ }
392
+ function createGitLabPublicationAdapter(sources, namespace = "gitlabRepoChange", describeRequest = (ctx) => ({
393
+ /** @internal */
394
+ title: ctx.process.title ?? "Leitwerk change",
395
+ /** @internal */
396
+ body: `${ctx.params.origin === "issue" ? `Implements ${ctx.params.issueUrl}
397
+
398
+ ` : ""}Leitwerk process: ${ctx.process.id}`
399
+ })) {
400
+ async function finalizeIssue(ctx, pr) {
401
+ if (ctx.params.origin !== "issue") return;
402
+ const call = callFor(ctx);
403
+ await call("gitlab_finalize_source_issue", {
404
+ issueNumber: ctx.params.issueNumber,
405
+ merged: pr?.merged ?? false,
406
+ triggerLabel: ctx.params.triggerLabel,
407
+ doneLabel: ctx.params.doneLabel,
408
+ writeKey: `gitlab:${ctx.process.id}:${pr?.merged ? "complete-source-issue" : pr ? "remove-source-trigger" : "no-changes-trigger"}`
409
+ });
410
+ await call("gitlab_add_issue_comment", {
411
+ issueNumber: ctx.params.issueNumber,
412
+ 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.`,
413
+ writeKey: `gitlab:${ctx.process.id}:${pr ? `${pr.merged ? "merged" : "closed"}-mr-comment` : "no-changes-comment"}`
414
+ });
415
+ }
416
+ const adapter = {
417
+ maintenance: {
418
+ source: gitlabMaintenanceSource(),
419
+ ownershipTool: "gitlab_assert_maintenance",
420
+ register: (api, process) => registerGitLabPublicationMaintenance(api, process, adapter)
421
+ },
422
+ namespace,
423
+ label: "GitLab MR",
424
+ ids: {
425
+ deliver: "deliver_change",
426
+ feedback: "revise_from_merge_request_feedback",
427
+ ciRepair: "repair_gitlab_pipeline",
428
+ operator: "ci_operator_action"
429
+ },
430
+ sources,
431
+ tools: {
432
+ delivery: [
433
+ "gitlab_assert_maintenance",
434
+ "gitlab_ensure_merge_request",
435
+ "gitlab_observe_merge_request",
436
+ "gitlab_comment",
437
+ "gitlab_reply",
438
+ "gitlab_get_identity",
439
+ "gitlab_acknowledge_feedback",
440
+ "gitlab_add_issue_comment",
441
+ "gitlab_finalize_source_issue"
442
+ ],
443
+ feedback: [
444
+ "gitlab_observe_merge_request",
445
+ "gitlab_get_changes",
446
+ "gitlab_list_merge_request_feedback"
447
+ ],
448
+ ci: ["gitlab_observe_merge_request", "gitlab_list_failed_jobs", "gitlab_get_job_trace"]
449
+ },
450
+ identity: (ctx) => {
451
+ if (!ctx.params.gitlabProfile) throw new Error("GitLab repository binding is not resolved");
452
+ return resolvePullRequestGitIdentity(ctx, "gitlab", ctx.params.gitlabProfile, false);
453
+ },
454
+ async ensureRequest(ctx) {
455
+ return gitlabPublicationRequest(
456
+ await callFor(ctx)("gitlab_ensure_merge_request", describeRequest(ctx))
457
+ );
458
+ },
459
+ async observeTerminal(ctx, current) {
460
+ const project = ctx.projects.find((project2) => project2.key === ctx.repo.get("repo").key);
461
+ if (!current.prNumber && !project?.metadata?.gitlab?.iid)
462
+ return null;
463
+ const { mr } = await callFor(ctx)("gitlab_observe_merge_request");
464
+ if (mr.state === "opened") assertGitLabBranchBinding(mr, ctx.params);
465
+ return mr.state === "opened" ? null : gitlabPublicationRequest(mr);
466
+ },
467
+ reconcileTerminal: (ctx, _current, pr) => finalizeIssue(ctx, pr),
468
+ unchanged: (ctx) => finalizeIssue(ctx, null),
469
+ async linkIssue(ctx, current) {
470
+ if (ctx.params.origin === "issue")
471
+ await callFor(ctx)("gitlab_add_issue_comment", {
472
+ issueNumber: ctx.params.issueNumber,
473
+ body: `Leitwerk opened merge request ${current.prUrl}.`,
474
+ writeKey: `gitlab:${ctx.process.id}:source-mr-link:${current.prNumber}`
475
+ });
476
+ },
477
+ async acknowledge(ctx, current) {
478
+ for (const feedback of current.feedbackIds)
479
+ await callFor(ctx)("gitlab_acknowledge_feedback", { noteId: feedback.id });
480
+ },
481
+ async reply(ctx, current) {
482
+ for (const feedback of current.feedbackIds) {
483
+ if (!feedback.discussionId) throw new Error("GitLab feedback discussion is missing");
484
+ await callFor(ctx)("gitlab_reply", {
485
+ discussionId: feedback.discussionId,
486
+ body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
487
+ writeKey: `gitlab:${ctx.process.id}:feedback-reply:${feedback.id}:${current.headSha}`
488
+ });
489
+ }
490
+ },
491
+ async head(ctx) {
492
+ return (await callFor(ctx)("gitlab_observe_merge_request")).mr.sha;
493
+ },
494
+ async afterRebase(ctx, current) {
495
+ await callFor(ctx)("gitlab_comment", {
496
+ body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
497
+ writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
498
+ });
499
+ },
500
+ commitMessage: (kind) => kind === "feedback" ? "fix: address GitLab review feedback" : "fix: repair GitLab pipeline",
501
+ prompt(kind, current) {
502
+ 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.`;
503
+ }
504
+ };
505
+ return adapter;
506
+ }
19
507
 
20
508
  // src/index.ts
21
- import { coreHostCapabilities } from "@leitwerk-dev/process-sdk";
22
509
  var manifest = {
23
510
  /** @internal */
24
511
  id: "gitlab",
@@ -30,14 +517,18 @@ var extension = {
30
517
  setupServer(api, config) {
31
518
  const profiles = parseGitLabProfiles(config);
32
519
  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
- });
520
+ setupGitLabIntegration(
521
+ api,
522
+ {
523
+ profiles: () => [...profiles.keys()],
524
+ client: (profile) => {
525
+ const client = clients.get(profile);
526
+ if (!client) throw new Error(`Unknown GitLab profile '${profile}'`);
527
+ return client;
528
+ }
529
+ },
530
+ { ticketCreation: parseTicketCreationConfig(config, "GitLab") }
531
+ );
41
532
  const deps = api.get(coreHostCapabilities.serverSetup);
42
533
  if (!deps || Array.isArray(deps)) return;
43
534
  deps.repositoryCredentials.register({
@@ -51,19 +542,37 @@ var extension = {
51
542
  };
52
543
  var index_default = extension;
53
544
  export {
545
+ GITLAB_ACTIVE_LABEL,
546
+ GITLAB_DONE_LABEL,
547
+ GITLAB_MAINTAINED_KIND,
548
+ GitLabError,
549
+ createGitLabPublicationAdapter,
550
+ createGitLabRepositoryCatalog,
54
551
  index_default as default,
552
+ ensureGitLabComment,
55
553
  ensureGitLabSeenReaction,
554
+ gitLabActivationStatus,
555
+ gitLabCommentMarker,
56
556
  gitLabFeedbackReadyAt,
57
557
  gitlabExternal,
58
558
  gitlabIntegration,
59
559
  gitlabIssueExternalId,
60
560
  gitlabIssueWatcherSource,
561
+ gitlabMaintenance,
562
+ gitlabMaintenanceSource,
563
+ gitlabPublicationEvidenceForRequest,
564
+ gitlabPublicationRequest,
565
+ gitlabPublicationSource,
61
566
  gitlabRepositoryCredentials,
62
567
  observationKey,
63
568
  observeMergeRequest,
64
569
  parseGitLabSelection,
65
570
  pendingGitLabFeedback,
571
+ readGitLabLabels,
572
+ registerGitLabMaintainedProcess,
66
573
  resolveGitLabBinding,
574
+ resolveGitLabLaunchProject,
575
+ resolveGitLabRepositoryBinding,
67
576
  selectGitLabProjects
68
577
  };
69
578
  //# sourceMappingURL=index.js.map