@leitwerk-dev/gitlab 0.2.0 → 0.2.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.
- package/README.md +21 -3
- package/dist/capability.d.ts +5 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/{chunk-5GBBPAG5.js → chunk-64FNBSKH.js} +95 -146
- package/dist/chunk-64FNBSKH.js.map +1 -0
- package/dist/client.d.ts +161 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/external.d.ts +25 -4
- package/dist/external.d.ts.map +1 -1
- package/dist/index.d.ts +10 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +80 -22
- package/dist/index.js.map +1 -1
- package/dist/selection.d.ts +11 -1
- package/dist/selection.d.ts.map +1 -1
- package/dist/setup.d.ts +11 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/testing.d.ts +28 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +11 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +28 -4
- package/dist/tools.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/capability.ts +5 -1
- package/src/client.ts +232 -13
- package/src/external.ts +43 -7
- package/src/index.ts +39 -26
- package/src/selection.ts +19 -3
- package/src/setup.ts +20 -0
- package/src/testing.ts +23 -8
- package/src/tools.ts +76 -50
- package/dist/chunk-5GBBPAG5.js.map +0 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ extensions:
|
|
|
17
17
|
|
|
18
18
|
`base_url` must be an HTTPS origin without credentials, a query or a fragment. Supply a personal, project or group token with `api` and `write_repository` scopes and permission to push the selected source branches. Tokens stay on the server except for the selected repository's authenticated `worker.start` delivery. No separate Git credential configuration is needed. Missing tokens, identity or permissions are configuration errors.
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Interface
|
|
21
21
|
|
|
22
22
|
- `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
23
|
- `gitlabIntegration` exposes `profiles()` and `client(profile)` through the SDK capability registry. `setupGitLabIntegration()` registers an explicit adapter for tools and external observations.
|
|
@@ -30,10 +30,28 @@ extensions:
|
|
|
30
30
|
|
|
31
31
|
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.
|
|
32
32
|
|
|
33
|
-
Comments require a stable business `writeKey`. `ensureGitLabComment()` combines it with the instance, project, MR and process IDs, appends a hidden marker, and uses `
|
|
33
|
+
Comments require a stable business `writeKey`. `ensureGitLabComment()` combines it with the instance, project, MR and process IDs, appends a hidden marker, and uses `ctx.externalWrites.ensure()`. It searches remote notes before creating a comment and after an uncertain write. `gitlab_reply` additionally requires `discussionId` and reconciles within that discussion. Repeating a call after losing either the response or the local write-log record reuses the same remote comment.
|
|
34
34
|
|
|
35
35
|
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, the authenticated bot and accounts flagged as bots. 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.
|
|
36
36
|
|
|
37
|
-
`ensureGitLabSeenReaction()` lets a process acknowledge an authorized MR comment with an eyes reaction. It reconciles the authenticated bot's reaction and records it with `
|
|
37
|
+
`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.
|
|
38
38
|
|
|
39
39
|
The extension contains no Renovate selection or repair policy. `./testing` exports a persistent `LocalGitLabAdapter` with real local repository ancestry for integration tests.
|
|
40
|
+
|
|
41
|
+
## API support
|
|
42
|
+
|
|
43
|
+
The following exported declarations are `@public`:
|
|
44
|
+
|
|
45
|
+
- `@leitwerk-dev/gitlab`: `GitLabDiff`, `GitLabFeedback`, `GitLabIdentity`, `GitLabIntegration`, `GitLabJob`, `GitLabMergeRequest`, `GitLabObservation`, `GitLabProject`, `GitLabSelection`, `default`, `ensureGitLabSeenReaction`, `gitLabFeedbackReadyAt`, `gitlabExternal`, `gitlabIntegration`, `gitlabRepositoryCredentials`, `observationKey`, `observeMergeRequest`, `parseGitLabSelection`, `pendingGitLabFeedback`, `resolveGitLabBinding`, `selectGitLabProjects`.
|
|
46
|
+
- `@leitwerk-dev/gitlab/testing`: `GitLabClientLike`, `GitLabMergeRequest`, `GitLabPipeline`, `GitLabProject`, `LocalGitLabAdapter`, `setupGitLabIntegration`.
|
|
47
|
+
|
|
48
|
+
Members have individual classifications; these exports do not make every member
|
|
49
|
+
public. Both `@public` and `@internal` APIs remain usable and fully typed. Source
|
|
50
|
+
annotations are authoritative; see the [SDK compatibility
|
|
51
|
+
policy](../../docs/process-sdk.md#api-compatibility).
|
|
52
|
+
|
|
53
|
+
### External-write replay
|
|
54
|
+
|
|
55
|
+
Writes follow the [shared reconciliation contract](../../docs/process-sdk.md#typed-external-writes).
|
|
56
|
+
Comment recovery includes closed merge requests and completed discussions. A logged
|
|
57
|
+
comment or reaction that cannot be recovered fails without repeating the write.
|
package/dist/capability.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { type RepositoryCredentialProject, type RepositoryCredentialRequirement } from "@leitwerk-dev/process-sdk";
|
|
2
2
|
import type { GitLabClientLike } from "./client.js";
|
|
3
|
+
/** @public */
|
|
3
4
|
export interface GitLabIntegration {
|
|
5
|
+
/** @public */
|
|
4
6
|
profiles(): readonly string[];
|
|
7
|
+
/** @public */
|
|
5
8
|
client(profile: string): GitLabClientLike;
|
|
6
9
|
}
|
|
10
|
+
/** @public */
|
|
7
11
|
export declare const gitlabIntegration: import("@leitwerk-dev/process-sdk").CapabilityToken<GitLabIntegration>;
|
|
8
|
-
/** Internal references are derived from the same profile as API access. */
|
|
12
|
+
/** Internal references are derived from the same profile as API access. @public */
|
|
9
13
|
export declare function gitlabRepositoryCredentials(profile: string, projects: readonly RepositoryCredentialProject[]): RepositoryCredentialRequirement[];
|
|
10
14
|
//# sourceMappingURL=capability.d.ts.map
|
package/dist/capability.d.ts.map
CHANGED
|
@@ -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,MAAM,WAAW,iBAAiB;IACjC,QAAQ,IAAI,SAAS,MAAM,EAAE,CAAC;IAC9B,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AACD,eAAO,MAAM,iBAAiB,wEAE7B,CAAC;AACF,
|
|
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,27 +1,8 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
coreHostCapabilities
|
|
4
|
-
} from "@leitwerk-dev/process-sdk";
|
|
5
|
-
|
|
6
|
-
// src/capability.ts
|
|
7
|
-
import {
|
|
8
|
-
createCapabilityToken
|
|
9
|
-
} from "@leitwerk-dev/process-sdk";
|
|
10
|
-
var gitlabIntegration = createCapabilityToken(
|
|
11
|
-
"@leitwerk-dev/gitlab.integration"
|
|
12
|
-
);
|
|
13
|
-
function gitlabRepositoryCredentials(profile, projects) {
|
|
14
|
-
return projects.map((project) => ({
|
|
15
|
-
projectKey: project.key,
|
|
16
|
-
kind: "git_https",
|
|
17
|
-
credentialRef: `gitlab:${profile}`
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
1
|
// src/client.ts
|
|
22
2
|
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
23
3
|
import { repositoryHttpsUrl } from "@leitwerk-dev/process-sdk";
|
|
24
4
|
var GitLabError = class extends Error {
|
|
5
|
+
/** @internal */
|
|
25
6
|
constructor(status, retryable) {
|
|
26
7
|
super(
|
|
27
8
|
`GitLab request failed (${status || "network unavailable"})${retryable ? "; retryable" : "; check profile and project access"}`
|
|
@@ -62,10 +43,12 @@ function parseGitLabProfiles(raw) {
|
|
|
62
43
|
var projectPath = (id) => `/projects/${encodeURIComponent(id)}`;
|
|
63
44
|
var mrPath = (id, iid) => `${projectPath(id)}/merge_requests/${iid}`;
|
|
64
45
|
var GitLabClient = class {
|
|
46
|
+
/** @public */
|
|
65
47
|
baseUrl;
|
|
66
48
|
#profile;
|
|
67
49
|
#fetch;
|
|
68
50
|
#sleep;
|
|
51
|
+
/** @internal */
|
|
69
52
|
constructor(profile, options = {}) {
|
|
70
53
|
if (repositoryHttpsUrl(`${profile.baseUrl}/repository`).origin !== profile.baseUrl)
|
|
71
54
|
throw new Error("GitLab requires an HTTPS origin baseUrl");
|
|
@@ -136,69 +119,85 @@ var GitLabClient = class {
|
|
|
136
119
|
}
|
|
137
120
|
throw new Error("GitLab pagination limit exceeded; discovery incomplete");
|
|
138
121
|
}
|
|
122
|
+
/** @public */
|
|
139
123
|
getProject(id, signal) {
|
|
140
124
|
return this.request(projectPath(id), signal);
|
|
141
125
|
}
|
|
126
|
+
/** @internal */
|
|
142
127
|
listProjects(signal) {
|
|
143
128
|
return this.pages("/projects?archived=false", signal);
|
|
144
129
|
}
|
|
130
|
+
/** @internal */
|
|
145
131
|
getGroup(id, signal) {
|
|
146
132
|
return this.request(`/groups/${encodeURIComponent(id)}`, signal);
|
|
147
133
|
}
|
|
134
|
+
/** @internal */
|
|
148
135
|
listGroupProjects(id, signal) {
|
|
149
136
|
return this.pages(
|
|
150
137
|
`/groups/${encodeURIComponent(id)}/projects?include_subgroups=true&with_shared=false&archived=false`,
|
|
151
138
|
signal
|
|
152
139
|
);
|
|
153
140
|
}
|
|
141
|
+
/** @public */
|
|
154
142
|
listMergeRequests(id, label, signal) {
|
|
155
143
|
return this.pages(
|
|
156
144
|
`${projectPath(id)}/merge_requests?state=opened&labels=${encodeURIComponent(label)}`,
|
|
157
145
|
signal
|
|
158
146
|
);
|
|
159
147
|
}
|
|
148
|
+
/** @internal */
|
|
160
149
|
getMergeRequest(id, iid, signal) {
|
|
161
150
|
return this.request(mrPath(id, iid), signal);
|
|
162
151
|
}
|
|
152
|
+
/** @public */
|
|
163
153
|
getChanges(id, iid, signal) {
|
|
164
154
|
return this.pages(`${mrPath(id, iid)}/diffs`, signal);
|
|
165
155
|
}
|
|
156
|
+
/** @public */
|
|
166
157
|
getBranch(id, branch, signal) {
|
|
167
158
|
return this.request(
|
|
168
159
|
`${projectPath(id)}/repository/branches/${encodeURIComponent(branch)}`,
|
|
169
160
|
signal
|
|
170
161
|
);
|
|
171
162
|
}
|
|
163
|
+
/** @internal */
|
|
172
164
|
getCommit(id, sha, signal) {
|
|
173
165
|
return this.request(`${projectPath(id)}/repository/commits/${encodeURIComponent(sha)}`, signal);
|
|
174
166
|
}
|
|
167
|
+
/** @internal */
|
|
175
168
|
listMergeRequestPipelines(id, iid, signal) {
|
|
176
169
|
return this.pages(`${mrPath(id, iid)}/pipelines`, signal);
|
|
177
170
|
}
|
|
171
|
+
/** @internal */
|
|
178
172
|
listBranchPipelines(id, branch, sha, signal) {
|
|
179
173
|
return this.pages(
|
|
180
174
|
`${projectPath(id)}/pipelines?ref=${encodeURIComponent(branch)}&sha=${encodeURIComponent(sha)}&source=push`,
|
|
181
175
|
signal
|
|
182
176
|
);
|
|
183
177
|
}
|
|
178
|
+
/** @internal */
|
|
184
179
|
getPipeline(id, pipeline, signal) {
|
|
185
180
|
return this.request(`${projectPath(id)}/pipelines/${pipeline}`, signal);
|
|
186
181
|
}
|
|
182
|
+
/** @public */
|
|
187
183
|
listFailedJobs(id, pipeline, signal) {
|
|
188
184
|
return this.pages(
|
|
189
185
|
`${projectPath(id)}/pipelines/${pipeline}/jobs?scope[]=failed&include_retried=false`,
|
|
190
186
|
signal
|
|
191
187
|
);
|
|
192
188
|
}
|
|
189
|
+
/** @internal */
|
|
193
190
|
listNotes(id, iid, signal) {
|
|
194
191
|
return this.pages(`${mrPath(id, iid)}/notes`, signal);
|
|
195
192
|
}
|
|
193
|
+
/** @internal */
|
|
196
194
|
getDiscussion(id, iid, discussionId, signal) {
|
|
197
195
|
return this.request(
|
|
198
196
|
`${mrPath(id, iid)}/discussions/${encodeURIComponent(discussionId)}`,
|
|
199
197
|
signal
|
|
200
198
|
);
|
|
201
199
|
}
|
|
200
|
+
/** @internal */
|
|
202
201
|
replyToDiscussion(id, iid, discussionId, body, signal) {
|
|
203
202
|
return this.request(
|
|
204
203
|
`${mrPath(id, iid)}/discussions/${encodeURIComponent(discussionId)}/notes`,
|
|
@@ -206,12 +205,15 @@ var GitLabClient = class {
|
|
|
206
205
|
{ body }
|
|
207
206
|
);
|
|
208
207
|
}
|
|
208
|
+
/** @internal */
|
|
209
209
|
listNoteReactions(id, iid, noteId, signal) {
|
|
210
210
|
return this.pages(`${mrPath(id, iid)}/notes/${noteId}/award_emoji`, signal);
|
|
211
211
|
}
|
|
212
|
+
/** @internal */
|
|
212
213
|
addNoteReaction(id, iid, noteId, name, signal) {
|
|
213
214
|
return this.request(`${mrPath(id, iid)}/notes/${noteId}/award_emoji`, signal, { name });
|
|
214
215
|
}
|
|
216
|
+
/** @public */
|
|
215
217
|
async listMergeRequestFeedback(id, iid, signal) {
|
|
216
218
|
const [discussions, identity] = await Promise.all([
|
|
217
219
|
this.pages(`${mrPath(id, iid)}/discussions`, signal),
|
|
@@ -238,9 +240,11 @@ var GitLabClient = class {
|
|
|
238
240
|
}
|
|
239
241
|
return feedback.sort((a, b) => a.id - b.id);
|
|
240
242
|
}
|
|
243
|
+
/** @internal */
|
|
241
244
|
addNote(id, iid, body, signal) {
|
|
242
245
|
return this.request(`${mrPath(id, iid)}/notes`, signal, { body });
|
|
243
246
|
}
|
|
247
|
+
/** @public */
|
|
244
248
|
async resolveGitIdentity(signal) {
|
|
245
249
|
const user = await this.request("/user", signal);
|
|
246
250
|
const name = this.#profile.gitIdentity?.name ?? user.name;
|
|
@@ -251,6 +255,7 @@ var GitLabClient = class {
|
|
|
251
255
|
);
|
|
252
256
|
return { name, email, username: user.username };
|
|
253
257
|
}
|
|
258
|
+
/** @public */
|
|
254
259
|
async getJobTrace(id, job, maxBytes = 65536, signal) {
|
|
255
260
|
const limit = Math.min(262144, Math.max(1, Math.floor(maxBytes) || 65536));
|
|
256
261
|
const response = await this.response(`${projectPath(id)}/jobs/${job}/trace`, signal);
|
|
@@ -280,6 +285,7 @@ var GitLabClient = class {
|
|
|
280
285
|
async function observeMergeRequest(client, projectId, iid, signal) {
|
|
281
286
|
const mr = await client.getMergeRequest(projectId, iid, signal);
|
|
282
287
|
if (mr.state !== "opened") return { mr, pipeline: null };
|
|
288
|
+
const targetHead = (await client.getBranch(mr.target_project_id, mr.target_branch, signal)).commit.id;
|
|
283
289
|
const associated = (await client.listMergeRequestPipelines(projectId, iid, signal)).sort(
|
|
284
290
|
(a, b) => b.id - a.id
|
|
285
291
|
);
|
|
@@ -290,7 +296,8 @@ async function observeMergeRequest(client, projectId, iid, signal) {
|
|
|
290
296
|
const commit = await client.getCommit(id, candidate.sha, signal);
|
|
291
297
|
matches = commit.parent_ids.includes(mr.sha);
|
|
292
298
|
}
|
|
293
|
-
if (matches)
|
|
299
|
+
if (matches)
|
|
300
|
+
return { mr, targetHead, pipeline: await client.getPipeline(id, candidate.id, signal) };
|
|
294
301
|
}
|
|
295
302
|
const candidates = await client.listBranchPipelines(
|
|
296
303
|
mr.source_project_id,
|
|
@@ -301,10 +308,26 @@ async function observeMergeRequest(client, projectId, iid, signal) {
|
|
|
301
308
|
const latest = candidates.filter((p) => p.sha === mr.sha && p.ref === mr.source_branch && p.source === "push").sort((a, b) => b.id - a.id)[0];
|
|
302
309
|
return {
|
|
303
310
|
mr,
|
|
311
|
+
targetHead,
|
|
304
312
|
pipeline: latest ? await client.getPipeline(mr.source_project_id, latest.id, signal) : null
|
|
305
313
|
};
|
|
306
314
|
}
|
|
307
315
|
|
|
316
|
+
// src/capability.ts
|
|
317
|
+
import {
|
|
318
|
+
createCapabilityToken
|
|
319
|
+
} from "@leitwerk-dev/process-sdk";
|
|
320
|
+
var gitlabIntegration = createCapabilityToken(
|
|
321
|
+
"@leitwerk-dev/gitlab.integration"
|
|
322
|
+
);
|
|
323
|
+
function gitlabRepositoryCredentials(profile, projects) {
|
|
324
|
+
return projects.map((project) => ({
|
|
325
|
+
projectKey: project.key,
|
|
326
|
+
kind: "git_https",
|
|
327
|
+
credentialRef: `gitlab:${profile}`
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
|
|
308
331
|
// src/external.ts
|
|
309
332
|
import {
|
|
310
333
|
createExternalSourcePollReporter
|
|
@@ -318,20 +341,29 @@ function pendingGitLabFeedback(items, afterId, since) {
|
|
|
318
341
|
function gitLabFeedbackReadyAt(items, quietPeriodMs) {
|
|
319
342
|
return items.length ? Math.max(...items.map((item) => Date.parse(item.createdAt))) + quietPeriodMs : null;
|
|
320
343
|
}
|
|
321
|
-
var observationKey = ({ mr, pipeline }) => JSON.stringify([
|
|
344
|
+
var observationKey = ({ mr, pipeline, targetHead }) => JSON.stringify([
|
|
322
345
|
mr.state,
|
|
323
346
|
mr.sha,
|
|
324
347
|
[...mr.labels].sort(),
|
|
325
348
|
pipeline?.project_id,
|
|
326
349
|
pipeline?.id,
|
|
327
|
-
pipeline?.status
|
|
350
|
+
pipeline?.status,
|
|
351
|
+
mr.source_project_id,
|
|
352
|
+
mr.source_branch,
|
|
353
|
+
mr.target_project_id,
|
|
354
|
+
mr.target_branch,
|
|
355
|
+
targetHead,
|
|
356
|
+
mr.has_conflicts,
|
|
357
|
+
mr.merge_status,
|
|
358
|
+
mr.detailed_merge_status
|
|
328
359
|
]);
|
|
329
360
|
var gitlabExternal = {
|
|
361
|
+
/** @public */
|
|
330
362
|
mergeRequest(resolve) {
|
|
331
363
|
return {
|
|
332
364
|
kind: GITLAB_MR_KIND,
|
|
333
365
|
label: "GitLab merge request",
|
|
334
|
-
description: "Observe MR state,
|
|
366
|
+
description: "Observe MR state, source/target heads, mergeability and revision-correlated CI",
|
|
335
367
|
config: {},
|
|
336
368
|
inputMode: "none",
|
|
337
369
|
resolve
|
|
@@ -410,15 +442,19 @@ function createGitLabProvider(deps, integration, options = {}) {
|
|
|
410
442
|
|
|
411
443
|
// src/tools.ts
|
|
412
444
|
import { createHash } from "crypto";
|
|
413
|
-
import {
|
|
414
|
-
createWriteIdentity,
|
|
415
|
-
ensureWrite
|
|
416
|
-
} from "@leitwerk-dev/external-writes";
|
|
417
445
|
import {
|
|
418
446
|
numberArg,
|
|
419
447
|
projectParameters,
|
|
420
448
|
stringArg
|
|
421
449
|
} from "@leitwerk-dev/process-sdk";
|
|
450
|
+
async function existingRemote(read) {
|
|
451
|
+
try {
|
|
452
|
+
return await read();
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (error instanceof GitLabError && error.status === 404) return null;
|
|
455
|
+
throw error;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
422
458
|
function resolveGitLabBinding(ctx) {
|
|
423
459
|
if (!ctx.project || ctx.project.instanceId !== ctx.process.id)
|
|
424
460
|
throw new Error("An authorized GitLab process project is required");
|
|
@@ -427,17 +463,6 @@ function resolveGitLabBinding(ctx) {
|
|
|
427
463
|
throw new Error("Invalid GitLab project binding");
|
|
428
464
|
return { profile: binding.profile, projectId: binding.projectId, iid: binding.iid };
|
|
429
465
|
}
|
|
430
|
-
async function findOrCreate(find, create) {
|
|
431
|
-
const existing = await find();
|
|
432
|
-
if (existing) return existing;
|
|
433
|
-
try {
|
|
434
|
-
return await create();
|
|
435
|
-
} catch (error) {
|
|
436
|
-
const recovered = await find();
|
|
437
|
-
if (!recovered) throw error;
|
|
438
|
-
return recovered;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
466
|
async function ensureGitLabComment(input) {
|
|
442
467
|
const { client, writes, instanceId, projectId, iid, writeKey, signal } = input;
|
|
443
468
|
const identity = [client.baseUrl, projectId, iid, instanceId, writeKey];
|
|
@@ -448,38 +473,39 @@ async function ensureGitLabComment(input) {
|
|
|
448
473
|
const notes = input.discussionId ? (await client.getDiscussion(projectId, iid, input.discussionId, signal)).notes : await client.listNotes(projectId, iid, signal);
|
|
449
474
|
return notes.find((note) => note.body.includes(marker));
|
|
450
475
|
};
|
|
451
|
-
await
|
|
452
|
-
|
|
453
|
-
|
|
476
|
+
await writes.ensure(
|
|
477
|
+
{ writeType: "gitlab.comment", dedupKey: digest },
|
|
478
|
+
{
|
|
479
|
+
reconcile: () => existingRemote(async () => await find() ?? null),
|
|
480
|
+
execute: () => {
|
|
481
|
+
const body = `${input.body}
|
|
454
482
|
|
|
455
483
|
${marker}`;
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
484
|
+
return input.discussionId ? client.replyToDiscussion(projectId, iid, input.discussionId, body, signal) : client.addNote(projectId, iid, body, signal);
|
|
485
|
+
},
|
|
486
|
+
toMetadata: (note) => ({ projectId, iid, noteId: note.id, marker })
|
|
487
|
+
}
|
|
488
|
+
);
|
|
460
489
|
return { marker };
|
|
461
490
|
}
|
|
462
491
|
async function ensureGitLabSeenReaction(input) {
|
|
463
492
|
const { client, writes, instanceId, projectId, iid, noteId, signal } = input;
|
|
464
493
|
const digest = createHash("sha256").update(JSON.stringify([client.baseUrl, projectId, iid, instanceId, "eyes", noteId])).digest("hex");
|
|
465
|
-
await
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
)
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
() => client.addNoteReaction(projectId, iid, noteId, "eyes", signal)
|
|
477
|
-
);
|
|
478
|
-
return { projectId, iid, noteId, reactionId: reaction.id, name: "eyes" };
|
|
494
|
+
await writes.ensure(
|
|
495
|
+
{ writeType: "gitlab.reaction", dedupKey: digest },
|
|
496
|
+
{
|
|
497
|
+
reconcile: () => existingRemote(async () => {
|
|
498
|
+
const identity = await client.resolveGitIdentity(signal);
|
|
499
|
+
return (await client.listNoteReactions(projectId, iid, noteId, signal)).find(
|
|
500
|
+
(reaction) => reaction.name === "eyes" && reaction.user.username === identity.username
|
|
501
|
+
) ?? null;
|
|
502
|
+
}),
|
|
503
|
+
execute: () => client.addNoteReaction(projectId, iid, noteId, "eyes", signal),
|
|
504
|
+
toMetadata: (reaction) => ({ projectId, iid, noteId, reactionId: reaction.id, name: "eyes" })
|
|
479
505
|
}
|
|
480
506
|
);
|
|
481
507
|
}
|
|
482
|
-
function registerGitLabTools(api, integration
|
|
508
|
+
function registerGitLabTools(api, integration) {
|
|
483
509
|
for (const [name, description, required] of [
|
|
484
510
|
["gitlab_observe_merge_request", "Read the current MR source revision and its latest CI", []],
|
|
485
511
|
["gitlab_get_changes", "Read the MR changes", []],
|
|
@@ -521,7 +547,7 @@ function registerGitLabTools(api, integration, writes) {
|
|
|
521
547
|
if (name === "gitlab_comment" || name === "gitlab_reply")
|
|
522
548
|
return ensureGitLabComment({
|
|
523
549
|
client,
|
|
524
|
-
writes,
|
|
550
|
+
writes: ctx.externalWrites,
|
|
525
551
|
instanceId: ctx.process.id,
|
|
526
552
|
projectId: b.projectId,
|
|
527
553
|
iid: b.iid,
|
|
@@ -552,105 +578,28 @@ function registerGitLabTools(api, integration, writes) {
|
|
|
552
578
|
}
|
|
553
579
|
}
|
|
554
580
|
|
|
555
|
-
// src/
|
|
556
|
-
|
|
557
|
-
const list = (value) => {
|
|
558
|
-
if (value === void 0) return [];
|
|
559
|
-
if (!Array.isArray(value) || value.some(
|
|
560
|
-
(v) => typeof v !== "string" || !/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/.test(v) || v.split("/").some((p) => p === "." || p === "..")
|
|
561
|
-
))
|
|
562
|
-
throw new Error("GitLab selectors require exact namespace paths");
|
|
563
|
-
return [...new Set(value)];
|
|
564
|
-
};
|
|
565
|
-
const pair = (value) => {
|
|
566
|
-
if (value !== void 0 && (!value || typeof value !== "object" || Array.isArray(value)))
|
|
567
|
-
throw new Error("GitLab selectors must be objects");
|
|
568
|
-
const item = value;
|
|
569
|
-
return { include: list(item?.include), exclude: list(item?.exclude) };
|
|
570
|
-
};
|
|
571
|
-
if (raw.all_accessible !== void 0 && typeof raw.all_accessible !== "boolean")
|
|
572
|
-
throw new Error("all_accessible must be a boolean");
|
|
573
|
-
const parsed = {
|
|
574
|
-
projects: pair(raw.projects),
|
|
575
|
-
groups: pair(raw.groups),
|
|
576
|
-
allAccessible: raw.all_accessible === true
|
|
577
|
-
};
|
|
578
|
-
if (!parsed.allAccessible && !parsed.projects.include.length && !parsed.groups.include.length)
|
|
579
|
-
throw new Error("GitLab requires explicit project/group includes or all_accessible: true");
|
|
580
|
-
return parsed;
|
|
581
|
-
}
|
|
582
|
-
function projectExcluded(selection, name) {
|
|
583
|
-
return selection.projects.exclude.includes(name) || selection.groups.exclude.some((group) => name.startsWith(`${group}/`));
|
|
584
|
-
}
|
|
585
|
-
async function selectGitLabProjects(client, selection) {
|
|
586
|
-
const candidates = selection.allAccessible ? await client.listProjects() : [];
|
|
587
|
-
for (const name of selection.projects.include) candidates.push(await client.getProject(name));
|
|
588
|
-
for (const group of selection.groups.include)
|
|
589
|
-
candidates.push(...await client.listGroupProjects(group));
|
|
590
|
-
return [
|
|
591
|
-
...new Map(
|
|
592
|
-
candidates.filter((p) => !p.archived && !projectExcluded(selection, p.path_with_namespace)).map((p) => [p.id, p])
|
|
593
|
-
).values()
|
|
594
|
-
];
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// src/index.ts
|
|
598
|
-
var manifest = { id: "gitlab", version: "0.1.9" };
|
|
581
|
+
// src/setup.ts
|
|
582
|
+
import { coreHostCapabilities } from "@leitwerk-dev/process-sdk";
|
|
599
583
|
function setupGitLabIntegration(api, integration, options = {}) {
|
|
600
584
|
api.provide(gitlabIntegration, integration);
|
|
601
585
|
const deps = api.get(coreHostCapabilities.serverSetup);
|
|
602
586
|
if (!deps || Array.isArray(deps)) return;
|
|
603
|
-
registerGitLabTools(api, integration
|
|
587
|
+
registerGitLabTools(api, integration);
|
|
604
588
|
return createGitLabProvider(deps, integration, options);
|
|
605
589
|
}
|
|
606
|
-
var extension = {
|
|
607
|
-
manifest,
|
|
608
|
-
setupServer(api, config) {
|
|
609
|
-
const profiles = parseGitLabProfiles(config);
|
|
610
|
-
const clients = new Map([...profiles].map(([id, profile]) => [id, new GitLabClient(profile)]));
|
|
611
|
-
setupGitLabIntegration(api, {
|
|
612
|
-
profiles: () => [...profiles.keys()],
|
|
613
|
-
client: (profile) => {
|
|
614
|
-
const client = clients.get(profile);
|
|
615
|
-
if (!client) throw new Error(`Unknown GitLab profile '${profile}'`);
|
|
616
|
-
return client;
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
const deps = api.get(coreHostCapabilities.serverSetup);
|
|
620
|
-
if (!deps || Array.isArray(deps)) return;
|
|
621
|
-
deps.repositoryCredentials.register({
|
|
622
|
-
kind: "git_https",
|
|
623
|
-
resolve(ref) {
|
|
624
|
-
const profile = ref.startsWith("gitlab:") ? profiles.get(ref.slice(7)) : void 0;
|
|
625
|
-
return profile ? { origin: profile.baseUrl, username: "oauth2", password: profile.token } : null;
|
|
626
|
-
}
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
var index_default = extension;
|
|
631
590
|
|
|
632
591
|
export {
|
|
633
|
-
gitlabIntegration,
|
|
634
|
-
gitlabRepositoryCredentials,
|
|
635
|
-
GitLabError,
|
|
636
592
|
parseGitLabProfiles,
|
|
637
593
|
GitLabClient,
|
|
638
594
|
observeMergeRequest,
|
|
639
|
-
|
|
595
|
+
gitlabIntegration,
|
|
596
|
+
gitlabRepositoryCredentials,
|
|
640
597
|
pendingGitLabFeedback,
|
|
641
598
|
gitLabFeedbackReadyAt,
|
|
642
599
|
observationKey,
|
|
643
600
|
gitlabExternal,
|
|
644
|
-
createGitLabProvider,
|
|
645
601
|
resolveGitLabBinding,
|
|
646
|
-
ensureGitLabComment,
|
|
647
602
|
ensureGitLabSeenReaction,
|
|
648
|
-
|
|
649
|
-
parseGitLabSelection,
|
|
650
|
-
projectExcluded,
|
|
651
|
-
selectGitLabProjects,
|
|
652
|
-
manifest,
|
|
653
|
-
setupGitLabIntegration,
|
|
654
|
-
index_default
|
|
603
|
+
setupGitLabIntegration
|
|
655
604
|
};
|
|
656
|
-
//# sourceMappingURL=chunk-
|
|
605
|
+
//# sourceMappingURL=chunk-64FNBSKH.js.map
|