@leitwerk-dev/gitlab 0.2.0 → 0.3.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.
- package/README.md +45 -5
- package/dist/capability.d.ts +5 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/chunk-H4JCQNDY.js +1162 -0
- package/dist/chunk-H4JCQNDY.js.map +1 -0
- package/dist/client.d.ts +230 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/delivery-tools.d.ts +4 -0
- package/dist/delivery-tools.d.ts.map +1 -0
- package/dist/external.d.ts +80 -5
- package/dist/external.d.ts.map +1 -1
- package/dist/index.d.ts +13 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -20
- package/dist/index.js.map +1 -1
- package/dist/issue-watcher.d.ts +42 -0
- package/dist/issue-watcher.d.ts.map +1 -0
- package/dist/preflight.d.ts +10 -0
- package/dist/preflight.d.ts.map +1 -0
- 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 +43 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +139 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +35 -4
- package/dist/tools.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/capability.ts +5 -1
- package/src/client.ts +392 -20
- package/src/delivery-tools.ts +226 -0
- package/src/external.ts +200 -8
- package/src/index.ts +42 -26
- package/src/issue-watcher.ts +152 -0
- package/src/preflight.ts +70 -0
- package/src/selection.ts +19 -3
- package/src/setup.ts +22 -0
- package/src/testing.ts +161 -7
- package/src/tools.ts +106 -54
- package/dist/chunk-5GBBPAG5.js +0 -656
- package/dist/chunk-5GBBPAG5.js.map +0 -1
package/src/client.ts
CHANGED
|
@@ -1,120 +1,294 @@
|
|
|
1
1
|
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2
2
|
import { repositoryHttpsUrl } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { preflightGitLabRepository } from "./preflight.js";
|
|
3
4
|
|
|
5
|
+
/** @internal */
|
|
4
6
|
export interface GitLabProfile {
|
|
7
|
+
/** @internal */
|
|
5
8
|
baseUrl: string;
|
|
9
|
+
/** @internal */
|
|
6
10
|
token: string;
|
|
7
|
-
|
|
11
|
+
/** @internal */
|
|
12
|
+
gitIdentity?: {
|
|
13
|
+
/** @internal */
|
|
14
|
+
name: string;
|
|
15
|
+
/** @internal */
|
|
16
|
+
email: string;
|
|
17
|
+
};
|
|
8
18
|
}
|
|
19
|
+
/** @public */
|
|
9
20
|
export interface GitLabProject {
|
|
21
|
+
/** @public */
|
|
10
22
|
id: number;
|
|
23
|
+
/** @public */
|
|
11
24
|
path_with_namespace: string;
|
|
25
|
+
/** @public */
|
|
12
26
|
http_url_to_repo: string;
|
|
27
|
+
/** @public */
|
|
13
28
|
web_url: string;
|
|
29
|
+
/** @internal */
|
|
14
30
|
default_branch: string;
|
|
31
|
+
/** @public */
|
|
15
32
|
archived?: boolean;
|
|
33
|
+
/** @internal */
|
|
16
34
|
permissions?: {
|
|
17
|
-
|
|
18
|
-
|
|
35
|
+
/** @internal */
|
|
36
|
+
project_access?: {
|
|
37
|
+
/** @internal */
|
|
38
|
+
access_level: number;
|
|
39
|
+
} | null;
|
|
40
|
+
/** @internal */
|
|
41
|
+
group_access?: {
|
|
42
|
+
/** @internal */
|
|
43
|
+
access_level: number;
|
|
44
|
+
} | null;
|
|
19
45
|
};
|
|
20
46
|
}
|
|
47
|
+
/** @internal */
|
|
21
48
|
export interface GitLabGroup {
|
|
49
|
+
/** @internal */
|
|
22
50
|
id: number;
|
|
51
|
+
/** @internal */
|
|
23
52
|
full_path: string;
|
|
24
53
|
}
|
|
54
|
+
/** @public */
|
|
55
|
+
export interface GitLabIssue {
|
|
56
|
+
/** @public */
|
|
57
|
+
id: number;
|
|
58
|
+
/** @public */
|
|
59
|
+
iid: number;
|
|
60
|
+
/** @public */
|
|
61
|
+
project_id: number;
|
|
62
|
+
/** @public */
|
|
63
|
+
title: string;
|
|
64
|
+
/** @public */
|
|
65
|
+
description: string | null;
|
|
66
|
+
/** @public */
|
|
67
|
+
web_url: string;
|
|
68
|
+
/** @public */
|
|
69
|
+
state: string;
|
|
70
|
+
/** @public */
|
|
71
|
+
labels: string[];
|
|
72
|
+
}
|
|
73
|
+
/** @public */
|
|
25
74
|
export interface GitLabMergeRequest {
|
|
75
|
+
/** @public */
|
|
76
|
+
detailed_merge_status?: string;
|
|
77
|
+
/** @public */
|
|
78
|
+
has_conflicts?: boolean;
|
|
79
|
+
/** @public */
|
|
80
|
+
merge_status?: string;
|
|
81
|
+
/** @public */
|
|
26
82
|
iid: number;
|
|
83
|
+
/** @public */
|
|
27
84
|
project_id: number;
|
|
85
|
+
/** @public */
|
|
28
86
|
source_project_id: number;
|
|
87
|
+
/** @public */
|
|
29
88
|
target_project_id: number;
|
|
89
|
+
/** @public */
|
|
30
90
|
title: string;
|
|
91
|
+
/** @public */
|
|
31
92
|
description: string | null;
|
|
93
|
+
/** @public */
|
|
32
94
|
state: string;
|
|
95
|
+
/** @public */
|
|
33
96
|
labels: string[];
|
|
97
|
+
/** @public */
|
|
34
98
|
sha: string;
|
|
99
|
+
/** @public */
|
|
35
100
|
source_branch: string;
|
|
101
|
+
/** @public */
|
|
36
102
|
target_branch: string;
|
|
103
|
+
/** @public */
|
|
37
104
|
web_url: string;
|
|
105
|
+
/** @internal */
|
|
38
106
|
merge_commit_sha?: string | null;
|
|
39
|
-
|
|
107
|
+
/** @internal */
|
|
108
|
+
diff_refs?: {
|
|
109
|
+
/** @internal */
|
|
110
|
+
base_sha: string;
|
|
111
|
+
/** @internal */
|
|
112
|
+
head_sha: string;
|
|
113
|
+
/** @internal */
|
|
114
|
+
start_sha: string;
|
|
115
|
+
};
|
|
40
116
|
}
|
|
117
|
+
/** @public */
|
|
41
118
|
export interface GitLabCommit {
|
|
119
|
+
/** @public */
|
|
42
120
|
id: string;
|
|
121
|
+
/** @internal */
|
|
43
122
|
parent_ids: string[];
|
|
123
|
+
/** @internal */
|
|
44
124
|
message: string;
|
|
125
|
+
/** @internal */
|
|
45
126
|
web_url?: string;
|
|
46
127
|
}
|
|
128
|
+
/** @public */
|
|
47
129
|
export interface GitLabBranch {
|
|
130
|
+
/** @internal */
|
|
48
131
|
name: string;
|
|
132
|
+
/** @public */
|
|
49
133
|
can_push: boolean;
|
|
134
|
+
/** @internal */
|
|
50
135
|
protected: boolean;
|
|
136
|
+
/** @public */
|
|
51
137
|
commit: GitLabCommit;
|
|
52
138
|
}
|
|
139
|
+
/** @public */
|
|
53
140
|
export interface GitLabPipeline {
|
|
141
|
+
/** @public */
|
|
54
142
|
id: number;
|
|
143
|
+
/** @public */
|
|
55
144
|
project_id: number;
|
|
145
|
+
/** @public */
|
|
56
146
|
sha: string;
|
|
147
|
+
/** @public */
|
|
57
148
|
ref: string;
|
|
149
|
+
/** @public */
|
|
58
150
|
status: string;
|
|
151
|
+
/** @internal */
|
|
59
152
|
source?: string;
|
|
153
|
+
/** @public */
|
|
60
154
|
web_url: string;
|
|
61
155
|
}
|
|
156
|
+
/** @public */
|
|
62
157
|
export interface GitLabJob {
|
|
158
|
+
/** @internal */
|
|
63
159
|
id: number;
|
|
160
|
+
/** @public */
|
|
64
161
|
name: string;
|
|
162
|
+
/** @internal */
|
|
65
163
|
status: string;
|
|
164
|
+
/** @public */
|
|
66
165
|
web_url: string;
|
|
166
|
+
/** @public */
|
|
67
167
|
failure_reason?: string;
|
|
68
168
|
}
|
|
169
|
+
/** @public */
|
|
69
170
|
export interface GitLabDiff {
|
|
171
|
+
/** @public */
|
|
70
172
|
old_path: string;
|
|
173
|
+
/** @public */
|
|
71
174
|
new_path: string;
|
|
175
|
+
/** @public */
|
|
72
176
|
diff: string;
|
|
177
|
+
/** @public */
|
|
73
178
|
new_file: boolean;
|
|
179
|
+
/** @public */
|
|
74
180
|
deleted_file: boolean;
|
|
181
|
+
/** @public */
|
|
75
182
|
renamed_file: boolean;
|
|
76
183
|
}
|
|
184
|
+
/** @public */
|
|
77
185
|
export interface GitLabNote {
|
|
186
|
+
/** @internal */
|
|
78
187
|
id: number;
|
|
188
|
+
/** @public */
|
|
79
189
|
body: string;
|
|
80
190
|
}
|
|
191
|
+
/** @public */
|
|
81
192
|
export interface GitLabNoteReaction {
|
|
193
|
+
/** @public */
|
|
82
194
|
id: number;
|
|
195
|
+
/** @internal */
|
|
83
196
|
name: string;
|
|
84
|
-
|
|
197
|
+
/** @internal */
|
|
198
|
+
user: {
|
|
199
|
+
/** @internal */
|
|
200
|
+
username: string;
|
|
201
|
+
};
|
|
85
202
|
}
|
|
203
|
+
/** @public */
|
|
86
204
|
export interface GitLabFeedback {
|
|
205
|
+
/** @public */
|
|
87
206
|
id: number;
|
|
207
|
+
/** @public */
|
|
88
208
|
discussionId: string;
|
|
209
|
+
/** @public */
|
|
89
210
|
body: string;
|
|
211
|
+
/** @public */
|
|
90
212
|
author: string;
|
|
213
|
+
/** @public */
|
|
91
214
|
createdAt: string;
|
|
215
|
+
/** @public */
|
|
92
216
|
path?: string;
|
|
217
|
+
/** @public */
|
|
93
218
|
line?: number;
|
|
94
219
|
}
|
|
220
|
+
/** @internal */
|
|
95
221
|
export interface GitLabDiscussion {
|
|
222
|
+
/** @internal */
|
|
96
223
|
id: string;
|
|
224
|
+
/** @internal */
|
|
97
225
|
notes: (GitLabNote & {
|
|
226
|
+
/** @internal */
|
|
98
227
|
system: boolean;
|
|
228
|
+
/** @internal */
|
|
99
229
|
created_at: string;
|
|
100
|
-
|
|
230
|
+
/** @internal */
|
|
231
|
+
author: {
|
|
232
|
+
/** @internal */
|
|
233
|
+
username: string;
|
|
234
|
+
/** @internal */
|
|
235
|
+
bot?: boolean;
|
|
236
|
+
};
|
|
237
|
+
/** @internal */
|
|
101
238
|
resolved?: boolean;
|
|
102
|
-
|
|
239
|
+
/** @internal */
|
|
240
|
+
position?: {
|
|
241
|
+
/** @internal */
|
|
242
|
+
new_path?: string;
|
|
243
|
+
/** @internal */
|
|
244
|
+
old_path?: string;
|
|
245
|
+
/** @internal */
|
|
246
|
+
new_line?: number;
|
|
247
|
+
/** @internal */
|
|
248
|
+
old_line?: number;
|
|
249
|
+
};
|
|
103
250
|
})[];
|
|
104
251
|
}
|
|
252
|
+
/** @public */
|
|
105
253
|
export interface GitLabIdentity {
|
|
254
|
+
/** @public */
|
|
106
255
|
name: string;
|
|
256
|
+
/** @public */
|
|
107
257
|
email: string;
|
|
258
|
+
/** @public */
|
|
108
259
|
username: string;
|
|
109
260
|
}
|
|
261
|
+
/** @public */
|
|
110
262
|
export interface GitLabObservation {
|
|
263
|
+
/** @public */
|
|
111
264
|
mr: GitLabMergeRequest;
|
|
265
|
+
/** @public */
|
|
112
266
|
pipeline: GitLabPipeline | null;
|
|
267
|
+
/** @public */
|
|
268
|
+
targetHead?: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** @public */
|
|
272
|
+
export function gitLabMergeabilityPending(mr: GitLabMergeRequest): boolean {
|
|
273
|
+
return ["checking", "unchecked", "preparing"].includes(
|
|
274
|
+
mr.detailed_merge_status ?? mr.merge_status ?? "",
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** @public Only actionable Git conflicts/rebase requirements, not approvals or CI gates. */
|
|
279
|
+
export function gitLabMergeRepairReason(mr: GitLabMergeRequest): "conflict" | "rebase" | null {
|
|
280
|
+
if (gitLabMergeabilityPending(mr)) return null;
|
|
281
|
+
if (mr.has_conflicts || mr.detailed_merge_status === "conflict") return "conflict";
|
|
282
|
+
return mr.detailed_merge_status === "need_rebase" ? "rebase" : null;
|
|
113
283
|
}
|
|
114
284
|
|
|
285
|
+
/** @internal */
|
|
115
286
|
export class GitLabError extends Error {
|
|
287
|
+
/** @internal */
|
|
116
288
|
constructor(
|
|
289
|
+
/** @internal */
|
|
117
290
|
readonly status: number,
|
|
291
|
+
/** @internal */
|
|
118
292
|
readonly retryable: boolean,
|
|
119
293
|
) {
|
|
120
294
|
super(
|
|
@@ -122,6 +296,7 @@ export class GitLabError extends Error {
|
|
|
122
296
|
);
|
|
123
297
|
}
|
|
124
298
|
}
|
|
299
|
+
/** @internal */
|
|
125
300
|
export function parseGitLabProfiles(raw: unknown): Map<string, GitLabProfile> {
|
|
126
301
|
const profiles = new Map<string, GitLabProfile>();
|
|
127
302
|
for (const [name, value] of Object.entries(
|
|
@@ -160,14 +335,24 @@ const projectPath = (id: number | string) => `/projects/${encodeURIComponent(id)
|
|
|
160
335
|
const mrPath = (id: number, iid: number) => `${projectPath(id)}/merge_requests/${iid}`;
|
|
161
336
|
|
|
162
337
|
/** GitLab v4 API. Errors deliberately omit response bodies, headers and tokens. */
|
|
338
|
+
/** @public */
|
|
163
339
|
export class GitLabClient {
|
|
340
|
+
/** @public */
|
|
164
341
|
readonly baseUrl: string;
|
|
165
342
|
readonly #profile: GitLabProfile;
|
|
166
343
|
readonly #fetch: typeof fetch;
|
|
167
344
|
readonly #sleep: (ms: number) => Promise<unknown>;
|
|
345
|
+
/** @internal */
|
|
168
346
|
constructor(
|
|
169
347
|
profile: GitLabProfile,
|
|
170
|
-
|
|
348
|
+
/** @public */
|
|
349
|
+
/** @public */
|
|
350
|
+
options: {
|
|
351
|
+
/** @internal */
|
|
352
|
+
fetch?: typeof fetch;
|
|
353
|
+
/** @internal */
|
|
354
|
+
sleep?: (ms: number) => Promise<unknown>;
|
|
355
|
+
} = {},
|
|
171
356
|
) {
|
|
172
357
|
if (repositoryHttpsUrl(`${profile.baseUrl}/repository`).origin !== profile.baseUrl)
|
|
173
358
|
throw new Error("GitLab requires an HTTPS origin baseUrl");
|
|
@@ -178,12 +363,17 @@ export class GitLabClient {
|
|
|
178
363
|
this.#fetch = options.fetch ?? fetch;
|
|
179
364
|
this.#sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
180
365
|
}
|
|
181
|
-
private async response(
|
|
366
|
+
private async response(
|
|
367
|
+
path: string,
|
|
368
|
+
signal?: AbortSignal,
|
|
369
|
+
body?: unknown,
|
|
370
|
+
method?: string,
|
|
371
|
+
): Promise<Response> {
|
|
182
372
|
for (let attempt = 0; ; attempt++) {
|
|
183
373
|
let response: Response;
|
|
184
374
|
try {
|
|
185
375
|
response = await this.#fetch(`${this.baseUrl}/api/v4${path}`, {
|
|
186
|
-
method: body === undefined ? "GET" : "POST",
|
|
376
|
+
method: method ?? (body === undefined ? "GET" : "POST"),
|
|
187
377
|
redirect: "error",
|
|
188
378
|
headers: {
|
|
189
379
|
"PRIVATE-TOKEN": this.#profile.token,
|
|
@@ -211,8 +401,13 @@ export class GitLabClient {
|
|
|
211
401
|
await this.#sleep(Math.min(30_000, seconds > 0 ? seconds * 1_000 : 1_000 * 2 ** attempt));
|
|
212
402
|
}
|
|
213
403
|
}
|
|
214
|
-
private async request<T>(
|
|
215
|
-
|
|
404
|
+
private async request<T>(
|
|
405
|
+
path: string,
|
|
406
|
+
signal?: AbortSignal,
|
|
407
|
+
body?: unknown,
|
|
408
|
+
method?: string,
|
|
409
|
+
): Promise<T> {
|
|
410
|
+
return this.json<T>(await this.response(path, signal, body, method));
|
|
216
411
|
}
|
|
217
412
|
private async json<T>(response: Response): Promise<T> {
|
|
218
413
|
try {
|
|
@@ -241,21 +436,133 @@ export class GitLabClient {
|
|
|
241
436
|
}
|
|
242
437
|
throw new Error("GitLab pagination limit exceeded; discovery incomplete");
|
|
243
438
|
}
|
|
439
|
+
/** @public */
|
|
440
|
+
listIssues(id: number, signal?: AbortSignal): Promise<GitLabIssue[]> {
|
|
441
|
+
return this.pages(`${projectPath(id)}/issues?state=opened&scope=all`, signal);
|
|
442
|
+
}
|
|
443
|
+
/** @public */
|
|
444
|
+
getIssue(id: number, iid: number, signal?: AbortSignal): Promise<GitLabIssue> {
|
|
445
|
+
return this.request(`${projectPath(id)}/issues/${iid}`, signal);
|
|
446
|
+
}
|
|
447
|
+
/** @public */
|
|
448
|
+
updateIssue(
|
|
449
|
+
id: number,
|
|
450
|
+
iid: number,
|
|
451
|
+
/** @public */
|
|
452
|
+
/** @public */
|
|
453
|
+
patch: {
|
|
454
|
+
/** @public */
|
|
455
|
+
labels?: string;
|
|
456
|
+
/** @public */
|
|
457
|
+
state_event?: "close";
|
|
458
|
+
},
|
|
459
|
+
signal?: AbortSignal,
|
|
460
|
+
): Promise<GitLabIssue> {
|
|
461
|
+
return this.request(`${projectPath(id)}/issues/${iid}`, signal, patch, "PUT");
|
|
462
|
+
}
|
|
463
|
+
/** @public */
|
|
464
|
+
listIssueNotes(id: number, iid: number, signal?: AbortSignal): Promise<GitLabNote[]> {
|
|
465
|
+
return this.pages(`${projectPath(id)}/issues/${iid}/notes`, signal);
|
|
466
|
+
}
|
|
467
|
+
/** @public */
|
|
468
|
+
addIssueNote(id: number, iid: number, body: string, signal?: AbortSignal): Promise<GitLabNote> {
|
|
469
|
+
return this.request(`${projectPath(id)}/issues/${iid}/notes`, signal, { body });
|
|
470
|
+
}
|
|
471
|
+
/** @public */
|
|
472
|
+
/** @public */
|
|
473
|
+
listLabels(
|
|
474
|
+
id: number,
|
|
475
|
+
signal?: AbortSignal,
|
|
476
|
+
): Promise<
|
|
477
|
+
Array<{
|
|
478
|
+
/** @public */ name: string;
|
|
479
|
+
}>
|
|
480
|
+
> {
|
|
481
|
+
return this.pages(`${projectPath(id)}/labels`, signal);
|
|
482
|
+
}
|
|
483
|
+
/** @public */
|
|
484
|
+
/** @public */
|
|
485
|
+
createLabel(
|
|
486
|
+
id: number,
|
|
487
|
+
name: string,
|
|
488
|
+
signal?: AbortSignal,
|
|
489
|
+
): Promise<{
|
|
490
|
+
/** @public */ name: string;
|
|
491
|
+
}> {
|
|
492
|
+
return this.request(`${projectPath(id)}/labels`, signal, { name, color: "#2da44e" });
|
|
493
|
+
}
|
|
494
|
+
/** @public */
|
|
495
|
+
listBranchMergeRequests(
|
|
496
|
+
id: number,
|
|
497
|
+
source: string,
|
|
498
|
+
target: string,
|
|
499
|
+
signal?: AbortSignal,
|
|
500
|
+
): Promise<GitLabMergeRequest[]> {
|
|
501
|
+
return this.pages(
|
|
502
|
+
`${projectPath(id)}/merge_requests?state=all&source_branch=${encodeURIComponent(source)}&target_branch=${encodeURIComponent(target)}`,
|
|
503
|
+
signal,
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
/** @public */
|
|
507
|
+
createMergeRequest(
|
|
508
|
+
id: number,
|
|
509
|
+
/** @public */
|
|
510
|
+
/** @public */
|
|
511
|
+
input: {
|
|
512
|
+
/** @public */
|
|
513
|
+
title: string;
|
|
514
|
+
/** @public */
|
|
515
|
+
description: string;
|
|
516
|
+
/** @public */
|
|
517
|
+
source_branch: string;
|
|
518
|
+
/** @public */
|
|
519
|
+
target_branch: string;
|
|
520
|
+
},
|
|
521
|
+
signal?: AbortSignal,
|
|
522
|
+
): Promise<GitLabMergeRequest> {
|
|
523
|
+
return this.request(`${projectPath(id)}/merge_requests`, signal, {
|
|
524
|
+
...input,
|
|
525
|
+
remove_source_branch: false,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/** @public */
|
|
529
|
+
async preflightRepository(
|
|
530
|
+
projectId: number,
|
|
531
|
+
baseBranch: string,
|
|
532
|
+
workBranch: string,
|
|
533
|
+
signal?: AbortSignal,
|
|
534
|
+
): Promise<void> {
|
|
535
|
+
const project = await this.getProject(projectId, signal);
|
|
536
|
+
await preflightGitLabRepository({
|
|
537
|
+
url: project.http_url_to_repo,
|
|
538
|
+
origin: this.baseUrl,
|
|
539
|
+
token: this.#profile.token,
|
|
540
|
+
baseBranch,
|
|
541
|
+
workBranch,
|
|
542
|
+
signal,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** @public */
|
|
244
547
|
getProject(id: number | string, signal?: AbortSignal): Promise<GitLabProject> {
|
|
245
548
|
return this.request(projectPath(id), signal);
|
|
246
549
|
}
|
|
550
|
+
/** @internal */
|
|
247
551
|
listProjects(signal?: AbortSignal): Promise<GitLabProject[]> {
|
|
248
552
|
return this.pages("/projects?archived=false", signal);
|
|
249
553
|
}
|
|
554
|
+
/** @internal */
|
|
250
555
|
getGroup(id: number | string, signal?: AbortSignal): Promise<GitLabGroup> {
|
|
251
556
|
return this.request(`/groups/${encodeURIComponent(id)}`, signal);
|
|
252
557
|
}
|
|
558
|
+
/** @internal */
|
|
253
559
|
listGroupProjects(id: number | string, signal?: AbortSignal): Promise<GitLabProject[]> {
|
|
254
560
|
return this.pages(
|
|
255
561
|
`/groups/${encodeURIComponent(id)}/projects?include_subgroups=true&with_shared=false&archived=false`,
|
|
256
562
|
signal,
|
|
257
563
|
);
|
|
258
564
|
}
|
|
565
|
+
/** @public */
|
|
259
566
|
listMergeRequests(
|
|
260
567
|
id: number,
|
|
261
568
|
label: string,
|
|
@@ -266,21 +573,26 @@ export class GitLabClient {
|
|
|
266
573
|
signal,
|
|
267
574
|
);
|
|
268
575
|
}
|
|
576
|
+
/** @internal */
|
|
269
577
|
getMergeRequest(id: number, iid: number, signal?: AbortSignal): Promise<GitLabMergeRequest> {
|
|
270
578
|
return this.request(mrPath(id, iid), signal);
|
|
271
579
|
}
|
|
580
|
+
/** @public */
|
|
272
581
|
getChanges(id: number, iid: number, signal?: AbortSignal): Promise<GitLabDiff[]> {
|
|
273
582
|
return this.pages(`${mrPath(id, iid)}/diffs`, signal);
|
|
274
583
|
}
|
|
584
|
+
/** @public */
|
|
275
585
|
getBranch(id: number, branch: string, signal?: AbortSignal): Promise<GitLabBranch> {
|
|
276
586
|
return this.request(
|
|
277
587
|
`${projectPath(id)}/repository/branches/${encodeURIComponent(branch)}`,
|
|
278
588
|
signal,
|
|
279
589
|
);
|
|
280
590
|
}
|
|
591
|
+
/** @internal */
|
|
281
592
|
getCommit(id: number, sha: string, signal?: AbortSignal): Promise<GitLabCommit> {
|
|
282
593
|
return this.request(`${projectPath(id)}/repository/commits/${encodeURIComponent(sha)}`, signal);
|
|
283
594
|
}
|
|
595
|
+
/** @internal */
|
|
284
596
|
listMergeRequestPipelines(
|
|
285
597
|
id: number,
|
|
286
598
|
iid: number,
|
|
@@ -288,6 +600,7 @@ export class GitLabClient {
|
|
|
288
600
|
): Promise<GitLabPipeline[]> {
|
|
289
601
|
return this.pages(`${mrPath(id, iid)}/pipelines`, signal);
|
|
290
602
|
}
|
|
603
|
+
/** @internal */
|
|
291
604
|
listBranchPipelines(
|
|
292
605
|
id: number,
|
|
293
606
|
branch: string,
|
|
@@ -299,18 +612,22 @@ export class GitLabClient {
|
|
|
299
612
|
signal,
|
|
300
613
|
);
|
|
301
614
|
}
|
|
615
|
+
/** @internal */
|
|
302
616
|
getPipeline(id: number, pipeline: number, signal?: AbortSignal): Promise<GitLabPipeline> {
|
|
303
617
|
return this.request(`${projectPath(id)}/pipelines/${pipeline}`, signal);
|
|
304
618
|
}
|
|
619
|
+
/** @public */
|
|
305
620
|
listFailedJobs(id: number, pipeline: number, signal?: AbortSignal): Promise<GitLabJob[]> {
|
|
306
621
|
return this.pages(
|
|
307
622
|
`${projectPath(id)}/pipelines/${pipeline}/jobs?scope[]=failed&include_retried=false`,
|
|
308
623
|
signal,
|
|
309
624
|
);
|
|
310
625
|
}
|
|
626
|
+
/** @internal */
|
|
311
627
|
listNotes(id: number, iid: number, signal?: AbortSignal): Promise<GitLabNote[]> {
|
|
312
628
|
return this.pages(`${mrPath(id, iid)}/notes`, signal);
|
|
313
629
|
}
|
|
630
|
+
/** @internal */
|
|
314
631
|
getDiscussion(
|
|
315
632
|
id: number,
|
|
316
633
|
iid: number,
|
|
@@ -322,6 +639,7 @@ export class GitLabClient {
|
|
|
322
639
|
signal,
|
|
323
640
|
);
|
|
324
641
|
}
|
|
642
|
+
/** @internal */
|
|
325
643
|
replyToDiscussion(
|
|
326
644
|
id: number,
|
|
327
645
|
iid: number,
|
|
@@ -335,6 +653,7 @@ export class GitLabClient {
|
|
|
335
653
|
{ body },
|
|
336
654
|
);
|
|
337
655
|
}
|
|
656
|
+
/** @internal */
|
|
338
657
|
listNoteReactions(
|
|
339
658
|
id: number,
|
|
340
659
|
iid: number,
|
|
@@ -343,6 +662,7 @@ export class GitLabClient {
|
|
|
343
662
|
): Promise<GitLabNoteReaction[]> {
|
|
344
663
|
return this.pages(`${mrPath(id, iid)}/notes/${noteId}/award_emoji`, signal);
|
|
345
664
|
}
|
|
665
|
+
/** @internal */
|
|
346
666
|
addNoteReaction(
|
|
347
667
|
id: number,
|
|
348
668
|
iid: number,
|
|
@@ -352,15 +672,16 @@ export class GitLabClient {
|
|
|
352
672
|
): Promise<GitLabNoteReaction> {
|
|
353
673
|
return this.request(`${mrPath(id, iid)}/notes/${noteId}/award_emoji`, signal, { name });
|
|
354
674
|
}
|
|
675
|
+
/** @public */
|
|
355
676
|
async listMergeRequestFeedback(
|
|
356
677
|
id: number,
|
|
357
678
|
iid: number,
|
|
358
679
|
signal?: AbortSignal,
|
|
359
680
|
): Promise<GitLabFeedback[]> {
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
681
|
+
const discussions = await this.pages<GitLabDiscussion>(
|
|
682
|
+
`${mrPath(id, iid)}/discussions`,
|
|
683
|
+
signal,
|
|
684
|
+
);
|
|
364
685
|
const feedback: GitLabFeedback[] = [];
|
|
365
686
|
for (const discussion of discussions) {
|
|
366
687
|
for (const note of discussion.notes) {
|
|
@@ -368,7 +689,7 @@ export class GitLabClient {
|
|
|
368
689
|
note.system ||
|
|
369
690
|
note.resolved ||
|
|
370
691
|
note.author.bot ||
|
|
371
|
-
|
|
692
|
+
/<!-- leitwerk:gitlab:[a-f0-9]{64} -->/.test(note.body) ||
|
|
372
693
|
!note.body.trim() ||
|
|
373
694
|
!Number.isFinite(Date.parse(note.created_at))
|
|
374
695
|
)
|
|
@@ -391,9 +712,11 @@ export class GitLabClient {
|
|
|
391
712
|
}
|
|
392
713
|
return feedback.sort((a, b) => a.id - b.id);
|
|
393
714
|
}
|
|
715
|
+
/** @internal */
|
|
394
716
|
addNote(id: number, iid: number, body: string, signal?: AbortSignal): Promise<GitLabNote> {
|
|
395
717
|
return this.request(`${mrPath(id, iid)}/notes`, signal, { body });
|
|
396
718
|
}
|
|
719
|
+
/** @public */
|
|
397
720
|
async resolveGitIdentity(signal?: AbortSignal): Promise<GitLabIdentity> {
|
|
398
721
|
const user = await this.request<{
|
|
399
722
|
name?: string;
|
|
@@ -409,12 +732,20 @@ export class GitLabClient {
|
|
|
409
732
|
);
|
|
410
733
|
return { name, email, username: user.username };
|
|
411
734
|
}
|
|
735
|
+
/** @public */
|
|
412
736
|
async getJobTrace(
|
|
413
737
|
id: number,
|
|
414
738
|
job: number,
|
|
415
739
|
maxBytes = 65_536,
|
|
416
740
|
signal?: AbortSignal,
|
|
417
|
-
|
|
741
|
+
/** @public */
|
|
742
|
+
/** @public */
|
|
743
|
+
): Promise<{
|
|
744
|
+
/** @public */
|
|
745
|
+
text: string;
|
|
746
|
+
/** @public */
|
|
747
|
+
truncated: boolean;
|
|
748
|
+
}> {
|
|
418
749
|
const limit = Math.min(262_144, Math.max(1, Math.floor(maxBytes) || 65_536));
|
|
419
750
|
const response = await this.response(`${projectPath(id)}/jobs/${job}/trace`, signal);
|
|
420
751
|
const reader = response.body?.getReader();
|
|
@@ -440,9 +771,46 @@ export class GitLabClient {
|
|
|
440
771
|
return { text: Buffer.concat(chunks).toString("utf8"), truncated };
|
|
441
772
|
}
|
|
442
773
|
}
|
|
443
|
-
|
|
774
|
+
/** @public */
|
|
775
|
+
export type GitLabClientLike = Pick<
|
|
776
|
+
GitLabClient,
|
|
777
|
+
| "listIssues"
|
|
778
|
+
| "getIssue"
|
|
779
|
+
| "updateIssue"
|
|
780
|
+
| "listIssueNotes"
|
|
781
|
+
| "addIssueNote"
|
|
782
|
+
| "listLabels"
|
|
783
|
+
| "createLabel"
|
|
784
|
+
| "listBranchMergeRequests"
|
|
785
|
+
| "createMergeRequest"
|
|
786
|
+
| "preflightRepository"
|
|
787
|
+
| "addNote"
|
|
788
|
+
| "addNoteReaction"
|
|
789
|
+
| "baseUrl"
|
|
790
|
+
| "getBranch"
|
|
791
|
+
| "getChanges"
|
|
792
|
+
| "getCommit"
|
|
793
|
+
| "getDiscussion"
|
|
794
|
+
| "getGroup"
|
|
795
|
+
| "getJobTrace"
|
|
796
|
+
| "getMergeRequest"
|
|
797
|
+
| "getPipeline"
|
|
798
|
+
| "getProject"
|
|
799
|
+
| "listBranchPipelines"
|
|
800
|
+
| "listFailedJobs"
|
|
801
|
+
| "listGroupProjects"
|
|
802
|
+
| "listMergeRequestFeedback"
|
|
803
|
+
| "listMergeRequestPipelines"
|
|
804
|
+
| "listMergeRequests"
|
|
805
|
+
| "listNoteReactions"
|
|
806
|
+
| "listNotes"
|
|
807
|
+
| "listProjects"
|
|
808
|
+
| "replyToDiscussion"
|
|
809
|
+
| "resolveGitIdentity"
|
|
810
|
+
>;
|
|
444
811
|
|
|
445
812
|
/** A pending current pipeline supersedes every older result. Synthetic merges must contain this source head. */
|
|
813
|
+
/** @public */
|
|
446
814
|
export async function observeMergeRequest(
|
|
447
815
|
client: GitLabClientLike,
|
|
448
816
|
projectId: number,
|
|
@@ -451,6 +819,8 @@ export async function observeMergeRequest(
|
|
|
451
819
|
): Promise<GitLabObservation> {
|
|
452
820
|
const mr = await client.getMergeRequest(projectId, iid, signal);
|
|
453
821
|
if (mr.state !== "opened") return { mr, pipeline: null };
|
|
822
|
+
const targetHead = (await client.getBranch(mr.target_project_id, mr.target_branch, signal)).commit
|
|
823
|
+
.id;
|
|
454
824
|
const associated = (await client.listMergeRequestPipelines(projectId, iid, signal)).sort(
|
|
455
825
|
(a, b) => b.id - a.id,
|
|
456
826
|
);
|
|
@@ -465,7 +835,8 @@ export async function observeMergeRequest(
|
|
|
465
835
|
const commit = await client.getCommit(id, candidate.sha, signal);
|
|
466
836
|
matches = commit.parent_ids.includes(mr.sha);
|
|
467
837
|
}
|
|
468
|
-
if (matches)
|
|
838
|
+
if (matches)
|
|
839
|
+
return { mr, targetHead, pipeline: await client.getPipeline(id, candidate.id, signal) };
|
|
469
840
|
}
|
|
470
841
|
const candidates = await client.listBranchPipelines(
|
|
471
842
|
mr.source_project_id,
|
|
@@ -478,6 +849,7 @@ export async function observeMergeRequest(
|
|
|
478
849
|
.sort((a, b) => b.id - a.id)[0];
|
|
479
850
|
return {
|
|
480
851
|
mr,
|
|
852
|
+
targetHead,
|
|
481
853
|
pipeline: latest ? await client.getPipeline(mr.source_project_id, latest.id, signal) : null,
|
|
482
854
|
};
|
|
483
855
|
}
|