@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/README.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # GitLab
2
2
 
3
+ ## Ticket creation
4
+
5
+ Load `@leitwerk-dev/ticket-creation` and set:
6
+
7
+ ```yaml
8
+ extensions:
9
+ gitlab:
10
+ ticket_creation:
11
+ enabled: true
12
+ default_labels: [created-by-leitwerk]
13
+ ```
14
+
15
+ `gitlab_create_issue` discovers projects from configured profiles, excluding archived
16
+ projects and projects with issues disabled. The token needs API access and permission
17
+ to create issues and configured default labels in the destination. Optional labels
18
+ must already exist. Set `default_labels: []` to omit defaults; label names cannot
19
+ contain commas.
20
+
21
+ The normal draft process asks for approval before writing. Its snapshot pins the
22
+ installation, project ID and path. Renamed, transferred, disabled or repointed
23
+ destinations fail before writing. Retry reconciliation includes closed issues and
24
+ recovers lost create responses. Ticket creation defaults to disabled; enabling it
25
+ requires the ticket process to be loaded.
26
+
27
+ ## Profiles and delivery
28
+
3
29
  `@leitwerk-dev/gitlab` supplies GitLab v4 API access and repository-scoped HTTPS Git authentication from one server-owned profile. Load this optional extension on the server and worker.
4
30
 
5
31
  ```yaml
@@ -9,6 +35,7 @@ extensions:
9
35
  example:
10
36
  base_url: https://forge.test
11
37
  token: env:GITLAB_TOKEN
38
+ ignored_comment_users: [sonarqube]
12
39
  # Optional, when /user cannot provide a usable commit identity:
13
40
  # git_identity:
14
41
  # name: Leitwerk Bot
@@ -21,12 +48,41 @@ extensions:
21
48
 
22
49
  - `GitLabClientLike` defines project/group discovery, MR metadata and paginated changes, branches/commits, pipelines, failed jobs, bounded traces, bot identity and notes. `GitLabClient` implements it using HTTPS, pagination and bounded transient read retries. Errors omit response bodies and credentials. Writes are reconciled by their caller rather than blindly repeated.
23
50
  - `gitlabIntegration` exposes `profiles()` and `client(profile)` through the SDK capability registry. `setupGitLabIntegration()` registers an explicit adapter for tools and external observations.
51
+ - Server setup also supplies `repositoryCatalog` for Settings. Opening Settings
52
+ or a repository editor does not scan GitLab. Searches of at least two characters
53
+ read one page of up to 100 matches per profile and cache repeated queries;
54
+ concurrent identical searches share one request. **Refresh sources** explicitly
55
+ loads a complete catalog, which subsequent searches filter locally. A failed
56
+ refresh retains the last successful data. Server restart or integration
57
+ reconfiguration starts a new cache. Saved selections use known metadata without
58
+ remote reads; unknown names display the stable repository ID until found.
59
+ Admission and delivery still read live project metadata and permissions through
60
+ `client(profile)`.
61
+ - `listMergeRequestLabelEvents()` reads paginated label transitions with stable event IDs. `updateMergeRequestLabels()` applies `add_labels` and `remove_labels` without replacing unrelated labels.
62
+ - `registerGitLabMaintainedProcess()` registers a typed MR maintenance policy through
63
+ the capability registry. One server service observes all registered processes,
64
+ including running turns and operator waits. The process supplies its repair
65
+ destinations, state adapters and completion policy.
24
66
  - `gitlabRepositoryCredentials(profile, projects)` derives internal credential references. The core authorizes their HTTPS origin and exact repository path against the process projects.
25
67
  - `selectGitLabProjects()` expands exact includes and groups, including subgroups, then applies exclusions. Includes form a union; stable project IDs remove duplicates. An explicit include or `all_accessible: true` is required.
26
68
  - `observeMergeRequest()` selects the newest pipeline associated with the current MR source revision. Synthetic merge commits must contain that head as a parent. With no matching MR pipeline, it falls back to the current source branch's push pipeline. A newer pending result supersedes older terminal results. The observation includes GitLab's `has_conflicts`, `merge_status` and `detailed_merge_status`, plus `targetHead` read from the current target branch (not the historical diff base). Closed MRs do not require branch or pipeline reads.
27
69
  - `gitLabMergeRepairReason(mr)` identifies explicit conflict and `need_rebase` evidence. `gitLabMergeabilityPending(mr)` distinguishes asynchronous checks; approvals, discussions and generic merge blocking are not Git conflict evidence.
28
70
  - `gitlabExternal.mergeRequest()` reports MR closure/merge, source/target project and branch changes, current heads, mergeability and CI observations. Mergeability or target changes wake an idle process even when its source SHA and successful pipeline are unchanged. Its `afterKey` is the previous `observationKey()`. An optional `wakeAt` timestamp permits recovery timers without retaining a worker. Poll failures back off from 30 seconds to five minutes and surface diagnostics.
29
71
 
72
+ ## Commit-pinned repository inspection
73
+
74
+ `gitlab_inspect_project`, `gitlab_repository_tree`, `gitlab_repository_file`, and
75
+ `gitlab_code_search` require a GitLab process project binding. Tree, file, and
76
+ search calls require a full commit ID as `ref`; branches are rejected. Tokens
77
+ stay on the server unless the process explicitly declares repository credentials.
78
+
79
+ `gitlab_code_search({ projectKey, ref, search, page?, perPage? })` uses
80
+ project-scoped basic blob search. It returns paths, snippets, starting lines, the
81
+ requested revision/page, and `nextPage` (`null` when complete). Defaults are page
82
+ 1 and 20 results; at most 100 results are returned per page. Follow continuation
83
+ pages and read the files for complete evidence. Access errors, unavailable search,
84
+ invalid responses, and cancellation fail the call; they are never empty matches.
85
+
30
86
  ## Project-bound tools
31
87
 
32
88
  Project metadata binds tools to `{ gitlab: { profile, projectId, iid } }`. Each call requires an authorized process project. Available tools are `gitlab_observe_merge_request`, `gitlab_get_changes`, `gitlab_get_identity`, `gitlab_list_failed_jobs`, `gitlab_get_job_trace`, `gitlab_comment`, and `gitlab_reply`. Job and pipeline reads verify membership in the bound MR's current pipeline. Traces cap individual reads at 256 KiB; truncation is explicit.
@@ -35,10 +91,106 @@ Comments require a stable business `writeKey`. `ensureGitLabComment()` combines
35
91
 
36
92
  The MR external source can also observe review feedback using `feedback: { afterId, since, quietPeriodMs }`. It reads paginated discussions, preserving inline file/line context, and excludes system/resolved notes, Leitwerk-generated comment markers and accounts flagged as bots. Human comments by the authenticated PAT owner remain actionable. Each new unseen note resets the trailing quiet period; a mature batch wakes the process even when the MR revision and CI status are unchanged. The process owns the durable cursor and decides when feedback is consumed. The provider recomputes timing from note timestamps after restart.
37
93
 
94
+ Each profile may configure `ignored_comment_users`, defaulting to `[]`. Usernames
95
+ are case-insensitive and accept a leading `@`. The shared feedback reader excludes
96
+ those authors for every workflow using the profile, before feedback settling and
97
+ cursor selection. Their general comments, inline comments and replies do not trigger
98
+ work or acknowledgements. Other users' replies in the same discussion remain
99
+ actionable; mentioning an ignored account does not exclude a comment. Profile edits
100
+ apply after server restart; executing turns keep their captured inputs. CI and
101
+ conflict observations remain available.
102
+
38
103
  `ensureGitLabSeenReaction()` lets a process acknowledge an authorized MR comment with an eyes reaction. It reconciles the authenticated bot's reaction and records it with `ctx.externalWrites.ensure()`. Other users' eyes reactions do not suppress the bot's acknowledgement; retries and restarts do not duplicate it. The calling process owns selection and lifecycle checks.
39
104
 
105
+ `gitlab_approve_merge_request` approves the bound MR when its current source SHA matches the supplied full SHA. The write key includes that SHA. A repeated call reconciles the bot's existing approval and does not approve again. A SHA that is no longer HEAD is left unapproved. `gitlab_unapprove_merge_request` removes that approval when the same SHA is still HEAD. A repeated call does not unapprove again. A moved HEAD is left unchanged so the next review can decide.
106
+
40
107
  The extension contains no Renovate selection or repair policy. `./testing` exports a persistent `LocalGitLabAdapter` with real local repository ancestry for integration tests.
41
108
 
109
+ ## Shared MR maintenance
110
+
111
+ Opt in during `setupServer`. Declare external edges using
112
+ `gitlabMaintenanceSource()` and register their identities:
113
+
114
+ ```ts
115
+ registerGitLabMaintainedProcess(api, {
116
+ processId: process.id,
117
+ paramsCodec: process.paramsCodec,
118
+ stateCodec: process.stateCodec,
119
+ idleTurnId: "deliver_change",
120
+ observe: repairPolicy.observe,
121
+ stopped: repairPolicy.stopped,
122
+ terminal: repairPolicy.terminal,
123
+ completion: repairPolicy.completion,
124
+ complete: repairPolicy.complete,
125
+ });
126
+ ```
127
+
128
+ Bindings default to each process project's `gitlab` metadata. `bindings` can
129
+ provide explicit MR targets. `settings` supplies the consumed feedback cursor,
130
+ activation receipt, polling interval and quiet period; the quiet period defaults
131
+ to two minutes. `assess`, `eligible` and `canWrite` retain process-specific admission
132
+ rules. `observe` returns state and an optional declared external action ID, such
133
+ as `maintenance_feedback`. It replaces the former `destinations` alias mapping.
134
+ The service fires that edge; ordinary observations allocate no worker or turn record.
135
+ `currentBinding` identifies a selected repair or operator decision so removing a
136
+ different MR's label preserves that business position. Interrupted repairs on
137
+ remaining MRs retain their staged work and repair budgets.
138
+
139
+ `messages` supplies retry-safe discussion replies or comments. `settled` advances
140
+ business acknowledgement state after those writes succeed. `completion` determines
141
+ the terminal lifecycle without remote writes. `complete` delivers process-specific
142
+ terminal writes and retries them after the process ends.
143
+
144
+ Eligible, owned bindings request server-managed recovery for failed unaccepted
145
+ worker starts. The server allows three starts per episode, with 30/60 second
146
+ retry delays for known transient failures. Configuration errors, OOMs and unknown
147
+ failures require manual recovery. Accepted failed turns are never retried by
148
+ maintenance. Recovery does not consume the process's business repair budget.
149
+ The deprecated `retry.maxAttempts` setting is ignored; maintenance cannot override
150
+ the server's startup budget.
151
+
152
+ Taking responsibility adds `leitwerk-active`. Green CI keeps maintenance active for
153
+ later feedback. Removing the label ends that MR's activation and leaves the MR open.
154
+ Other bindings continue; a single stopped, unmerged binding aborts its process.
155
+ Remove/re-add pairs between polls end the old activation. Ownership is rechecked
156
+ before publication, replies and reactions; late worker outcomes are fenced.
157
+ Label-read failures produce retry diagnostics and do not cancel maintenance.
158
+ Deleting a linked MR aborts the whole process, including running repairs and
159
+ operator waits. Deletion is confirmed by an MR 404 while its project remains
160
+ accessible; access failures and other read errors remain retryable diagnostics.
161
+ Deleted bindings are persisted and receive no further MR reads or writes after
162
+ restart.
163
+
164
+ Merged MRs lose `leitwerk-active` and gain `leitwerk-done`. Unmerged closure and
165
+ stopping remove active without adding done. Label writes preserve unrelated labels
166
+ and reconcile lost responses. Startup adopts live bindings and existing activation
167
+ receipts, retaining feedback cursors, budgets, selected turns and historical records.
168
+ Processes retain their own reactivation admission and partial-completion rules.
169
+
170
+ The shared publication adapter used by Jira and GitLab repository changes registers
171
+ this policy. Settled feedback and actionable conflicts invoke Address Feedback
172
+ directly; failed current-revision CI invokes Fix CI. Changed work returns to Deliver.
173
+ A no-change outcome returns through Deliver to check concurrent source updates and
174
+ retained local work before acknowledging its batch. An unchanged checkout creates
175
+ no commit or push. Label, target-head and mergeability updates do not replay a
176
+ handled pipeline failure. A new pipeline or an observed running-to-failed retry
177
+ remains actionable. Maintenance adds no business turns.
178
+
179
+ The current source branch is authoritative, including developer rebases and pushes.
180
+ Idle observations adopt its head while retaining the earlier work baseline and
181
+ publication receipt separately. Feedback stays actionable when the head changes;
182
+ the worker reconciles unpublished local work before adjusting the current revision.
183
+ Source/target project or branch changes are explicit binding errors, not permission
184
+ to publish elsewhere. Active workers keep their captured state; delivery rechecks
185
+ the branch after their work. Only pipelines associated with the current source
186
+ revision or a merge-result commit containing it can trigger repair.
187
+
188
+ An eyes reaction means the watcher saw an authorized comment. It does not mean a
189
+ worker started, completed an adjustment, or consumed the feedback. Comments remain
190
+ pending until publication or a verified no-change result is acknowledged. Conflict
191
+ resolution, validation retries and safe publication use the shared
192
+ [Coding reconciliation contract](../coding/README.md#source-branch-reconciliation).
193
+
42
194
  ## Creating repository changes
43
195
 
44
196
  Load [gitlab-repo-change](../gitlab-repo-change/README.md) for UI and labeled-issue
@@ -48,6 +200,12 @@ the process branches, reconciles its remote marker through the durable write log
48
200
  and pins `iid` through server project persistence. Existing MR-bound metadata and
49
201
  tool calls remain supported. MR-only tools reject missing bindings.
50
202
 
203
+ The GitLab repository change process uses SSH clone URLs and `git-ssh` profiles.
204
+ The [Jira GitLab change](../jira-gitlab-change/README.md) process supports HTTPS with
205
+ the GitLab profile's token, or explicitly selected SSH profiles. HTTPS mappings need
206
+ no separate SSH credentials. Jira API tokens stay on the server. Supplying `origin`
207
+ in the GitLab binding pins the installation: tool calls fail if its profile is repointed.
208
+
51
209
  Source-issue tools require the launch-pinned `issueIid`. Issue updates, comments,
52
210
  labels, MR creation, and feedback acknowledgements reconcile uncertain writes.
53
211
  `gitlab_list_merge_request_feedback` and `gitlab_acknowledge_feedback` expose the
@@ -60,13 +218,24 @@ facts. Existing source callers retain their event kind and observation behavior.
60
218
  HTTPS preflight performs repository reads and a dry-run feature-branch push without
61
219
  putting credentials in URLs or command arguments.
62
220
 
221
+ `createGitLabPublicationAdapter()` shares publication and repair operations between
222
+ the GitLab and Jira processes. `gitlabExternal.mergeRequests()` observes coordinated
223
+ repositories through the same MR observation contract, retaining each repository's
224
+ `projectKey`, cursor, source revision, feedback settling, and repair evidence.
225
+
63
226
  ## API support
64
227
 
65
228
  The following exported declarations are `@public`:
66
229
 
67
- - `@leitwerk-dev/gitlab`: `GitLabDeliveryObservation`, `GitLabIssueWatcherEvent`, `gitlabIssueExternalId`, `gitlabIssueWatcherSource`, `GitLabDiff`, `GitLabFeedback`, `GitLabIdentity`, `GitLabIntegration`, `GitLabJob`, `GitLabMergeRequest`, `GitLabObservation`, `GitLabProject`, `GitLabSelection`, `default`, `ensureGitLabSeenReaction`, `gitLabFeedbackReadyAt`, `gitlabExternal`, `gitlabIntegration`, `gitlabRepositoryCredentials`, `observationKey`, `observeMergeRequest`, `parseGitLabSelection`, `pendingGitLabFeedback`, `resolveGitLabBinding`, `selectGitLabProjects`.
230
+ - `@leitwerk-dev/gitlab`: `GitLabDeliveryObservation`, `GitLabIssueWatcherEvent`, `gitlabIssueExternalId`, `gitlabIssueWatcherSource`, `GitLabDiff`, `GitLabFeedback`, `GitLabIdentity`, `GitLabIntegration`, `GitLabJob`, `GitLabMergeRequest`, `GitLabObservation`, `GitLabProject`, `GitLabRepositoryCatalog`, `GitLabSelection`, `default`, `ensureGitLabSeenReaction`, `gitLabFeedbackReadyAt`, `gitlabExternal`, `gitlabIntegration`, `gitlabRepositoryCredentials`, `observationKey`, `observeMergeRequest`, `parseGitLabSelection`, `pendingGitLabFeedback`, `resolveGitLabBinding`, `selectGitLabProjects`.
68
231
  - `@leitwerk-dev/gitlab/testing`: `GitLabClientLike`, `GitLabMergeRequest`, `GitLabPipeline`, `GitLabProject`, `LocalGitLabAdapter`, `setupGitLabIntegration`.
69
232
 
233
+ The maintained-process API also supports `registerGitLabMaintainedProcess`,
234
+ `gitlabMaintenanceSource`, `gitlabMaintenance`, `GITLAB_MAINTAINED_KIND`,
235
+ `GITLAB_ACTIVE_LABEL`, `GITLAB_DONE_LABEL` and the exported
236
+ `GitLabMaintainedBinding`, `GitLabMaintainedProcess`, `GitLabMaintenance*` policy,
237
+ context, event, message, record, destination, retry and settings types.
238
+
70
239
  Members have individual classifications; these exports do not make every member
71
240
  public. Both `@public` and `@internal` APIs remain usable and fully typed. Source
72
241
  annotations are authoritative; see the [SDK compatibility
@@ -77,3 +246,7 @@ policy](../../docs/process-sdk.md#api-compatibility).
77
246
  Writes follow the [shared reconciliation contract](../../docs/process-sdk.md#typed-external-writes).
78
247
  Comment recovery includes closed merge requests and completed discussions. A logged
79
248
  comment or reaction that cannot be recovered fails without repeating the write.
249
+
250
+ The Settings repository refresh discovers repositories through configured profiles.
251
+ Provider origin and stable repository ID define identity; known clone URLs are
252
+ aliases. Execution uses retained identities without requiring external rediscovery.
@@ -1,11 +1,14 @@
1
1
  import { type RepositoryCredentialProject, type RepositoryCredentialRequirement } from "@leitwerk-dev/process-sdk";
2
2
  import type { GitLabClientLike } from "./client.js";
3
+ import type { GitLabRepositoryCatalog } from "./repository-catalog.js";
3
4
  /** @public */
4
5
  export interface GitLabIntegration {
5
6
  /** @public */
6
7
  profiles(): readonly string[];
7
8
  /** @public */
8
9
  client(profile: string): GitLabClientLike;
10
+ /** Cached repository metadata for Settings, supplied by server setup. @public */
11
+ readonly repositoryCatalog?: GitLabRepositoryCatalog;
9
12
  }
10
13
  /** @public */
11
14
  export declare const gitlabIntegration: import("@leitwerk-dev/process-sdk").CapabilityToken<GitLabIntegration>;
@@ -1 +1 @@
1
- {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,2BAA2B,EAChC,KAAK,+BAA+B,EACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,cAAc;AACd,MAAM,WAAW,iBAAiB;IACjC,cAAc;IACd,QAAQ,IAAI,SAAS,MAAM,EAAE,CAAC;IAC9B,cAAc;IACd,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AACD,cAAc;AACd,eAAO,MAAM,iBAAiB,wEAE7B,CAAC;AACF,mFAAmF;AACnF,wBAAgB,2BAA2B,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,2BAA2B,EAAE,GAC9C,+BAA+B,EAAE,CAMnC"}
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,2BAA2B,EAChC,KAAK,+BAA+B,EACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,cAAc;AACd,MAAM,WAAW,iBAAiB;IACjC,cAAc;IACd,QAAQ,IAAI,SAAS,MAAM,EAAE,CAAC;IAC9B,cAAc;IACd,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAC1C,iFAAiF;IACjF,QAAQ,CAAC,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;CACrD;AACD,cAAc;AACd,eAAO,MAAM,iBAAiB,wEAE7B,CAAC;AACF,mFAAmF;AACnF,wBAAgB,2BAA2B,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,2BAA2B,EAAE,GAC9C,+BAA+B,EAAE,CAMnC"}