@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/src/selection.ts CHANGED
@@ -1,9 +1,24 @@
1
1
  import type { GitLabClientLike, GitLabProject } from "./client.js";
2
+ /** @public */
2
3
  export interface GitLabSelection {
3
- projects: { include: readonly string[]; exclude: readonly string[] };
4
- groups: { include: readonly string[]; exclude: readonly string[] };
4
+ /** @public */
5
+ projects: {
6
+ /** @public */
7
+ include: readonly string[];
8
+ /** @internal */
9
+ exclude: readonly string[];
10
+ };
11
+ /** @public */
12
+ groups: {
13
+ /** @public */
14
+ include: readonly string[];
15
+ /** @internal */
16
+ exclude: readonly string[];
17
+ };
18
+ /** @internal */
5
19
  allAccessible: boolean;
6
20
  }
21
+ /** @public */
7
22
  export function parseGitLabSelection(raw: Record<string, unknown>): GitLabSelection {
8
23
  const list = (value: unknown): string[] => {
9
24
  if (value === undefined) return [];
@@ -36,13 +51,14 @@ export function parseGitLabSelection(raw: Record<string, unknown>): GitLabSelect
36
51
  throw new Error("GitLab requires explicit project/group includes or all_accessible: true");
37
52
  return parsed;
38
53
  }
54
+ /** @internal */
39
55
  export function projectExcluded(selection: GitLabSelection, name: string): boolean {
40
56
  return (
41
57
  selection.projects.exclude.includes(name) ||
42
58
  selection.groups.exclude.some((group) => name.startsWith(`${group}/`))
43
59
  );
44
60
  }
45
- /** Include union, subgroup expansion, exclusion precedence, stable-ID deduplication. */
61
+ /** Include union, subgroup expansion, exclusion precedence, stable-ID deduplication. @public */
46
62
  export async function selectGitLabProjects(
47
63
  client: GitLabClientLike,
48
64
  selection: GitLabSelection,
package/src/setup.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { coreHostCapabilities, type ServerExtensionAPI } from "@leitwerk-dev/process-sdk";
2
+ import { type GitLabIntegration, gitlabIntegration } from "./capability.js";
3
+ import { createGitLabProvider } from "./external.js";
4
+ import { registerGitLabTools } from "./tools.js";
5
+
6
+ /** Register shared tools and polling with an explicit integration. @public */
7
+ export function setupGitLabIntegration(
8
+ api: ServerExtensionAPI,
9
+ integration: GitLabIntegration,
10
+ options: {
11
+ /** @public */
12
+ now?: () => number;
13
+ } = {},
14
+ ) {
15
+ api.provide(gitlabIntegration, integration);
16
+ const deps = api.get(coreHostCapabilities.serverSetup);
17
+ if (!deps || Array.isArray(deps)) return;
18
+ registerGitLabTools(api, integration);
19
+ return createGitLabProvider(deps, integration, options);
20
+ }
package/src/testing.ts CHANGED
@@ -12,32 +12,42 @@ import type {
12
12
  GitLabProject,
13
13
  } from "./client.js";
14
14
 
15
- export type {
16
- GitLabClientLike,
17
- GitLabMergeRequest,
18
- GitLabPipeline,
19
- GitLabProject,
20
- } from "./client.js";
21
- export { setupGitLabIntegration } from "./index.js";
15
+ export { setupGitLabIntegration } from "./setup.js";
22
16
 
17
+ /** @public */
23
18
  interface LocalState {
19
+ /** @internal */
24
20
  projects: GitLabProject[];
21
+ /** @internal */
25
22
  mrs: GitLabMergeRequest[];
23
+ /** @internal */
26
24
  pipelines: GitLabPipeline[];
25
+ /** @public */
27
26
  notes: Record<string, GitLabNote[]>;
27
+ /** @internal */
28
28
  diffs: Record<string, GitLabDiff[]>;
29
+ /** @public */
29
30
  feedback?: Record<string, GitLabFeedback[]>;
31
+ /** @public */
30
32
  discussionNotes?: Record<string, GitLabNote[]>;
33
+ /** @public */
31
34
  reactions?: Record<string, GitLabNoteReaction[]>;
32
35
  }
33
- /** Persistent GitLab test boundary. Repository URLs use local Git's file transport. */
36
+ /** Persistent GitLab test boundary. Repository URLs use local Git's file transport. @public */
34
37
  export class LocalGitLabAdapter {
38
+ /** @public */
35
39
  state: LocalState;
40
+ /** @public */
36
41
  loseNextCommentResponse = false;
42
+ /** @public */
37
43
  loseNextReplyResponse = false;
44
+ /** @public */
38
45
  loseNextReactionResponse = false;
46
+ /** @public */
39
47
  constructor(
48
+ /** @internal */
40
49
  readonly root: string,
50
+ /** @internal */
41
51
  readonly baseUrl = "https://gitlab.test",
42
52
  ) {
43
53
  mkdirSync(root, { recursive: true });
@@ -46,6 +56,7 @@ export class LocalGitLabAdapter {
46
56
  ? JSON.parse(readFileSync(file, "utf8"))
47
57
  : { projects: [], mrs: [], pipelines: [], notes: {}, diffs: {} };
48
58
  }
59
+ /** @public */
49
60
  save() {
50
61
  writeFileSync(path.join(this.root, "gitlab.json"), JSON.stringify(this.state), { mode: 0o600 });
51
62
  }
@@ -76,6 +87,7 @@ export class LocalGitLabAdapter {
76
87
  { encoding: "utf8" },
77
88
  ).trim();
78
89
  }
90
+ /** @public */
79
91
  addProject(name: string, bare: string): GitLabProject {
80
92
  const project: GitLabProject = {
81
93
  id: this.state.projects.length + 1,
@@ -88,6 +100,7 @@ export class LocalGitLabAdapter {
88
100
  this.save();
89
101
  return project;
90
102
  }
103
+ /** @public */
91
104
  openMr(project: GitLabProject, branch: string): GitLabMergeRequest {
92
105
  const mr: GitLabMergeRequest = {
93
106
  iid: this.state.mrs.length + 1,
@@ -107,6 +120,7 @@ export class LocalGitLabAdapter {
107
120
  this.save();
108
121
  return mr;
109
122
  }
123
+ /** @public */
110
124
  pipeline(mr: GitLabMergeRequest, status: string): GitLabPipeline {
111
125
  const value: GitLabPipeline = {
112
126
  id: this.state.pipelines.length + 1,
@@ -121,6 +135,7 @@ export class LocalGitLabAdapter {
121
135
  this.save();
122
136
  return value;
123
137
  }
138
+ /** @public */
124
139
  client(): GitLabClientLike {
125
140
  const mr = (id: number, iid: number) => {
126
141
  const m = this.state.mrs.find((m) => m.project_id === id && m.iid === iid);
package/src/tools.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
- import {
3
- createWriteIdentity,
4
- type ExternalWriteLogRepoLike,
5
- ensureWrite,
6
- } from "@leitwerk-dev/external-writes";
2
+ import type { ExternalWrites } from "@leitwerk-dev/external-writes";
3
+
7
4
  import {
8
5
  type IntegrationToolExecutionContext,
9
6
  numberArg,
@@ -12,10 +9,27 @@ import {
12
9
  stringArg,
13
10
  } from "@leitwerk-dev/process-sdk";
14
11
  import type { GitLabIntegration } from "./capability.js";
15
- import { type GitLabClientLike, observeMergeRequest } from "./client.js";
12
+ import { type GitLabClientLike, GitLabError, observeMergeRequest } from "./client.js";
13
+
14
+ async function existingRemote<T>(read: () => Promise<T>): Promise<T | null> {
15
+ try {
16
+ return await read();
17
+ } catch (error) {
18
+ if (error instanceof GitLabError && error.status === 404) return null;
19
+ throw error;
20
+ }
21
+ }
22
+ /** @public */
16
23
  export function resolveGitLabBinding(
17
24
  ctx: Pick<IntegrationToolExecutionContext, "project" | "process">,
18
- ): { profile: string; projectId: number; iid: number } {
25
+ ): {
26
+ /** @public */
27
+ profile: string;
28
+ /** @public */
29
+ projectId: number;
30
+ /** @public */
31
+ iid: number;
32
+ } {
19
33
  if (!ctx.project || ctx.project.instanceId !== ctx.process.id)
20
34
  throw new Error("An authorized GitLab process project is required");
21
35
  const binding = ctx.project.metadata?.gitlab as
@@ -30,28 +44,30 @@ export function resolveGitLabBinding(
30
44
  throw new Error("Invalid GitLab project binding");
31
45
  return { profile: binding.profile, projectId: binding.projectId, iid: binding.iid };
32
46
  }
33
- async function findOrCreate<T>(find: () => Promise<T | undefined>, create: () => Promise<T>) {
34
- const existing = await find();
35
- if (existing) return existing;
36
- try {
37
- return await create();
38
- } catch (error) {
39
- const recovered = await find();
40
- if (!recovered) throw error;
41
- return recovered;
42
- }
43
- }
47
+ /** @internal */
44
48
  export async function ensureGitLabComment(input: {
49
+ /** @internal */
45
50
  client: GitLabClientLike;
46
- writes: ExternalWriteLogRepoLike;
51
+ /** @internal */
52
+ writes: ExternalWrites;
53
+ /** @internal */
47
54
  instanceId: string;
55
+ /** @internal */
48
56
  projectId: number;
57
+ /** @internal */
49
58
  iid: number;
59
+ /** @internal */
50
60
  writeKey: string;
61
+ /** @internal */
51
62
  body: string;
63
+ /** @internal */
52
64
  discussionId?: string;
65
+ /** @internal */
53
66
  signal?: AbortSignal;
54
- }): Promise<{ marker: string }> {
67
+ }): Promise<{
68
+ /** @internal */
69
+ marker: string;
70
+ }> {
55
71
  const { client, writes, instanceId, projectId, iid, writeKey, signal } = input;
56
72
  const identity = [client.baseUrl, projectId, iid, instanceId, writeKey];
57
73
  if (input.discussionId) identity.push(input.discussionId);
@@ -63,52 +79,62 @@ export async function ensureGitLabComment(input: {
63
79
  : await client.listNotes(projectId, iid, signal);
64
80
  return notes.find((note) => note.body.includes(marker));
65
81
  };
66
- await ensureWrite(writes, instanceId, createWriteIdentity("gitlab.comment", digest), async () => {
67
- const note = await findOrCreate(find, () => {
68
- const body = `${input.body}\n\n${marker}`;
69
- return input.discussionId
70
- ? client.replyToDiscussion(projectId, iid, input.discussionId, body, signal)
71
- : client.addNote(projectId, iid, body, signal);
72
- });
73
- return { projectId, iid, noteId: note.id, marker };
74
- });
82
+ await writes.ensure(
83
+ { writeType: "gitlab.comment", dedupKey: digest },
84
+ {
85
+ reconcile: () => existingRemote(async () => (await find()) ?? null),
86
+ execute: () => {
87
+ const body = `${input.body}\n\n${marker}`;
88
+ return input.discussionId
89
+ ? client.replyToDiscussion(projectId, iid, input.discussionId, body, signal)
90
+ : client.addNote(projectId, iid, body, signal);
91
+ },
92
+ toMetadata: (note) => ({ projectId, iid, noteId: note.id, marker }),
93
+ },
94
+ );
75
95
  return { marker };
76
96
  }
97
+ /** @public */
77
98
  export async function ensureGitLabSeenReaction(input: {
99
+ /** @public */
78
100
  client: GitLabClientLike;
79
- writes: ExternalWriteLogRepoLike;
101
+ /** @public */
102
+ writes: ExternalWrites;
103
+ /** @public */
80
104
  instanceId: string;
105
+ /** @public */
81
106
  projectId: number;
107
+ /** @public */
82
108
  iid: number;
109
+ /** @public */
83
110
  noteId: number;
111
+ /** @public */
84
112
  signal?: AbortSignal;
85
113
  }): Promise<void> {
86
114
  const { client, writes, instanceId, projectId, iid, noteId, signal } = input;
87
115
  const digest = createHash("sha256")
88
116
  .update(JSON.stringify([client.baseUrl, projectId, iid, instanceId, "eyes", noteId]))
89
117
  .digest("hex");
90
- await ensureWrite(
91
- writes,
92
- instanceId,
93
- createWriteIdentity("gitlab.reaction", digest),
94
- async () => {
95
- const identity = await client.resolveGitIdentity(signal);
96
- const find = async () =>
97
- (await client.listNoteReactions(projectId, iid, noteId, signal)).find(
98
- (reaction) => reaction.name === "eyes" && reaction.user.username === identity.username,
99
- );
100
- const reaction = await findOrCreate(find, () =>
101
- client.addNoteReaction(projectId, iid, noteId, "eyes", signal),
102
- );
103
- return { projectId, iid, noteId, reactionId: reaction.id, name: "eyes" };
118
+ await writes.ensure(
119
+ { writeType: "gitlab.reaction", dedupKey: digest },
120
+ {
121
+ reconcile: () =>
122
+ existingRemote(async () => {
123
+ const identity = await client.resolveGitIdentity(signal);
124
+ return (
125
+ (await client.listNoteReactions(projectId, iid, noteId, signal)).find(
126
+ (reaction) =>
127
+ reaction.name === "eyes" && reaction.user.username === identity.username,
128
+ ) ?? null
129
+ );
130
+ }),
131
+ execute: () => client.addNoteReaction(projectId, iid, noteId, "eyes", signal),
132
+ toMetadata: (reaction) => ({ projectId, iid, noteId, reactionId: reaction.id, name: "eyes" }),
104
133
  },
105
134
  );
106
135
  }
107
- export function registerGitLabTools(
108
- api: ServerExtensionAPI,
109
- integration: GitLabIntegration,
110
- writes: ExternalWriteLogRepoLike,
111
- ) {
136
+ /** @internal */
137
+ export function registerGitLabTools(api: ServerExtensionAPI, integration: GitLabIntegration) {
112
138
  for (const [name, description, required] of [
113
139
  ["gitlab_observe_merge_request", "Read the current MR source revision and its latest CI", []],
114
140
  ["gitlab_get_changes", "Read the MR changes", []],
@@ -150,7 +176,7 @@ export function registerGitLabTools(
150
176
  if (name === "gitlab_comment" || name === "gitlab_reply")
151
177
  return ensureGitLabComment({
152
178
  client,
153
- writes,
179
+ writes: ctx.externalWrites,
154
180
  instanceId: ctx.process.id,
155
181
  projectId: b.projectId,
156
182
  iid: b.iid,
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/capability.ts","../src/client.ts","../src/external.ts","../src/tools.ts","../src/selection.ts"],"sourcesContent":["import type { ExternalWriteLogRepoLike } from \"@leitwerk-dev/external-writes\";\nimport {\n\tcoreHostCapabilities,\n\ttype LeitwerkExtensionModule,\n\ttype ServerExtensionAPI,\n} from \"@leitwerk-dev/process-sdk\";\nimport { type GitLabIntegration, gitlabIntegration } from \"./capability.js\";\nimport { GitLabClient, parseGitLabProfiles } from \"./client.js\";\nimport { createGitLabProvider } from \"./external.js\";\nimport { registerGitLabTools } from \"./tools.js\";\nexport const manifest = { id: \"gitlab\", version: \"0.1.9\" } as const;\nexport function setupGitLabIntegration(\n\tapi: ServerExtensionAPI,\n\tintegration: GitLabIntegration,\n\toptions: { now?: () => number } = {},\n) {\n\tapi.provide(gitlabIntegration, integration);\n\tconst deps = api.get(coreHostCapabilities.serverSetup);\n\tif (!deps || Array.isArray(deps)) return;\n\tregisterGitLabTools(api, integration, deps.externalWrites as ExternalWriteLogRepoLike);\n\treturn createGitLabProvider(deps, integration, options);\n}\nconst extension: LeitwerkExtensionModule = {\n\tmanifest,\n\tsetupServer(api, config) {\n\t\tconst profiles = parseGitLabProfiles(config);\n\t\tconst clients = new Map([...profiles].map(([id, profile]) => [id, new GitLabClient(profile)]));\n\t\tsetupGitLabIntegration(api, {\n\t\t\tprofiles: () => [...profiles.keys()],\n\t\t\tclient: (profile) => {\n\t\t\t\tconst client = clients.get(profile);\n\t\t\t\tif (!client) throw new Error(`Unknown GitLab profile '${profile}'`);\n\t\t\t\treturn client;\n\t\t\t},\n\t\t});\n\t\tconst deps = api.get(coreHostCapabilities.serverSetup);\n\t\tif (!deps || Array.isArray(deps)) return;\n\t\tdeps.repositoryCredentials.register({\n\t\t\tkind: \"git_https\",\n\t\t\tresolve(ref) {\n\t\t\t\tconst profile = ref.startsWith(\"gitlab:\") ? profiles.get(ref.slice(7)) : undefined;\n\t\t\t\treturn profile\n\t\t\t\t\t? { origin: profile.baseUrl, username: \"oauth2\", password: profile.token }\n\t\t\t\t\t: null;\n\t\t\t},\n\t\t});\n\t},\n};\nexport default extension;\nexport * from \"./capability.js\";\nexport * from \"./client.js\";\nexport * from \"./external.js\";\nexport * from \"./selection.js\";\nexport * from \"./tools.js\";\n","import {\n\tcreateCapabilityToken,\n\ttype RepositoryCredentialProject,\n\ttype RepositoryCredentialRequirement,\n} from \"@leitwerk-dev/process-sdk\";\nimport type { GitLabClientLike } from \"./client.js\";\nexport interface GitLabIntegration {\n\tprofiles(): readonly string[];\n\tclient(profile: string): GitLabClientLike;\n}\nexport const gitlabIntegration = createCapabilityToken<GitLabIntegration>(\n\t\"@leitwerk-dev/gitlab.integration\",\n);\n/** Internal references are derived from the same profile as API access. */\nexport function gitlabRepositoryCredentials(\n\tprofile: string,\n\tprojects: readonly RepositoryCredentialProject[],\n): RepositoryCredentialRequirement[] {\n\treturn projects.map((project) => ({\n\t\tprojectKey: project.key,\n\t\tkind: \"git_https\",\n\t\tcredentialRef: `gitlab:${profile}`,\n\t}));\n}\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\nimport { repositoryHttpsUrl } from \"@leitwerk-dev/process-sdk\";\n\nexport interface GitLabProfile {\n\tbaseUrl: string;\n\ttoken: string;\n\tgitIdentity?: { name: string; email: string };\n}\nexport interface GitLabProject {\n\tid: number;\n\tpath_with_namespace: string;\n\thttp_url_to_repo: string;\n\tweb_url: string;\n\tdefault_branch: string;\n\tarchived?: boolean;\n\tpermissions?: {\n\t\tproject_access?: { access_level: number } | null;\n\t\tgroup_access?: { access_level: number } | null;\n\t};\n}\nexport interface GitLabGroup {\n\tid: number;\n\tfull_path: string;\n}\nexport interface GitLabMergeRequest {\n\tiid: number;\n\tproject_id: number;\n\tsource_project_id: number;\n\ttarget_project_id: number;\n\ttitle: string;\n\tdescription: string | null;\n\tstate: string;\n\tlabels: string[];\n\tsha: string;\n\tsource_branch: string;\n\ttarget_branch: string;\n\tweb_url: string;\n\tmerge_commit_sha?: string | null;\n\tdiff_refs?: { base_sha: string; head_sha: string; start_sha: string };\n}\nexport interface GitLabCommit {\n\tid: string;\n\tparent_ids: string[];\n\tmessage: string;\n\tweb_url?: string;\n}\nexport interface GitLabBranch {\n\tname: string;\n\tcan_push: boolean;\n\tprotected: boolean;\n\tcommit: GitLabCommit;\n}\nexport interface GitLabPipeline {\n\tid: number;\n\tproject_id: number;\n\tsha: string;\n\tref: string;\n\tstatus: string;\n\tsource?: string;\n\tweb_url: string;\n}\nexport interface GitLabJob {\n\tid: number;\n\tname: string;\n\tstatus: string;\n\tweb_url: string;\n\tfailure_reason?: string;\n}\nexport interface GitLabDiff {\n\told_path: string;\n\tnew_path: string;\n\tdiff: string;\n\tnew_file: boolean;\n\tdeleted_file: boolean;\n\trenamed_file: boolean;\n}\nexport interface GitLabNote {\n\tid: number;\n\tbody: string;\n}\nexport interface GitLabNoteReaction {\n\tid: number;\n\tname: string;\n\tuser: { username: string };\n}\nexport interface GitLabFeedback {\n\tid: number;\n\tdiscussionId: string;\n\tbody: string;\n\tauthor: string;\n\tcreatedAt: string;\n\tpath?: string;\n\tline?: number;\n}\nexport interface GitLabDiscussion {\n\tid: string;\n\tnotes: (GitLabNote & {\n\t\tsystem: boolean;\n\t\tcreated_at: string;\n\t\tauthor: { username: string; bot?: boolean };\n\t\tresolved?: boolean;\n\t\tposition?: { new_path?: string; old_path?: string; new_line?: number; old_line?: number };\n\t})[];\n}\nexport interface GitLabIdentity {\n\tname: string;\n\temail: string;\n\tusername: string;\n}\nexport interface GitLabObservation {\n\tmr: GitLabMergeRequest;\n\tpipeline: GitLabPipeline | null;\n}\n\nexport class GitLabError extends Error {\n\tconstructor(\n\t\treadonly status: number,\n\t\treadonly retryable: boolean,\n\t) {\n\t\tsuper(\n\t\t\t`GitLab request failed (${status || \"network unavailable\"})${retryable ? \"; retryable\" : \"; check profile and project access\"}`,\n\t\t);\n\t}\n}\nexport function parseGitLabProfiles(raw: unknown): Map<string, GitLabProfile> {\n\tconst profiles = new Map<string, GitLabProfile>();\n\tfor (const [name, value] of Object.entries(\n\t\tasUnknownRecord(asUnknownRecord(raw)?.profiles) ?? {},\n\t)) {\n\t\tconst item = asUnknownRecord(value) ?? {};\n\t\tconst baseUrl = typeof item.base_url === \"string\" ? item.base_url.replace(/\\/+$/, \"\") : \"\";\n\t\tconst url = repositoryHttpsUrl(`${baseUrl}/` === \"/\" ? \"\" : `${baseUrl}/repository`);\n\t\tif (url.origin !== baseUrl)\n\t\t\tthrow new Error(`GitLab profile '${name}' requires an HTTPS origin base_url`);\n\t\tconst configuredToken = typeof item.token === \"string\" ? item.token : \"\";\n\t\tconst token = configuredToken.startsWith(\"env:\")\n\t\t\t? (process.env[configuredToken.slice(4)] ?? \"\")\n\t\t\t: configuredToken;\n\t\tif (!token || /[\\r\\n\\0]/.test(token))\n\t\t\tthrow new Error(`GitLab profile '${name}' requires a token`);\n\t\tconst identity = asUnknownRecord(item.git_identity);\n\t\tif (\n\t\t\tidentity &&\n\t\t\t[identity.name, identity.email].some(\n\t\t\t\t(v) => typeof v !== \"string\" || !v.trim() || /[\\r\\n<>]/.test(v),\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`GitLab profile '${name}' requires a valid git_identity name and email`);\n\t\tprofiles.set(name, {\n\t\t\tbaseUrl,\n\t\t\ttoken,\n\t\t\t...(identity\n\t\t\t\t? { gitIdentity: { name: String(identity.name), email: String(identity.email) } }\n\t\t\t\t: {}),\n\t\t});\n\t}\n\treturn profiles;\n}\nconst projectPath = (id: number | string) => `/projects/${encodeURIComponent(id)}`;\nconst mrPath = (id: number, iid: number) => `${projectPath(id)}/merge_requests/${iid}`;\n\n/** GitLab v4 API. Errors deliberately omit response bodies, headers and tokens. */\nexport class GitLabClient {\n\treadonly baseUrl: string;\n\treadonly #profile: GitLabProfile;\n\treadonly #fetch: typeof fetch;\n\treadonly #sleep: (ms: number) => Promise<unknown>;\n\tconstructor(\n\t\tprofile: GitLabProfile,\n\t\toptions: { fetch?: typeof fetch; sleep?: (ms: number) => Promise<unknown> } = {},\n\t) {\n\t\tif (repositoryHttpsUrl(`${profile.baseUrl}/repository`).origin !== profile.baseUrl)\n\t\t\tthrow new Error(\"GitLab requires an HTTPS origin baseUrl\");\n\t\tif (!profile.token || /[\\r\\n\\0]/.test(profile.token))\n\t\t\tthrow new Error(\"GitLab requires a valid token\");\n\t\tthis.#profile = profile;\n\t\tthis.baseUrl = profile.baseUrl;\n\t\tthis.#fetch = options.fetch ?? fetch;\n\t\tthis.#sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));\n\t}\n\tprivate async response(path: string, signal?: AbortSignal, body?: unknown): Promise<Response> {\n\t\tfor (let attempt = 0; ; attempt++) {\n\t\t\tlet response: Response;\n\t\t\ttry {\n\t\t\t\tresponse = await this.#fetch(`${this.baseUrl}/api/v4${path}`, {\n\t\t\t\t\tmethod: body === undefined ? \"GET\" : \"POST\",\n\t\t\t\t\tredirect: \"error\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"PRIVATE-TOKEN\": this.#profile.token,\n\t\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t\t\t...(body === undefined ? {} : { \"Content-Type\": \"application/json\" }),\n\t\t\t\t\t},\n\t\t\t\t\tsignal: signal\n\t\t\t\t\t\t? AbortSignal.any([signal, AbortSignal.timeout(30_000)])\n\t\t\t\t\t\t: AbortSignal.timeout(30_000),\n\t\t\t\t\t...(body === undefined ? {} : { body: JSON.stringify(body) }),\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\tif (signal?.aborted) throw new GitLabError(0, true);\n\t\t\t\tif (body !== undefined || attempt >= 2) throw new GitLabError(0, true);\n\t\t\t\tawait this.#sleep(1_000 * 2 ** attempt);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (response.ok) return response;\n\t\t\tconst retryable =\n\t\t\t\tresponse.status === 429 || response.status >= 500 || response.status === 408;\n\t\t\tawait response.body?.cancel();\n\t\t\tif (!retryable || body !== undefined || attempt >= 2)\n\t\t\t\tthrow new GitLabError(response.status, retryable);\n\t\t\tconst seconds = Number(response.headers.get(\"retry-after\"));\n\t\t\tawait this.#sleep(Math.min(30_000, seconds > 0 ? seconds * 1_000 : 1_000 * 2 ** attempt));\n\t\t}\n\t}\n\tprivate async request<T>(path: string, signal?: AbortSignal, body?: unknown): Promise<T> {\n\t\treturn this.json<T>(await this.response(path, signal, body));\n\t}\n\tprivate async json<T>(response: Response): Promise<T> {\n\t\ttry {\n\t\t\treturn (await response.json()) as T;\n\t\t} catch {\n\t\t\tthrow new GitLabError(502, true);\n\t\t}\n\t}\n\tprivate async pages<T>(path: string, signal?: AbortSignal): Promise<T[]> {\n\t\tconst rows: T[] = [];\n\t\tlet page = 1;\n\t\tfor (let n = 0; n < 10_000; n++) {\n\t\t\tconst response = await this.response(\n\t\t\t\t`${path}${path.includes(\"?\") ? \"&\" : \"?\"}per_page=100&page=${page}`,\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tconst batch = await this.json<T[]>(response);\n\t\t\tif (!Array.isArray(batch)) throw new Error(\"Invalid GitLab list response\");\n\t\t\trows.push(...batch);\n\t\t\tconst next = response.headers.get(\"x-next-page\");\n\t\t\tif (next === \"\" || (next === null && batch.length < 100)) return rows;\n\t\t\tconst nextPage = next === null ? page + 1 : Number(next);\n\t\t\tif (!Number.isInteger(nextPage) || nextPage <= page)\n\t\t\t\tthrow new Error(\"Invalid GitLab pagination\");\n\t\t\tpage = nextPage;\n\t\t}\n\t\tthrow new Error(\"GitLab pagination limit exceeded; discovery incomplete\");\n\t}\n\tgetProject(id: number | string, signal?: AbortSignal): Promise<GitLabProject> {\n\t\treturn this.request(projectPath(id), signal);\n\t}\n\tlistProjects(signal?: AbortSignal): Promise<GitLabProject[]> {\n\t\treturn this.pages(\"/projects?archived=false\", signal);\n\t}\n\tgetGroup(id: number | string, signal?: AbortSignal): Promise<GitLabGroup> {\n\t\treturn this.request(`/groups/${encodeURIComponent(id)}`, signal);\n\t}\n\tlistGroupProjects(id: number | string, signal?: AbortSignal): Promise<GitLabProject[]> {\n\t\treturn this.pages(\n\t\t\t`/groups/${encodeURIComponent(id)}/projects?include_subgroups=true&with_shared=false&archived=false`,\n\t\t\tsignal,\n\t\t);\n\t}\n\tlistMergeRequests(\n\t\tid: number,\n\t\tlabel: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabMergeRequest[]> {\n\t\treturn this.pages(\n\t\t\t`${projectPath(id)}/merge_requests?state=opened&labels=${encodeURIComponent(label)}`,\n\t\t\tsignal,\n\t\t);\n\t}\n\tgetMergeRequest(id: number, iid: number, signal?: AbortSignal): Promise<GitLabMergeRequest> {\n\t\treturn this.request(mrPath(id, iid), signal);\n\t}\n\tgetChanges(id: number, iid: number, signal?: AbortSignal): Promise<GitLabDiff[]> {\n\t\treturn this.pages(`${mrPath(id, iid)}/diffs`, signal);\n\t}\n\tgetBranch(id: number, branch: string, signal?: AbortSignal): Promise<GitLabBranch> {\n\t\treturn this.request(\n\t\t\t`${projectPath(id)}/repository/branches/${encodeURIComponent(branch)}`,\n\t\t\tsignal,\n\t\t);\n\t}\n\tgetCommit(id: number, sha: string, signal?: AbortSignal): Promise<GitLabCommit> {\n\t\treturn this.request(`${projectPath(id)}/repository/commits/${encodeURIComponent(sha)}`, signal);\n\t}\n\tlistMergeRequestPipelines(\n\t\tid: number,\n\t\tiid: number,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabPipeline[]> {\n\t\treturn this.pages(`${mrPath(id, iid)}/pipelines`, signal);\n\t}\n\tlistBranchPipelines(\n\t\tid: number,\n\t\tbranch: string,\n\t\tsha: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabPipeline[]> {\n\t\treturn this.pages(\n\t\t\t`${projectPath(id)}/pipelines?ref=${encodeURIComponent(branch)}&sha=${encodeURIComponent(sha)}&source=push`,\n\t\t\tsignal,\n\t\t);\n\t}\n\tgetPipeline(id: number, pipeline: number, signal?: AbortSignal): Promise<GitLabPipeline> {\n\t\treturn this.request(`${projectPath(id)}/pipelines/${pipeline}`, signal);\n\t}\n\tlistFailedJobs(id: number, pipeline: number, signal?: AbortSignal): Promise<GitLabJob[]> {\n\t\treturn this.pages(\n\t\t\t`${projectPath(id)}/pipelines/${pipeline}/jobs?scope[]=failed&include_retried=false`,\n\t\t\tsignal,\n\t\t);\n\t}\n\tlistNotes(id: number, iid: number, signal?: AbortSignal): Promise<GitLabNote[]> {\n\t\treturn this.pages(`${mrPath(id, iid)}/notes`, signal);\n\t}\n\tgetDiscussion(\n\t\tid: number,\n\t\tiid: number,\n\t\tdiscussionId: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabDiscussion> {\n\t\treturn this.request(\n\t\t\t`${mrPath(id, iid)}/discussions/${encodeURIComponent(discussionId)}`,\n\t\t\tsignal,\n\t\t);\n\t}\n\treplyToDiscussion(\n\t\tid: number,\n\t\tiid: number,\n\t\tdiscussionId: string,\n\t\tbody: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabNote> {\n\t\treturn this.request(\n\t\t\t`${mrPath(id, iid)}/discussions/${encodeURIComponent(discussionId)}/notes`,\n\t\t\tsignal,\n\t\t\t{ body },\n\t\t);\n\t}\n\tlistNoteReactions(\n\t\tid: number,\n\t\tiid: number,\n\t\tnoteId: number,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabNoteReaction[]> {\n\t\treturn this.pages(`${mrPath(id, iid)}/notes/${noteId}/award_emoji`, signal);\n\t}\n\taddNoteReaction(\n\t\tid: number,\n\t\tiid: number,\n\t\tnoteId: number,\n\t\tname: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabNoteReaction> {\n\t\treturn this.request(`${mrPath(id, iid)}/notes/${noteId}/award_emoji`, signal, { name });\n\t}\n\tasync listMergeRequestFeedback(\n\t\tid: number,\n\t\tiid: number,\n\t\tsignal?: AbortSignal,\n\t): Promise<GitLabFeedback[]> {\n\t\tconst [discussions, identity] = await Promise.all([\n\t\t\tthis.pages<GitLabDiscussion>(`${mrPath(id, iid)}/discussions`, signal),\n\t\t\tthis.resolveGitIdentity(signal),\n\t\t]);\n\t\tconst feedback: GitLabFeedback[] = [];\n\t\tfor (const discussion of discussions) {\n\t\t\tfor (const note of discussion.notes) {\n\t\t\t\tif (\n\t\t\t\t\tnote.system ||\n\t\t\t\t\tnote.resolved ||\n\t\t\t\t\tnote.author.bot ||\n\t\t\t\t\tnote.author.username === identity.username ||\n\t\t\t\t\t!note.body.trim() ||\n\t\t\t\t\t!Number.isFinite(Date.parse(note.created_at))\n\t\t\t\t)\n\t\t\t\t\tcontinue;\n\t\t\t\tconst position = note.position ?? discussion.notes[0]?.position;\n\t\t\t\tfeedback.push({\n\t\t\t\t\tid: note.id,\n\t\t\t\t\tdiscussionId: discussion.id,\n\t\t\t\t\tbody: note.body,\n\t\t\t\t\tauthor: note.author.username,\n\t\t\t\t\tcreatedAt: note.created_at,\n\t\t\t\t\t...(position\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpath: position.new_path ?? position.old_path,\n\t\t\t\t\t\t\t\tline: position.new_line ?? position.old_line,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn feedback.sort((a, b) => a.id - b.id);\n\t}\n\taddNote(id: number, iid: number, body: string, signal?: AbortSignal): Promise<GitLabNote> {\n\t\treturn this.request(`${mrPath(id, iid)}/notes`, signal, { body });\n\t}\n\tasync resolveGitIdentity(signal?: AbortSignal): Promise<GitLabIdentity> {\n\t\tconst user = await this.request<{\n\t\t\tname?: string;\n\t\t\tusername?: string;\n\t\t\temail?: string;\n\t\t\tcommit_email?: string;\n\t\t}>(\"/user\", signal);\n\t\tconst name = this.#profile.gitIdentity?.name ?? user.name;\n\t\tconst email = this.#profile.gitIdentity?.email ?? user.commit_email ?? user.email;\n\t\tif (!user.username || !name?.trim() || !email?.includes(\"@\") || /[\\r\\n<>]/.test(name + email))\n\t\t\tthrow new Error(\n\t\t\t\t\"GitLab bot Git identity is unavailable; configure git_identity on the profile\",\n\t\t\t);\n\t\treturn { name, email, username: user.username };\n\t}\n\tasync getJobTrace(\n\t\tid: number,\n\t\tjob: number,\n\t\tmaxBytes = 65_536,\n\t\tsignal?: AbortSignal,\n\t): Promise<{ text: string; truncated: boolean }> {\n\t\tconst limit = Math.min(262_144, Math.max(1, Math.floor(maxBytes) || 65_536));\n\t\tconst response = await this.response(`${projectPath(id)}/jobs/${job}/trace`, signal);\n\t\tconst reader = response.body?.getReader();\n\t\tif (!reader) return { text: \"\", truncated: false };\n\t\tconst chunks: Uint8Array[] = [];\n\t\tlet size = 0;\n\t\tlet truncated = false;\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst item = await reader.read();\n\t\t\t\tif (item.done) break;\n\t\t\t\tconst take = Math.min(item.value.length, limit - size);\n\t\t\t\tchunks.push(item.value.slice(0, take));\n\t\t\t\tsize += take;\n\t\t\t\tif (size >= limit) {\n\t\t\t\t\ttruncated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tawait reader.cancel();\n\t\t}\n\t\treturn { text: Buffer.concat(chunks).toString(\"utf8\"), truncated };\n\t}\n}\nexport type GitLabClientLike = Pick<GitLabClient, keyof GitLabClient>;\n\n/** A pending current pipeline supersedes every older result. Synthetic merges must contain this source head. */\nexport async function observeMergeRequest(\n\tclient: GitLabClientLike,\n\tprojectId: number,\n\tiid: number,\n\tsignal?: AbortSignal,\n): Promise<GitLabObservation> {\n\tconst mr = await client.getMergeRequest(projectId, iid, signal);\n\tif (mr.state !== \"opened\") return { mr, pipeline: null };\n\tconst associated = (await client.listMergeRequestPipelines(projectId, iid, signal)).sort(\n\t\t(a, b) => b.id - a.id,\n\t);\n\tfor (const candidate of associated) {\n\t\tconst id = candidate.project_id ?? projectId;\n\t\tlet matches = candidate.sha === mr.sha;\n\t\tif (\n\t\t\t!matches &&\n\t\t\t(candidate.ref === `refs/merge-requests/${iid}/merge` ||\n\t\t\t\tcandidate.sha === mr.merge_commit_sha)\n\t\t) {\n\t\t\tconst commit = await client.getCommit(id, candidate.sha, signal);\n\t\t\tmatches = commit.parent_ids.includes(mr.sha);\n\t\t}\n\t\tif (matches) return { mr, pipeline: await client.getPipeline(id, candidate.id, signal) };\n\t}\n\tconst candidates = await client.listBranchPipelines(\n\t\tmr.source_project_id,\n\t\tmr.source_branch,\n\t\tmr.sha,\n\t\tsignal,\n\t);\n\tconst latest = candidates\n\t\t.filter((p) => p.sha === mr.sha && p.ref === mr.source_branch && p.source === \"push\")\n\t\t.sort((a, b) => b.id - a.id)[0];\n\treturn {\n\t\tmr,\n\t\tpipeline: latest ? await client.getPipeline(mr.source_project_id, latest.id, signal) : null,\n\t};\n}\n","import {\n\ttype CoreServerSetupDeps,\n\tcreateExternalSourcePollReporter,\n\ttype ExternalActionSource,\n} from \"@leitwerk-dev/process-sdk\";\nimport { emptyPollResult, parseDurationMs } from \"@leitwerk-dev/watcher-utils\";\nimport type { GitLabIntegration } from \"./capability.js\";\nimport { type GitLabFeedback, type GitLabObservation, observeMergeRequest } from \"./client.js\";\nexport const GITLAB_MR_KIND = \"@leitwerk-dev/gitlab.merge-request\";\nexport interface GitLabSourceConfig {\n\tprofile: string;\n\tprojectId: number;\n\tiid: number;\n\tpollInterval?: string;\n\tafterKey?: string;\n\t/** Optional timer also wakes retry work when GitLab facts have not changed. */\n\twakeAt?: number;\n\tfeedback?: { afterId: number; since?: string; quietPeriodMs: number };\n}\n/** A trailing quiet period survives restarts because it uses the newest unseen note's timestamp. */\nexport function pendingGitLabFeedback(\n\titems: GitLabFeedback[],\n\tafterId: number,\n\tsince?: string,\n): GitLabFeedback[] {\n\tconst start = since ? Date.parse(since) : 0;\n\treturn items.filter((item) => item.id > afterId && Date.parse(item.createdAt) >= start);\n}\nexport function gitLabFeedbackReadyAt(\n\titems: GitLabFeedback[],\n\tquietPeriodMs: number,\n): number | null {\n\treturn items.length\n\t\t? Math.max(...items.map((item) => Date.parse(item.createdAt))) + quietPeriodMs\n\t\t: null;\n}\nexport const observationKey = ({ mr, pipeline }: GitLabObservation): string =>\n\tJSON.stringify([\n\t\tmr.state,\n\t\tmr.sha,\n\t\t[...mr.labels].sort(),\n\t\tpipeline?.project_id,\n\t\tpipeline?.id,\n\t\tpipeline?.status,\n\t]);\nexport const gitlabExternal = {\n\tmergeRequest<P, S>(\n\t\tresolve: (ctx: { params: P; state: S }) => GitLabSourceConfig,\n\t): ExternalActionSource<P, S, GitLabObservation> {\n\t\treturn {\n\t\t\tkind: GITLAB_MR_KIND,\n\t\t\tlabel: \"GitLab merge request\",\n\t\t\tdescription: \"Observe MR state, current source head and revision-correlated CI\",\n\t\t\tconfig: {},\n\t\t\tinputMode: \"none\",\n\t\t\tresolve,\n\t\t};\n\t},\n};\nexport function createGitLabProvider(\n\tdeps: CoreServerSetupDeps,\n\tintegration: GitLabIntegration,\n\toptions: { now?: () => number } = {},\n) {\n\tconst schedule = new Map<string, { at: number; failures: number }>();\n\tconst now = options.now ?? Date.now;\n\treturn deps.polling.create({\n\t\tid: \"gitlab\",\n\t\tpollInterval: () => \"5s\",\n\t\tisEnabled: () => true,\n\t\tdefaultIntervalMs: 5000,\n\t\tasync pollOnce() {\n\t\t\tconst result = emptyPollResult();\n\t\t\tconst report = createExternalSourcePollReporter(deps.externalSources, result);\n\t\t\tawait report.poll(GITLAB_MR_KIND, async (armed) => {\n\t\t\t\tconst c = armed.resolved as unknown as GitLabSourceConfig;\n\t\t\t\tif (\n\t\t\t\t\t!c ||\n\t\t\t\t\ttypeof c.profile !== \"string\" ||\n\t\t\t\t\t!Number.isInteger(c.projectId) ||\n\t\t\t\t\t!Number.isInteger(c.iid)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid GitLab external source\");\n\t\t\t\tconst key = `${armed.instanceId}:${armed.id}:${armed.generation ?? \"\"}`;\n\t\t\t\tconst previous = schedule.get(key);\n\t\t\t\tif (previous && previous.at > now()) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst observation = await observeMergeRequest(\n\t\t\t\t\t\tintegration.client(c.profile),\n\t\t\t\t\t\tc.projectId,\n\t\t\t\t\t\tc.iid,\n\t\t\t\t\t);\n\t\t\t\t\tconst observedKey = observationKey(observation);\n\t\t\t\t\tconst feedback =\n\t\t\t\t\t\tc.feedback && observation.mr.state === \"opened\"\n\t\t\t\t\t\t\t? pendingGitLabFeedback(\n\t\t\t\t\t\t\t\t\tawait integration.client(c.profile).listMergeRequestFeedback(c.projectId, c.iid),\n\t\t\t\t\t\t\t\t\tc.feedback.afterId,\n\t\t\t\t\t\t\t\t\tc.feedback.since,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: [];\n\t\t\t\t\tconst feedbackReadyAt = gitLabFeedbackReadyAt(\n\t\t\t\t\t\tfeedback,\n\t\t\t\t\t\tc.feedback?.quietPeriodMs ?? 120_000,\n\t\t\t\t\t);\n\t\t\t\t\tconst feedbackReady = feedbackReadyAt !== null && feedbackReadyAt <= now();\n\t\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\t\tobservation: {\n\t\t\t\t\t\t\tsummary: `${observation.mr.state} · ${observation.pipeline?.status ?? \"no current pipeline\"}`,\n\t\t\t\t\t\t\tobservedAt: new Date(now()).toISOString(),\n\t\t\t\t\t\t\tsubject: observation.mr.web_url,\n\t\t\t\t\t\t\trevision: observation.mr.sha,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tif (\n\t\t\t\t\t\tobservedKey !== c.afterKey ||\n\t\t\t\t\t\tfeedbackReady ||\n\t\t\t\t\t\t(c.wakeAt !== undefined && c.wakeAt <= now())\n\t\t\t\t\t)\n\t\t\t\t\t\tawait report.fire(\n\t\t\t\t\t\t\tarmed,\n\t\t\t\t\t\t\t{ ...observation },\n\t\t\t\t\t\t\t`${observedKey}:${c.wakeAt ?? \"\"}:${feedbackReady ? feedback.map((item) => item.id).join(\",\") : \"\"}`,\n\t\t\t\t\t\t);\n\t\t\t\t\tschedule.set(key, {\n\t\t\t\t\t\tat: now() + parseDurationMs(c.pollInterval ?? \"30s\", 30000),\n\t\t\t\t\t\tfailures: 0,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst failures = (previous?.failures ?? 0) + 1;\n\t\t\t\t\tschedule.set(key, {\n\t\t\t\t\t\tat: now() + Math.min(300000, 30000 * 2 ** Math.min(failures - 1, 4)),\n\t\t\t\t\t\tfailures,\n\t\t\t\t\t});\n\t\t\t\t\tawait report.observe(armed, {\n\t\t\t\t\t\trefreshError: error instanceof Error ? error.message : \"GitLab observation unavailable\",\n\t\t\t\t\t});\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn result;\n\t\t},\n\t});\n}\n","import { createHash } from \"node:crypto\";\nimport {\n\tcreateWriteIdentity,\n\ttype ExternalWriteLogRepoLike,\n\tensureWrite,\n} from \"@leitwerk-dev/external-writes\";\nimport {\n\ttype IntegrationToolExecutionContext,\n\tnumberArg,\n\tprojectParameters,\n\ttype ServerExtensionAPI,\n\tstringArg,\n} from \"@leitwerk-dev/process-sdk\";\nimport type { GitLabIntegration } from \"./capability.js\";\nimport { type GitLabClientLike, observeMergeRequest } from \"./client.js\";\nexport function resolveGitLabBinding(\n\tctx: Pick<IntegrationToolExecutionContext, \"project\" | \"process\">,\n): { profile: string; projectId: number; iid: number } {\n\tif (!ctx.project || ctx.project.instanceId !== ctx.process.id)\n\t\tthrow new Error(\"An authorized GitLab process project is required\");\n\tconst binding = ctx.project.metadata?.gitlab as\n\t\t| { profile?: unknown; projectId?: unknown; iid?: unknown }\n\t\t| undefined;\n\tif (\n\t\t!binding ||\n\t\ttypeof binding.profile !== \"string\" ||\n\t\ttypeof binding.projectId !== \"number\" ||\n\t\ttypeof binding.iid !== \"number\"\n\t)\n\t\tthrow new Error(\"Invalid GitLab project binding\");\n\treturn { profile: binding.profile, projectId: binding.projectId, iid: binding.iid };\n}\nasync function findOrCreate<T>(find: () => Promise<T | undefined>, create: () => Promise<T>) {\n\tconst existing = await find();\n\tif (existing) return existing;\n\ttry {\n\t\treturn await create();\n\t} catch (error) {\n\t\tconst recovered = await find();\n\t\tif (!recovered) throw error;\n\t\treturn recovered;\n\t}\n}\nexport async function ensureGitLabComment(input: {\n\tclient: GitLabClientLike;\n\twrites: ExternalWriteLogRepoLike;\n\tinstanceId: string;\n\tprojectId: number;\n\tiid: number;\n\twriteKey: string;\n\tbody: string;\n\tdiscussionId?: string;\n\tsignal?: AbortSignal;\n}): Promise<{ marker: string }> {\n\tconst { client, writes, instanceId, projectId, iid, writeKey, signal } = input;\n\tconst identity = [client.baseUrl, projectId, iid, instanceId, writeKey];\n\tif (input.discussionId) identity.push(input.discussionId);\n\tconst digest = createHash(\"sha256\").update(JSON.stringify(identity)).digest(\"hex\");\n\tconst marker = `<!-- leitwerk:gitlab:${digest} -->`;\n\tconst find = async () => {\n\t\tconst notes = input.discussionId\n\t\t\t? (await client.getDiscussion(projectId, iid, input.discussionId, signal)).notes\n\t\t\t: await client.listNotes(projectId, iid, signal);\n\t\treturn notes.find((note) => note.body.includes(marker));\n\t};\n\tawait ensureWrite(writes, instanceId, createWriteIdentity(\"gitlab.comment\", digest), async () => {\n\t\tconst note = await findOrCreate(find, () => {\n\t\t\tconst body = `${input.body}\\n\\n${marker}`;\n\t\t\treturn input.discussionId\n\t\t\t\t? client.replyToDiscussion(projectId, iid, input.discussionId, body, signal)\n\t\t\t\t: client.addNote(projectId, iid, body, signal);\n\t\t});\n\t\treturn { projectId, iid, noteId: note.id, marker };\n\t});\n\treturn { marker };\n}\nexport async function ensureGitLabSeenReaction(input: {\n\tclient: GitLabClientLike;\n\twrites: ExternalWriteLogRepoLike;\n\tinstanceId: string;\n\tprojectId: number;\n\tiid: number;\n\tnoteId: number;\n\tsignal?: AbortSignal;\n}): Promise<void> {\n\tconst { client, writes, instanceId, projectId, iid, noteId, signal } = input;\n\tconst digest = createHash(\"sha256\")\n\t\t.update(JSON.stringify([client.baseUrl, projectId, iid, instanceId, \"eyes\", noteId]))\n\t\t.digest(\"hex\");\n\tawait ensureWrite(\n\t\twrites,\n\t\tinstanceId,\n\t\tcreateWriteIdentity(\"gitlab.reaction\", digest),\n\t\tasync () => {\n\t\t\tconst identity = await client.resolveGitIdentity(signal);\n\t\t\tconst find = async () =>\n\t\t\t\t(await client.listNoteReactions(projectId, iid, noteId, signal)).find(\n\t\t\t\t\t(reaction) => reaction.name === \"eyes\" && reaction.user.username === identity.username,\n\t\t\t\t);\n\t\t\tconst reaction = await findOrCreate(find, () =>\n\t\t\t\tclient.addNoteReaction(projectId, iid, noteId, \"eyes\", signal),\n\t\t\t);\n\t\t\treturn { projectId, iid, noteId, reactionId: reaction.id, name: \"eyes\" };\n\t\t},\n\t);\n}\nexport function registerGitLabTools(\n\tapi: ServerExtensionAPI,\n\tintegration: GitLabIntegration,\n\twrites: ExternalWriteLogRepoLike,\n) {\n\tfor (const [name, description, required] of [\n\t\t[\"gitlab_observe_merge_request\", \"Read the current MR source revision and its latest CI\", []],\n\t\t[\"gitlab_get_changes\", \"Read the MR changes\", []],\n\t\t[\"gitlab_get_identity\", \"Resolve the authenticated GitLab bot Git identity\", []],\n\t\t[\"gitlab_list_failed_jobs\", \"Read failed jobs from an MR-associated pipeline\", [\"pipelineId\"]],\n\t\t[\n\t\t\t\"gitlab_get_job_trace\",\n\t\t\t\"Read a bounded trace from a failed MR pipeline job\",\n\t\t\t[\"pipelineId\", \"jobId\"],\n\t\t],\n\t\t[\"gitlab_comment\", \"Post a retry-safe MR comment\", [\"body\", \"writeKey\"]],\n\t\t[\n\t\t\t\"gitlab_reply\",\n\t\t\t\"Post a retry-safe reply in an MR discussion\",\n\t\t\t[\"body\", \"writeKey\", \"discussionId\"],\n\t\t],\n\t] as const) {\n\t\tapi.tool<Record<string, unknown>>({\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tparameters: projectParameters(\n\t\t\t\t{\n\t\t\t\t\tpipelineId: { type: \"integer\" },\n\t\t\t\t\tjobId: { type: \"integer\" },\n\t\t\t\t\tmaxBytes: { type: \"integer\" },\n\t\t\t\t\tbody: { type: \"string\" },\n\t\t\t\t\twriteKey: { type: \"string\" },\n\t\t\t\t\tdiscussionId: { type: \"string\" },\n\t\t\t\t},\n\t\t\t\t[...required],\n\t\t\t),\n\t\t\tasync execute(ctx, args) {\n\t\t\t\tconst b = resolveGitLabBinding(ctx);\n\t\t\t\tconst client = integration.client(b.profile);\n\t\t\t\tif (name === \"gitlab_observe_merge_request\")\n\t\t\t\t\treturn observeMergeRequest(client, b.projectId, b.iid, ctx.signal);\n\t\t\t\tif (name === \"gitlab_get_changes\") return client.getChanges(b.projectId, b.iid, ctx.signal);\n\t\t\t\tif (name === \"gitlab_get_identity\") return client.resolveGitIdentity(ctx.signal);\n\t\t\t\tif (name === \"gitlab_comment\" || name === \"gitlab_reply\")\n\t\t\t\t\treturn ensureGitLabComment({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\twrites,\n\t\t\t\t\t\tinstanceId: ctx.process.id,\n\t\t\t\t\t\tprojectId: b.projectId,\n\t\t\t\t\t\tiid: b.iid,\n\t\t\t\t\t\twriteKey: stringArg(args, \"writeKey\"),\n\t\t\t\t\t\tbody: stringArg(args, \"body\"),\n\t\t\t\t\t\t...(name === \"gitlab_reply\" ? { discussionId: stringArg(args, \"discussionId\") } : {}),\n\t\t\t\t\t\tsignal: ctx.signal,\n\t\t\t\t\t});\n\t\t\t\tconst observation = await observeMergeRequest(client, b.projectId, b.iid, ctx.signal);\n\t\t\t\tif (!observation.pipeline || observation.pipeline.id !== numberArg(args, \"pipelineId\"))\n\t\t\t\t\tthrow new Error(\"Pipeline is not current for the authorized MR\");\n\t\t\t\tconst jobs = await client.listFailedJobs(\n\t\t\t\t\tobservation.pipeline.project_id,\n\t\t\t\t\tobservation.pipeline.id,\n\t\t\t\t\tctx.signal,\n\t\t\t\t);\n\t\t\t\tif (name === \"gitlab_list_failed_jobs\") return jobs;\n\t\t\t\tconst job = jobs.find((job) => job.id === numberArg(args, \"jobId\"));\n\t\t\t\tif (!job) throw new Error(\"Job is not a failed job of the authorized MR pipeline\");\n\t\t\t\treturn client.getJobTrace(\n\t\t\t\t\tobservation.pipeline.project_id,\n\t\t\t\t\tjob.id,\n\t\t\t\t\ttypeof args.maxBytes === \"number\" ? args.maxBytes : undefined,\n\t\t\t\t\tctx.signal,\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t}\n}\n","import type { GitLabClientLike, GitLabProject } from \"./client.js\";\nexport interface GitLabSelection {\n\tprojects: { include: readonly string[]; exclude: readonly string[] };\n\tgroups: { include: readonly string[]; exclude: readonly string[] };\n\tallAccessible: boolean;\n}\nexport function parseGitLabSelection(raw: Record<string, unknown>): GitLabSelection {\n\tconst list = (value: unknown): string[] => {\n\t\tif (value === undefined) return [];\n\t\tif (\n\t\t\t!Array.isArray(value) ||\n\t\t\tvalue.some(\n\t\t\t\t(v) =>\n\t\t\t\t\ttypeof v !== \"string\" ||\n\t\t\t\t\t!/^[a-zA-Z0-9_.-]+(?:\\/[a-zA-Z0-9_.-]+)*$/.test(v) ||\n\t\t\t\t\tv.split(\"/\").some((p: string) => p === \".\" || p === \"..\"),\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(\"GitLab selectors require exact namespace paths\");\n\t\treturn [...new Set(value as string[])];\n\t};\n\tconst pair = (value: unknown) => {\n\t\tif (value !== undefined && (!value || typeof value !== \"object\" || Array.isArray(value)))\n\t\t\tthrow new Error(\"GitLab selectors must be objects\");\n\t\tconst item = value as Record<string, unknown> | undefined;\n\t\treturn { include: list(item?.include), exclude: list(item?.exclude) };\n\t};\n\tif (raw.all_accessible !== undefined && typeof raw.all_accessible !== \"boolean\")\n\t\tthrow new Error(\"all_accessible must be a boolean\");\n\tconst parsed = {\n\t\tprojects: pair(raw.projects),\n\t\tgroups: pair(raw.groups),\n\t\tallAccessible: raw.all_accessible === true,\n\t};\n\tif (!parsed.allAccessible && !parsed.projects.include.length && !parsed.groups.include.length)\n\t\tthrow new Error(\"GitLab requires explicit project/group includes or all_accessible: true\");\n\treturn parsed;\n}\nexport function projectExcluded(selection: GitLabSelection, name: string): boolean {\n\treturn (\n\t\tselection.projects.exclude.includes(name) ||\n\t\tselection.groups.exclude.some((group) => name.startsWith(`${group}/`))\n\t);\n}\n/** Include union, subgroup expansion, exclusion precedence, stable-ID deduplication. */\nexport async function selectGitLabProjects(\n\tclient: GitLabClientLike,\n\tselection: GitLabSelection,\n): Promise<GitLabProject[]> {\n\tconst candidates: GitLabProject[] = selection.allAccessible ? await client.listProjects() : [];\n\tfor (const name of selection.projects.include) candidates.push(await client.getProject(name));\n\tfor (const group of selection.groups.include)\n\t\tcandidates.push(...(await client.listGroupProjects(group)));\n\treturn [\n\t\t...new Map(\n\t\t\tcandidates\n\t\t\t\t.filter((p) => !p.archived && !projectExcluded(selection, p.path_with_namespace))\n\t\t\t\t.map((p) => [p.id, p]),\n\t\t).values(),\n\t];\n}\n"],"mappings":";AACA;AAAA,EACC;AAAA,OAGM;;;ACLP;AAAA,EACC;AAAA,OAGM;AAMA,IAAM,oBAAoB;AAAA,EAChC;AACD;AAEO,SAAS,4BACf,SACA,UACoC;AACpC,SAAO,SAAS,IAAI,CAAC,aAAa;AAAA,IACjC,YAAY,QAAQ;AAAA,IACpB,MAAM;AAAA,IACN,eAAe,UAAU,OAAO;AAAA,EACjC,EAAE;AACH;;;ACvBA,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AAiH5B,IAAM,cAAN,cAA0B,MAAM;AAAA,EACtC,YACU,QACA,WACR;AACD;AAAA,MACC,0BAA0B,UAAU,qBAAqB,IAAI,YAAY,gBAAgB,oCAAoC;AAAA,IAC9H;AALS;AACA;AAAA,EAKV;AAAA,EANU;AAAA,EACA;AAMX;AACO,SAAS,oBAAoB,KAA0C;AAC7E,QAAM,WAAW,oBAAI,IAA2B;AAChD,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO;AAAA,IAClC,gBAAgB,gBAAgB,GAAG,GAAG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