@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/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, completion policy and optional retry budget.
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,86 @@ 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
 
40
105
  The extension contains no Renovate selection or repair policy. `./testing` exports a persistent `LocalGitLabAdapter` with real local repository ancestry for integration tests.
41
106
 
107
+ ## Shared MR maintenance
108
+
109
+ Opt in during `setupServer`. Declare external edges using
110
+ `gitlabMaintenanceSource()` and register their identities:
111
+
112
+ ```ts
113
+ registerGitLabMaintainedProcess(api, {
114
+ processId: process.id,
115
+ paramsCodec: process.paramsCodec,
116
+ stateCodec: process.stateCodec,
117
+ idleTurnId: "deliver_change",
118
+ destinations: {
119
+ feedback: "maintenance_feedback",
120
+ conflict: "maintenance_conflict",
121
+ ci: "maintenance_ci",
122
+ },
123
+ observe: repairPolicy.observe,
124
+ stopped: repairPolicy.stopped,
125
+ terminal: repairPolicy.terminal,
126
+ completion: repairPolicy.completion,
127
+ complete: repairPolicy.complete,
128
+ });
129
+ ```
130
+
131
+ Bindings default to each process project's `gitlab` metadata. `bindings` can
132
+ provide explicit MR targets. `settings` supplies the consumed feedback cursor,
133
+ activation receipt, polling interval and quiet period; the quiet period defaults
134
+ to two minutes. `assess`, `eligible` and `canWrite` retain process-specific admission
135
+ rules. `observe` returns state and an optional destination key (`feedback`,
136
+ `conflict`, `ci`) or an additional declared external action. The service fires the
137
+ existing edge; ordinary observations allocate no worker and create no turn record.
138
+ `currentBinding` identifies a selected repair or operator decision so removing a
139
+ different MR's label preserves that business position. Interrupted repairs on
140
+ remaining MRs retain their staged work and repair budgets.
141
+
142
+ `messages` supplies retry-safe discussion replies or comments. `settled` advances
143
+ business acknowledgement state after those writes succeed. `completion` determines
144
+ the terminal lifecycle without remote writes. `complete` delivers process-specific
145
+ terminal writes and retries them after the process ends. Optional `retry.maxAttempts`
146
+ bounds generic infrastructure retries without consuming the process's repair budget.
147
+
148
+ Taking responsibility adds `leitwerk-active`. Green CI keeps maintenance active for
149
+ later feedback. Removing the label ends that MR's activation and leaves the MR open.
150
+ Other bindings continue; a single stopped, unmerged binding aborts its process.
151
+ Remove/re-add pairs between polls end the old activation. Ownership is rechecked
152
+ before publication, replies and reactions; late worker outcomes are fenced.
153
+ Label-read failures produce retry diagnostics and do not cancel maintenance.
154
+ Deleting a linked MR aborts the whole process, including running repairs and
155
+ operator waits. Deletion is confirmed by an MR 404 while its project remains
156
+ accessible; access failures and other read errors remain retryable diagnostics.
157
+ Deleted bindings are persisted and receive no further MR reads or writes after
158
+ restart.
159
+
160
+ Merged MRs lose `leitwerk-active` and gain `leitwerk-done`. Unmerged closure and
161
+ stopping remove active without adding done. Label writes preserve unrelated labels
162
+ and reconcile lost responses. Startup adopts live bindings and existing activation
163
+ receipts, retaining feedback cursors, budgets, selected turns and historical records.
164
+ Processes retain their own reactivation admission and partial-completion rules.
165
+
166
+ The shared publication adapter used by Jira and GitLab repository changes registers
167
+ this policy. Settled feedback and actionable conflicts invoke Address Feedback
168
+ directly; failed current-revision CI invokes Fix CI. Changed work returns to Deliver.
169
+ A no-change outcome acknowledges its batch and resumes observation without another
170
+ Deliver execution. Label, target-head and mergeability updates do not replay a
171
+ handled pipeline failure. A new pipeline or an observed running-to-failed retry
172
+ remains actionable. Maintenance adds no business turns.
173
+
42
174
  ## Creating repository changes
43
175
 
44
176
  Load [gitlab-repo-change](../gitlab-repo-change/README.md) for UI and labeled-issue
@@ -48,6 +180,12 @@ the process branches, reconciles its remote marker through the durable write log
48
180
  and pins `iid` through server project persistence. Existing MR-bound metadata and
49
181
  tool calls remain supported. MR-only tools reject missing bindings.
50
182
 
183
+ The GitLab repository change process uses SSH clone URLs and `git-ssh` profiles.
184
+ The [Jira GitLab change](../jira-gitlab-change/README.md) process supports HTTPS with
185
+ the GitLab profile's token, or explicitly selected SSH profiles. HTTPS mappings need
186
+ no separate SSH credentials. Jira API tokens stay on the server. Supplying `origin`
187
+ in the GitLab binding pins the installation: tool calls fail if its profile is repointed.
188
+
51
189
  Source-issue tools require the launch-pinned `issueIid`. Issue updates, comments,
52
190
  labels, MR creation, and feedback acknowledgements reconcile uncertain writes.
53
191
  `gitlab_list_merge_request_feedback` and `gitlab_acknowledge_feedback` expose the
@@ -60,13 +198,24 @@ facts. Existing source callers retain their event kind and observation behavior.
60
198
  HTTPS preflight performs repository reads and a dry-run feature-branch push without
61
199
  putting credentials in URLs or command arguments.
62
200
 
201
+ `createGitLabPublicationAdapter()` shares publication and repair operations between
202
+ the GitLab and Jira processes. `gitlabExternal.mergeRequests()` observes coordinated
203
+ repositories through the same MR observation contract, retaining each repository's
204
+ `projectKey`, cursor, source revision, feedback settling, and repair evidence.
205
+
63
206
  ## API support
64
207
 
65
208
  The following exported declarations are `@public`:
66
209
 
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`.
210
+ - `@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
211
  - `@leitwerk-dev/gitlab/testing`: `GitLabClientLike`, `GitLabMergeRequest`, `GitLabPipeline`, `GitLabProject`, `LocalGitLabAdapter`, `setupGitLabIntegration`.
69
212
 
213
+ The maintained-process API also supports `registerGitLabMaintainedProcess`,
214
+ `gitlabMaintenanceSource`, `gitlabMaintenance`, `GITLAB_MAINTAINED_KIND`,
215
+ `GITLAB_ACTIVE_LABEL`, `GITLAB_DONE_LABEL` and the exported
216
+ `GitLabMaintainedBinding`, `GitLabMaintainedProcess`, `GitLabMaintenance*` policy,
217
+ context, event, message, record, destination, retry and settings types.
218
+
70
219
  Members have individual classifications; these exports do not make every member
71
220
  public. Both `@public` and `@internal` APIs remain usable and fully typed. Source
72
221
  annotations are authoritative; see the [SDK compatibility
@@ -77,3 +226,7 @@ policy](../../docs/process-sdk.md#api-compatibility).
77
226
  Writes follow the [shared reconciliation contract](../../docs/process-sdk.md#typed-external-writes).
78
227
  Comment recovery includes closed merge requests and completed discussions. A logged
79
228
  comment or reaction that cannot be recovered fails without repeating the write.
229
+
230
+ The Settings repository refresh discovers repositories through configured profiles.
231
+ Provider origin and stable repository ID define identity; known clone URLs are
232
+ 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"}