Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitLabIssueTracker.ts

782 lines26.7 KB

1/**
2 * GitLab's issue tracker over `glab api`. GitLab pages by offset, so every cursor is a page
3 * number. Notes, label events, linked merge requests and awards are separate endpoints, joined
4 * into the detail.
5 */
6import * as Effect from "effect/Effect";
7import * as Result from "effect/Result";
8import * as Schema from "effect/Schema";
9import {
10 IssueTrackerKind,
11 type IssueCapabilities,
12 type IssueEvent,
13 type IssueInvolvement,
14 type IssueViewerPermissions,
15} from "@t3tools/contracts";
16import {
17 IssueTrackerError,
18 type IssueTrackerApi,
19} from "@t3tools/source-control-core/server/IssueTracker";
20​
21import * as GitLabCli from "./GitLabCli.ts";
22import {
23 decodeCreatedIssueJson,
24 decodeUserIdsJson,
25 decodeIssueDetailJson,
26 decodeIssueListJson,
27 decodeIssueNotesJson,
28 decodeLabelEventsJson,
29 decodeLinkedMergeRequestsJson,
30 decodeProjectLabelsJson,
31 decodeProjectMembersJson,
32 decodeTemplateEntriesJson,
33 decodeTemplateJson,
34 ISSUE_AWARD_EMOJI_GRAPHQL_QUERY,
35 ISSUE_STATES,
36 PAGE_SIZE,
37 type GitLabTemplateEntry,
38} from "./gitLabIssueJson.ts";
39import {
40 decodeAwardEmojiJson,
41 decodeOwnAwardIdJson,
42 decodeViewerJson,
43 gitLabAwardName,
44} from "./gitLabMergeRequestJson.ts";
45​
46const KIND = IssueTrackerKind.make("gitlab");
47/** How many pages of system notes the timeline reads before giving up on the rest. */
48const MAX_ACTIVITY_PAGES = 20;
49​
50const CAPABILITIES: IssueCapabilities = {
51 create: true,
52 edit: true,
53 comment: true,
54 labels: true,
55 assignees: true,
56 reactions: true,
57 templates: true,
58 linkedPullRequests: true,
59 events: true,
60 search: true,
61};
62​
63/**
64 * Everything granted. GitLab's REST API reports the viewer's role on the project but never whether
65 * they opened this issue, and an issue's author may close, reopen and edit it whatever their role.
66 * Withholding those controls from the one person entitled to them is the worse mistake, so they
67 * are offered and GitLab explains any refusal itself.
68 */
69const VIEWER_PERMISSIONS: IssueViewerPermissions = {
70 setState: true,
71 comment: true,
72 edit: true,
73 labels: true,
74 assignees: true,
75};
76​
77/** How many of a scope's templates are read in full; each one is a request of its own. */
78const TEMPLATE_LIMIT = 20;
79​
80const encodeBody = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
81​
82/** The REST API addresses a project by its URL-encoded full path. */
83function projectPath(scope: string): string {
84 return encodeURIComponent(scope.trim());
86​
87/** An issue key is its iid; anything else names no GitLab issue. */
88function parseNumber(key: string): number | null {
89 return /^[1-9]\d*$/.test(key) ? Number(key) : null;
91​
92/** A page cursor this tracker handed out, or null for anything it could not have issued. */
93function parsePage(cursor: string | undefined): number | null {
94 if (cursor === undefined) return 1;
95 return /^[1-9]\d{0,6}$/.test(cursor) ? Number(cursor) : null;
97​
98/**
99 * A comments cursor: the next REST page of notes and, after a colon, where GraphQL's awards for
100 * that page start. The two page alike, so a page of comments is joined with its own awards.
101 */
102function parseCommentsCursor(
103 cursor: string,
104): { readonly page: number; readonly awards: string | null } | null {
105 const match = /^([1-9]\d{0,6})(?::(.{1,512}))?$/.exec(cursor);
106 return match === null ? null : { page: Number(match[1]), awards: match[2] ?? null };
108​
109function commentsCursor(notesNext: string | null, awardsNext: string | null): string | null {
110 if (notesNext === null) return null;
111 return awardsNext === null ? notesNext : `${notesNext}:${awardsNext}`;
113​
114/**
115 * `glab api --include` output split into the body and GitLab's next page. GitLab can return a
116 * short page when it hides notes the viewer may not see, so only `X-Next-Page` says whether more
117 * exists; without headers a full page is taken as the sign.
118 */
119function splitPagedResponse(raw: string): {
120 readonly body: string;
121 readonly nextPage: number | null | undefined;
122} {
123 if (!raw.startsWith("HTTP/")) return { body: raw, nextPage: undefined };
124 const end = /\r?\n\r?\n/.exec(raw);
125 const headers = end === null ? raw : raw.slice(0, end.index);
126 const body = end === null ? "" : raw.slice(end.index + end[0].length);
127 const next = /^x-next-page:[ \t]*([1-9]\d{0,6})?[ \t]*\r?$/im.exec(headers);
128 return {
129 body,
130 nextPage: next === null ? undefined : next[1] === undefined ? null : Number(next[1]),
131 };
133​
134function query(params: ReadonlyArray<readonly [string, string]>): string {
135 return params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
137​
138function involvementParams(input: {
139 readonly involvement: IssueInvolvement;
140 readonly viewer: string;
141 readonly assignee?: string | undefined;
142}): ReadonlyArray<readonly [string, string]> {
143 switch (input.involvement) {
144 case "authored":
145 return [["author_username", input.viewer]];
146 case "assigned":
147 // A named assignee takes the one assignee parameter GitLab reads; `listIssues` keeps the
148 // viewer by dropping rows.
149 return input.assignee === undefined ? [["assignee_username", input.viewer]] : [];
150 // GitLab's `my_reaction_emoji` and `iteration` filters aside, nothing narrows to mentions, so
151 // the listing stays as wide as `all` rather than guessing.
152 case "mentioned":
153 case "all":
154 return [];
155 }
157​
158function reasonFor(error: GitLabCli.GitLabCliError): IssueTrackerError["reason"] {
159 switch (error._tag) {
160 case "GitLabCliUnavailableError":
161 return "missing-tool";
162 case "GitLabCliAuthenticationError":
163 return "unauthenticated";
164 case "GitLabCliRateLimitError":
165 return "rate-limited";
166 default:
167 return "failed";
168 }
170​
171export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> = Effect.gen(
172 function* () {
173 const gitlab = yield* GitLabCli.GitLabCli;
174​
175 const fail = (operation: string) => (error: GitLabCli.GitLabCliError) =>
176 new IssueTrackerError({
177 tracker: KIND,
178 operation,
179 reason: reasonFor(error),
180 detail: error.detail,
181 cause: error,
182 });
183​
184 const unreadable = (operation: string, cause: unknown) =>
185 new IssueTrackerError({
186 tracker: KIND,
187 operation,
188 reason: "failed",
189 detail: `GitLab returned an unreadable ${operation} response.`,
190 cause,
191 });
192​
193 const notFound = (operation: string) =>
194 new IssueTrackerError({
195 tracker: KIND,
196 operation,
197 reason: "not-found",
198 detail: "GitLab could not find the requested issue.",
199 });
200​
201 const refused = (operation: string, detail: string) =>
202 new IssueTrackerError({ tracker: KIND, operation, reason: "failed", detail });
203​
204 const api = (input: {
205 readonly cwd: string;
206 readonly host: string;
207 readonly operation: string;
208 readonly path: string;
209 readonly method?: string;
210 readonly body?: unknown;
211 readonly includeHeaders?: boolean;
212 }) =>
213 gitlab
214 .execute({
215 cwd: input.cwd,
216 host: input.host,
217 args: [
218 "api",
219 input.path,
220 ...(input.includeHeaders === true ? ["--include"] : []),
221 ...(input.method === undefined ? [] : ["--method", input.method]),
222 // A JSON body from stdin: argv is visible in process listings, and `glab api --input`
223 // sends no Content-Type of its own, which GitLab answers with HTTP 415.
224 ...(input.body === undefined
225 ? []
226 : ["--input", "-", "--header", "Content-Type: application/json"]),
227 ],
228 ...(input.body === undefined ? {} : { stdin: encodeBody(input.body) }),
229 })
230 .pipe(
231 Effect.map((result) => result.stdout.trim()),
232 Effect.mapError(fail(input.operation)),
233 );
234​
235 const read = <A>(input: {
236 readonly cwd: string;
237 readonly host: string;
238 readonly operation: string;
239 readonly path: string;
240 readonly method?: string;
241 readonly body?: unknown;
242 readonly includeHeaders?: boolean;
243 readonly decode: (raw: string) => Result.Result<A, unknown>;
244 }): Effect.Effect<A, IssueTrackerError> =>
245 api(input).pipe(
246 Effect.flatMap((raw) => {
247 const decoded = input.decode(raw);
248 return Result.isSuccess(decoded)
249 ? Effect.succeed(decoded.success)
250 : Effect.fail(unreadable(input.operation, decoded.failure));
251 }),
252 );
253​
254 const write = (input: {
255 readonly cwd: string;
256 readonly host: string;
257 readonly operation: string;
258 readonly path: string;
259 readonly method: string;
260 readonly body?: unknown;
261 }) => api(input).pipe(Effect.asVoid);
262​
263 /** The signed-in account; an answer naming nobody is a failure, since every comparison needs a login. */
264 const viewer = (input: {
265 readonly cwd: string;
266 readonly host: string;
267 readonly operation: string;
268 }): Effect.Effect<string, IssueTrackerError> =>
269 read({
270 cwd: input.cwd,
271 host: input.host,
272 operation: input.operation,
273 path: "user",
274 decode: decodeViewerJson,
275 }).pipe(
276 Effect.filterOrFail(
277 (login) => login !== null,
278 () => refused(input.operation, "GitLab returned no username for the signed-in account."),
279 ),
280 );
281​
282 /** The issue as REST addresses it, or a not-found for a key that names no iid. */
283 const issuePath = (
284 input: { readonly scope: string; readonly key: string },
285 operation: string,
286 ): Effect.Effect<{ readonly number: number; readonly path: string }, IssueTrackerError> => {
287 const number = parseNumber(input.key);
288 return number === null
289 ? Effect.fail(notFound(operation))
290 : Effect.succeed({ number, path: `projects/${projectPath(input.scope)}/issues/${number}` });
291 };
292​
293 /**
294 * GitLab writes assignees by numeric id, which is what the candidates carry as `id`. An issue
295 * names the people it already has by username, so a kept assignee is looked up.
296 */
297 const assigneeIds = (
298 input: { readonly cwd: string; readonly host: string },
299 operation: string,
300 assignees: ReadonlyArray<string>,
301 ): Effect.Effect<ReadonlyArray<number>, IssueTrackerError> =>
302 Effect.forEach(assignees, (assignee) =>
303 /^[1-9]\d*$/.test(assignee)
304 ? Effect.succeed(Number(assignee))
305 : read({
306 cwd: input.cwd,
307 host: input.host,
308 operation,
309 path: `users?${query([["username", assignee]])}`,
310 decode: decodeUserIdsJson,
311 }).pipe(
312 Effect.flatMap(([id]) =>
313 id === undefined
314 ? Effect.fail(refused(operation, `GitLab has no user named ${assignee}.`))
315 : Effect.succeed(id),
316 ),
317 ),
318 );
319​
320 const paged = (path: string, page: number) =>
321 `${path}?${query([
322 ["per_page", String(PAGE_SIZE)],
323 ["page", String(page)],
324 ])}`;
325​
326 const notesPage = (input: {
327 readonly cwd: string;
328 readonly host: string;
329 readonly path: string;
330 readonly page: number;
331 readonly operation: string;
332 readonly onlyActivity?: boolean;
333 }) =>
334 read({
335 cwd: input.cwd,
336 host: input.host,
337 operation: input.operation,
338 path: `${input.path}/notes?${query([
339 ["per_page", String(PAGE_SIZE)],
340 ["page", String(input.page)],
341 ["order_by", "created_at"],
342 ["sort", "asc"],
343 ...(input.onlyActivity === true ? [["activity_filter", "only_activity"] as const] : []),
344 ])}`,
345 includeHeaders: true,
346 decode: (raw) => {
347 const { body, nextPage } = splitPagedResponse(raw);
348 return Result.map(decodeIssueNotesJson(body), (notes) => {
349 const next =
350 nextPage === undefined
351 ? notes.rawCount < PAGE_SIZE
352 ? null
353 : input.page + 1
354 : nextPage;
355 return { ...notes, nextCursor: next === null ? null : String(next) };
356 });
357 },
358 });
359​
360 /** Every system note, wherever it falls among the comments, for the issue's timeline. */
361 const activity = Effect.fn("GitLabIssueTracker.activity")(function* (input: {
362 readonly cwd: string;
363 readonly host: string;
364 readonly path: string;
365 }) {
366 const events: Array<IssueEvent> = [];
367 let page = 1;
368 for (let count = 0; count < MAX_ACTIVITY_PAGES; count++) {
369 const notes = yield* notesPage({
370 ...input,
371 page,
372 operation: "getIssue",
373 onlyActivity: true,
374 });
375 events.push(...notes.events);
376 if (notes.nextCursor === null) break;
377 page = Number(notes.nextCursor);
378 }
379 return events;
380 });
381​
382 const awards = (input: {
383 readonly cwd: string;
384 readonly host: string;
385 readonly scope: string;
386 readonly number: number;
387 readonly operation: string;
388 readonly cursor?: string | undefined;
389 }) =>
390 read({
391 cwd: input.cwd,
392 host: input.host,
393 operation: input.operation,
394 path: "graphql",
395 method: "POST",
396 body: {
397 query: ISSUE_AWARD_EMOJI_GRAPHQL_QUERY,
398 variables: {
399 fullPath: input.scope.trim(),
400 iid: String(input.number),
401 cursor: input.cursor ?? null,
402 },
403 },
404 decode: decodeAwardEmojiJson,
405 });
406​
407 const linked = (input: {
408 readonly cwd: string;
409 readonly host: string;
410 readonly path: string;
411 readonly endpoint: "closed_by" | "related_merge_requests";
412 }) =>
413 read({
414 cwd: input.cwd,
415 host: input.host,
416 operation: "getIssue",
417 path: paged(`${input.path}/${input.endpoint}`, 1),
418 decode: (raw) => decodeLinkedMergeRequestsJson(raw, input.endpoint === "closed_by"),
419 });
420​
421 const template =
422 (input: { readonly cwd: string; readonly host: string; readonly scope: string }) =>
423 (entry: GitLabTemplateEntry) =>
424 read({
425 cwd: input.cwd,
426 host: input.host,
427 operation: "listTemplates",
428 path: `projects/${projectPath(input.scope)}/templates/issues/${encodeURIComponent(entry.key)}`,
429 decode: (raw) => decodeTemplateJson(entry, raw),
430 });
431​
432 return {
433 kind: KIND,
434 capabilities: CAPABILITIES,
435​
436 getViewer: (input) => viewer({ cwd: input.cwd, host: input.host, operation: "getViewer" }),
437​
438 listIssues: Effect.fn("GitLabIssueTracker.listIssues")(function* (input) {
439 const page = parsePage(input.cursor);
440 if (page === null) {
441 return yield* refused("listIssues", "The cursor was not one GitLab handed out.");
442 }
443 const perPage = Math.min(Math.max(input.limit, 1), PAGE_SIZE);
444 const text = input.query?.trim() ?? "";
445 const alsoAssignedTo =
446 input.involvement === "assigned" && input.assignee !== undefined
447 ? input.viewer.toLowerCase()
448 : null;
449 return yield* read({
450 cwd: input.cwd,
451 host: input.host,
452 operation: "listIssues",
453 path: `projects/${projectPath(input.scope)}/issues?${query([
454 ["state", input.state === "open" ? "opened" : input.state],
455 ...involvementParams(input),
456 // GitLab's own `search` matches title and description, URL-encoded like every other
457 // value here, so no text in it can become a parameter of its own.
458 ...(text.length === 0 ? [] : [["search", text] as const]),
459 ...(input.labels === undefined || input.labels.length === 0
460 ? []
461 : [["labels", input.labels.join(",")] as const]),
462 ...(input.assignee === undefined
463 ? []
464 : [["assignee_username", input.assignee] as const]),
465 ["order_by", input.sort === "created" ? "created_at" : "updated_at"],
466 ["sort", "desc"],
467 ["per_page", String(perPage)],
468 ["page", String(page)],
469 ])}`,
470 decode: decodeIssueListJson,
471 }).pipe(
472 Effect.map((list) => ({
473 items:
474 alsoAssignedTo === null
475 ? list.items
476 : list.items.filter((issue) =>
477 issue.assignees.some((actor) => actor.login.toLowerCase() === alsoAssignedTo),
478 ),
479 nextCursor: list.rawCount < perPage ? null : String(page + 1),
480 })),
481 );
482 }),
483​
484 getIssue: (input) =>
485 issuePath(input, "getIssue").pipe(
486 Effect.flatMap(({ number, path }) =>
487 Effect.all(
488 [
489 read({
490 cwd: input.cwd,
491 host: input.host,
492 operation: "getIssue",
493 path,
494 decode: decodeIssueDetailJson,
495 }),
496 viewer({ cwd: input.cwd, host: input.host, operation: "getIssue" }),
497 notesPage({
498 cwd: input.cwd,
499 host: input.host,
500 path,
501 page: 1,
502 operation: "getIssue",
503 }),
504 activity({ cwd: input.cwd, host: input.host, path }),
505 read({
506 cwd: input.cwd,
507 host: input.host,
508 operation: "getIssue",
509 path: paged(`${path}/resource_label_events`, 1),
510 decode: decodeLabelEventsJson,
511 }),
512 linked({ cwd: input.cwd, host: input.host, path, endpoint: "closed_by" }),
513 linked({
514 cwd: input.cwd,
515 host: input.host,
516 path,
517 endpoint: "related_merge_requests",
518 }),
519 awards({
520 cwd: input.cwd,
521 host: input.host,
522 scope: input.scope,
523 number,
524 operation: "getIssue",
525 }),
526 ],
527 { concurrency: 4 },
528 ),
529 ),
530 Effect.map(
531 ([
532 issue,
533 viewerLogin,
534 notes,
535 systemEvents,
536 labelEvents,
537 closing,
538 related,
539 awardPage,
540 ]) => {
541 const closingKeys = new Set(
542 closing.map((link) => `${link.repository}!${link.number}`),
543 );
544 return {
545 ...issue,
546 viewer: viewerLogin,
547 viewerPermissions: VIEWER_PERMISSIONS,
548 states: ISSUE_STATES,
549 reactions: awardPage.reactions,
550 comments: notes.comments.map((comment) => ({
551 ...comment,
552 reactions: awardPage.reactionsByNoteId.get(comment.id) ?? [],
553 })),
554 commentsCursor: commentsCursor(notes.nextCursor, awardPage.nextCursor),
555 events: [...systemEvents, ...labelEvents].sort((left, right) =>
556 left.createdAt.localeCompare(right.createdAt),
557 ),
558 // A merge request that closes the issue outranks its sighting as a mere mention.
559 linkedPullRequests: [
560 ...closing,
561 ...related.filter(
562 (link) => !closingKeys.has(`${link.repository}!${link.number}`),
563 ),
564 ],
565 };
566 },
567 ),
568 ),
569​
570 getComments: (input) => {
571 const cursor = parseCommentsCursor(input.cursor);
572 return cursor === null
573 ? Effect.fail(refused("getComments", "The cursor was not one GitLab handed out."))
574 : issuePath(input, "getComments").pipe(
575 Effect.flatMap(({ number, path }) =>
576 Effect.all(
577 [
578 notesPage({
579 cwd: input.cwd,
580 host: input.host,
581 path,
582 page: cursor.page,
583 operation: "getComments",
584 }),
585 // Without its awards cursor a later page's awards cannot be found.
586 cursor.awards === null && cursor.page > 1
587 ? Effect.succeed(null)
588 : awards({
589 cwd: input.cwd,
590 host: input.host,
591 scope: input.scope,
592 number,
593 operation: "getComments",
594 cursor: cursor.awards ?? undefined,
595 }),
596 ],
597 { concurrency: 2 },
598 ),
599 ),
600 Effect.map(([notes, awardPage]) => ({
601 comments: notes.comments.map((comment) => ({
602 ...comment,
603 reactions: awardPage?.reactionsByNoteId.get(comment.id) ?? [],
604 })),
605 nextCursor: commentsCursor(notes.nextCursor, awardPage?.nextCursor ?? null),
606 })),
607 );
608 },
609​
610 create: (input) =>
611 assigneeIds(input, "create", input.assignees).pipe(
612 Effect.flatMap((assignee_ids) =>
613 read({
614 cwd: input.cwd,
615 host: input.host,
616 operation: "create",
617 path: `projects/${projectPath(input.scope)}/issues`,
618 method: "POST",
619 body: {
620 title: input.title,
621 description: input.body,
622 labels: input.labels.join(","),
623 assignee_ids,
624 },
625 decode: decodeCreatedIssueJson,
626 }),
627 ),
628 Effect.map((issue) => ({
629 key: String(issue.number),
630 displayKey: `#${issue.number}`,
631 url: issue.url,
632 })),
633 ),
634​
635 comment: (input) =>
636 issuePath(input, "comment").pipe(
637 Effect.flatMap(({ path }) =>
638 write({
639 cwd: input.cwd,
640 host: input.host,
641 operation: "comment",
642 path: `${path}/notes`,
643 method: "POST",
644 body: { body: input.body },
645 }),
646 ),
647 ),
648​
649 update: (input) =>
650 Effect.all([
651 issuePath(input, "update"),
652 input.assignees === undefined
653 ? Effect.void
654 : assigneeIds(input, "update", input.assignees),
655 ]).pipe(
656 Effect.flatMap(([{ path }, assignee_ids]) =>
657 write({
658 cwd: input.cwd,
659 host: input.host,
660 operation: "update",
661 path,
662 method: "PUT",
663 body: {
664 ...(input.title === undefined ? {} : { title: input.title }),
665 ...(input.body === undefined ? {} : { description: input.body }),
666 ...(input.labels === undefined ? {} : { labels: input.labels.join(",") }),
667 ...(assignee_ids === undefined ? {} : { assignee_ids }),
668 },
669 }),
670 ),
671 ),
672​
673 setState: (input) => {
674 const wanted = ISSUE_STATES.find((state) => state.name === input.state);
675 if (wanted === undefined) {
676 return Effect.fail(refused("setState", `A GitLab issue has no "${input.state}" state.`));
677 }
678 return issuePath(input, "setState").pipe(
679 Effect.flatMap(({ path }) =>
680 write({
681 cwd: input.cwd,
682 host: input.host,
683 operation: "setState",
684 path,
685 method: "PUT",
686 body: { state_event: wanted.category === "closed" ? "close" : "reopen" },
687 }),
688 ),
689 );
690 },
691​
692 setReaction: Effect.fn("GitLabIssueTracker.setReaction")(function* (input) {
693 const { path } = yield* issuePath(input, "setReaction");
694 if (input.subjectId !== undefined && !/^[1-9]\d*$/.test(input.subjectId)) {
695 return yield* refused("setReaction", "The comment id names no GitLab note.");
696 }
697 const subject =
698 input.subjectId === undefined
699 ? `${path}/award_emoji`
700 : `${path}/notes/${input.subjectId}/award_emoji`;
701 if (input.reacted) {
702 return yield* write({
703 cwd: input.cwd,
704 host: input.host,
705 operation: "setReaction",
706 path: `${subject}?${query([["name", gitLabAwardName(input.content)]])}`,
707 method: "POST",
708 });
709 }
710 // GitLab deletes an award by its id and takes no emoji name there, so the reader's own
711 // award of that name is looked up first. Nothing to delete is success.
712 const login = yield* viewer({
713 cwd: input.cwd,
714 host: input.host,
715 operation: "setReaction",
716 });
717 for (let page = 1; ; page++) {
718 const own = yield* read({
719 cwd: input.cwd,
720 host: input.host,
721 operation: "setReaction",
722 path: paged(subject, page),
723 decode: (raw) => decodeOwnAwardIdJson(raw, { content: input.content, viewer: login }),
724 });
725 if (own.id !== null) {
726 return yield* write({
727 cwd: input.cwd,
728 host: input.host,
729 operation: "setReaction",
730 path: `${subject}/${own.id}`,
731 method: "DELETE",
732 });
733 }
734 // An empty raw page establishes exhaustion even when the host caps page size.
735 if (own.empty) return;
736 }
737 }),
738​
739 listTemplates: (input) =>
740 read({
741 cwd: input.cwd,
742 host: input.host,
743 operation: "listTemplates",
744 path: `projects/${projectPath(input.scope)}/templates/issues`,
745 decode: decodeTemplateEntriesJson,
746 }).pipe(
747 Effect.flatMap((entries) =>
748 Effect.forEach(entries.slice(0, TEMPLATE_LIMIT), template(input), { concurrency: 4 }),
749 ),
750 // GitLab has no switch that forbids an issue filed from nothing.
751 Effect.map((templates) => ({ templates, blankIssuesEnabled: true })),
752 ),
753​
754 listCandidates: (input) =>
755 Effect.all(
756 [
757 read({
758 cwd: input.cwd,
759 host: input.host,
760 operation: "listCandidates",
761 path: paged(`projects/${projectPath(input.scope)}/labels`, 1),
762 decode: decodeProjectLabelsJson,
763 }),
764 read({
765 cwd: input.cwd,
766 host: input.host,
767 operation: "listCandidates",
768 path: paged(`projects/${projectPath(input.scope)}/members/all`, 1),
769 decode: decodeProjectMembersJson,
770 }),
771 ],
772 { concurrency: 2 },
773 ).pipe(
774 Effect.map(([labels, assignees]) => ({
775 labels,
776 assignees,
777 truncated: labels.length >= PAGE_SIZE || assignees.length >= PAGE_SIZE,
778 })),
779 ),
780 };
781 },
782);