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

GitLabPullRequestProvider.ts

692 lines24.2 KB

1import { removeAgentCredits } from "@t3tools/source-control-core/server/mergeMessage";
2import { SourceControlProviderKind } from "@t3tools/contracts";
3import * as Cache from "effect/Cache";
4import * as Duration from "effect/Duration";
5import * as Effect from "effect/Effect";
6import * as Exit from "effect/Exit";
7import type {
8 PullRequestActor,
9 PullRequestCapabilities,
10 PullRequestReaction,
11 PullRequestThreadComment,
12 PullRequestViewerPermissions,
13} from "@t3tools/contracts";
14​
15import * as GitLabPullRequestCli from "./GitLabPullRequestCli.ts";
16import type { GitLabDiffRefs, GitLabMergeRequestListState } from "./gitLabMergeRequestJson.ts";
17import {
18 PullRequestProviderError,
19 type PullRequestProviderFailure,
20 type ProviderChangeRequestActivity,
21 type ProviderChangeRequestDetail,
22 type PullRequestProviderApi,
23} from "@t3tools/source-control-core/server/PullRequestProvider";
24import { definition } from "../shared/definition.ts";
25​
26const CAPABILITIES: PullRequestCapabilities = {
27 diff: true,
28 comment: true,
29 actions: [...definition.changeRequestActions],
30 mergeMethods: ["merge", "squash", "rebase"],
31 deleteBranch: true,
32 // GitLab has no merge-target-into-source operation.
33 updateMethods: ["rebase"],
34 search: true,
35 reactions: true,
36 mentions: true,
37 referenceSigils: ["#", "!"],
38 // GitLab's viewed marks live in browser-local storage.
39 viewedFiles: "environment",
40 review: {
41 inlineComment: true,
42 rangeComment: true,
43 reply: true,
44 resolve: true,
45 verdicts: ["comment", "approve", "request-changes"],
46 },
47 reviewers: { request: true, listCandidates: true, searchCandidates: true },
48 labels: true,
49 edit: { changeRequest: true, comment: true, maintainerEdits: true },
50};
51​
52const UNAVAILABLE_REQUIREMENT = {
53 missing:
54 "GitLab CLI (`glab`) is required to browse change requests on this host. Install it from https://gitlab.com/gitlab-org/cli and reload.",
55 unauthenticated: "GitLab CLI is not authenticated. Run `glab auth login` and retry.",
56};
57​
58/**
59 * The actions `user.can_merge` answers for. Rebasing writes to the source branch rather than to
60 * the target, so it is not literally the same permission — but GitLab reports nothing narrower,
61 * and someone it will not let land this change has no business rewriting its branch either.
62 * Reverting pushes a branch to the target project, which the same permission covers.
63 */
64const MERGE_ACTIONS: ReadonlySet<string> = new Set([
65 "merge",
66 "update-branch",
67 "enable-auto-merge",
68 "disable-auto-merge",
69 "revert",
70]);
71​
72/** Authors may close/reopen/change draft state regardless of role; REST omits authorship. */
73export function gitLabViewerPermissions(input: {
74 readonly viewerCanMerge: boolean;
75 readonly viewerCanEditMaintainerEdits?: boolean | undefined;
76 readonly viewerCanDeleteBranch?: boolean;
77 readonly viewerCanEditLabels?: boolean | undefined;
78}): PullRequestViewerPermissions {
79 return {
80 actions: CAPABILITIES.actions.filter((action) =>
81 action === "delete-branch"
82 ? input.viewerCanDeleteBranch === true
83 : !MERGE_ACTIONS.has(action) || input.viewerCanMerge,
84 ),
85 comment: true,
86 resolve: true,
87 verdicts: CAPABILITIES.review.verdicts,
88 requestReviewers: true,
89 maintainerEdits: input.viewerCanEditMaintainerEdits === true,
90 labels: input.viewerCanEditLabels === true,
91 ...(input.viewerCanMerge ? { updateMethods: CAPABILITIES.updateMethods } : {}),
92 };
94​
95/**
96 * One page view asks for the detail and then its checks within a second, and the poll that
97 * follows asks again. A minute keeps those to one `glab` call without hiding a pipeline for long;
98 * a refresh or a finished turn drops it sooner through `forgetChangeRequestReads`.
99 */
100const MERGE_REQUEST_DETAIL_TTL = Duration.minutes(1);
101/** A project's merge methods change in its settings, which nobody does between page views. */
102const PROJECT_MERGE_CAPABILITIES_TTL = Duration.minutes(15);
103const READ_CACHE_CAPACITY = 256;
104/** A host's GitLab version only changes on upgrade. */
105const GRAPHQL_LIST_SUPPORT_TTL = Duration.hours(1);
106​
107function gitLabProviderFailure(
108 error: GitLabPullRequestCli.GitLabPullRequestCliError,
109): PullRequestProviderFailure {
110 if (error._tag === "GitLabCliUnavailableError") return { reason: "missing-tool" };
111 if (error._tag === "GitLabCliAuthenticationError") return { reason: "unauthenticated" };
112 if (error._tag === "GitLabCliRateLimitError") return { reason: "rate-limited" };
113 if (error._tag === "GitLabMergeRequestNotFoundError") return { reason: "not-found" };
114 return { reason: "failed" };
116​
117// GitLab keeps a thread on the latest diff while its line survives, so older refs mean the code moved.
118const isOutdated = (
119 thread: GitLabDiffRefs | undefined,
120 current: GitLabDiffRefs | undefined,
121): boolean =>
122 thread !== undefined &&
123 current !== undefined &&
124 (thread.baseSha !== current.baseSha ||
125 thread.startSha !== current.startSha ||
126 thread.headSha !== current.headSha);
127​
128export const make = Effect.gen(function* () {
129 const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
130​
131 // Keyed on the checkout as well: `glab` picks the host and the account to answer as from the
132 // checkout's remote and config, so two checkouts may read the same project as different people.
133 const mergeRequestDetails = yield* Cache.makeWith(
134 (key: string) => {
135 const [cwd, repository, number, host] = JSON.parse(key) as [string, string, number, string];
136 return cli.getMergeRequestDetail({ cwd, repository, number, host });
137 },
138 {
139 capacity: READ_CACHE_CAPACITY,
140 timeToLive: (exit) => (Exit.isSuccess(exit) ? MERGE_REQUEST_DETAIL_TTL : Duration.zero),
141 },
142 );
143 const graphqlListSupport = yield* Cache.makeWith(
144 (key: string) => {
145 const [cwd, host] = JSON.parse(key) as [string, string | undefined];
146 // A host whose version read fails keeps failing it; remember REST rather than ask each poll.
147 return cli.supportsGraphqlList({ cwd, host }).pipe(
148 Effect.catchIf(
149 (cause) =>
150 cause._tag !== "GitLabCliUnavailableError" &&
151 cause._tag !== "GitLabCliAuthenticationError" &&
152 cause._tag !== "GitLabCliRateLimitError",
153 () => Effect.succeed(false),
154 ),
155 );
156 },
157 {
158 capacity: READ_CACHE_CAPACITY,
159 timeToLive: (exit) => (Exit.isSuccess(exit) ? GRAPHQL_LIST_SUPPORT_TTL : Duration.zero),
160 },
161 );
162 const projectMergeCapabilities = yield* Cache.makeWith(
163 (key: string) => {
164 const [cwd, repository, host] = JSON.parse(key) as [string, string, string];
165 return cli.getProjectMergeCapabilities({ cwd, repository, host });
166 },
167 {
168 capacity: READ_CACHE_CAPACITY,
169 timeToLive: (exit) => (Exit.isSuccess(exit) ? PROJECT_MERGE_CAPABILITIES_TTL : Duration.zero),
170 },
171 );
172​
173 const detailKey = (input: {
174 readonly cwd: string;
175 readonly host: string;
176 readonly repository: string;
177 readonly number: number;
178 }) => JSON.stringify([input.cwd, input.repository, input.number, input.host]);
179 const mergeRequestDetail = (input: {
180 readonly cwd: string;
181 readonly host: string;
182 readonly repository: string;
183 readonly number: number;
184 }) => Cache.get(mergeRequestDetails, detailKey(input));
185​
186 // Dropped on both sides, as the service does with its own reads: a read that starts while the
187 // write is in flight must not outlive it.
188 const writing =
189 <
190 I extends {
191 readonly cwd: string;
192 readonly host: string;
193 readonly repository: string;
194 readonly number: number;
195 },
196 A,
197 E,
198 >(
199 write: (input: I) => Effect.Effect<A, E>,
200 ) =>
201 (input: I): Effect.Effect<A, E> => {
202 const invalidate = Cache.invalidate(mergeRequestDetails, detailKey(input));
203 return invalidate.pipe(Effect.andThen(write(input)), Effect.ensuring(invalidate));
204 };
205​
206 const fail = (operation: string) => (error: GitLabPullRequestCli.GitLabPullRequestCliError) =>
207 new PullRequestProviderError({
208 provider: SourceControlProviderKind.make("gitlab"),
209 operation,
210 ...gitLabProviderFailure(error),
211 detail: error.detail,
212 cause: error,
213 });
214​
215 // Optional endpoints may lose part of the activity, but an unusable CLI or account must
216 // reach the caller so it can report authentication failures and pause a throttled host.
217 const recoverRead = <A>(
218 read: Effect.Effect<A, GitLabPullRequestCli.GitLabPullRequestCliError>,
219 fallback: A,
220 ) =>
221 read.pipe(
222 Effect.catch((error) => {
223 const { reason } = gitLabProviderFailure(error);
224 return reason === "rate-limited" ||
225 reason === "unauthenticated" ||
226 reason === "missing-tool"
227 ? Effect.fail(error)
228 : Effect.succeed(fallback);
229 }),
230 );
231​
232 // The rows were already read, so even a rate limit only leaves their states unknown.
233 const listStates = (input: Parameters<typeof cli.getListStates>[0]) =>
234 cli.getListStates(input).pipe(
235 Effect.catch((error) =>
236 Effect.logWarning("GitLab merge request approval and pipeline read failed", {
237 repository: input.repository,
238 reason: error._tag,
239 }).pipe(Effect.as<ReadonlyMap<number, GitLabMergeRequestListState>>(new Map())),
240 ),
241 );
242​
243 // REST omits line counts; the CLI recovers optional stats failures per batch.
244 const mergeRequestWithStats = (
245 input: {
246 readonly cwd: string;
247 readonly host: string;
248 readonly repository: string;
249 readonly number: number;
250 },
251 detail = cli.getMergeRequestDetail(input),
252 ) =>
253 Effect.all(
254 [
255 detail,
256 cli.listMergeRequestStats({ cwd: input.cwd, host: input.host, changeRequests: [input] }),
257 ],
258 {
259 concurrency: 2,
260 },
261 ).pipe(
262 Effect.map(([mergeRequest, [stat]]) =>
263 stat === undefined
264 ? mergeRequest
265 : { ...mergeRequest, additions: stat.additions, deletions: stat.deletions },
266 ),
267 );
268​
269 const provider: PullRequestProviderApi = {
270 kind: SourceControlProviderKind.make("gitlab"),
271 capabilities: CAPABILITIES,
272 mergeMessageRewrite: removeAgentCredits,
273 unavailableRequirement: UNAVAILABLE_REQUIREMENT,
274​
275 getViewer: (input) => cli.getViewerUsername(input).pipe(Effect.mapError(fail("getViewer"))),
276​
277 listChangeRequests: (input) =>
278 Cache.get(graphqlListSupport, JSON.stringify([input.cwd, input.host])).pipe(
279 // Without a known version the REST list still answers, only with fewer filters.
280 Effect.orElseSucceed(() => false),
281 Effect.flatMap((graphql) =>
282 cli.listMergeRequests({
283 cwd: input.cwd,
284 host: input.host,
285 repository: input.repository,
286 state: input.state,
287 involvement: input.involvement,
288 viewer: input.viewer,
289 limit: input.limit,
290 query: input.query,
291 cursor: input.cursor,
292 filters: input.filters,
293 graphql,
294 }),
295 ),
296 Effect.flatMap(({ listStates: carried, ...batch }) =>
297 (carried === undefined
298 ? listStates({
299 cwd: input.cwd,
300 host: input.host,
301 repository: input.repository,
302 numbers: batch.items.map((item) => item.number),
303 })
304 : Effect.succeed(carried)
305 ).pipe(
306 Effect.map((states) => ({
307 ...batch,
308 items: batch.items.map((item) => withListState(item, states)),
309 continues: true,
310 })),
311 ),
312 ),
313 Effect.mapError(fail("listChangeRequests")),
314 ),
315​
316 getFileStats: (input) =>
317 cli.getMergeRequestFileStats(input).pipe(Effect.mapError(fail("getFileStats"))),
318​
319 listChangeRequestStats: (input) =>
320 cli.listMergeRequestStats(input).pipe(Effect.mapError(fail("listChangeRequestStats"))),
321​
322 getChangeRequestChecks: (input) =>
323 mergeRequestDetail(input).pipe(
324 Effect.map(({ state, checks }) => ({ state, checks })),
325 Effect.mapError(fail("getChangeRequestChecks")),
326 ),
327​
328 // Merge settings only affect the detail panel's actions.
329 getChangeRequestPreview: (input) =>
330 cli
331 .getMergeRequestDetail({ ...input, maintainerEdits: false })
332 .pipe(Effect.mapError(fail("getChangeRequestPreview"))),
333​
334 getChangeRequestSummary: (input) =>
335 Effect.all(
336 [
337 mergeRequestWithStats(
338 input,
339 cli.getMergeRequestDetail({ ...input, maintainerEdits: false }),
340 ),
341 listStates({
342 cwd: input.cwd,
343 host: input.host,
344 repository: input.repository,
345 numbers: [input.number],
346 }),
347 ],
348 { concurrency: 2 },
349 ).pipe(
350 Effect.map(([mergeRequest, states]) => withListState(mergeRequest, states)),
351 Effect.mapError(fail("getChangeRequestSummary")),
352 ),
353​
354 getChangeRequest: (input) =>
355 Effect.all(
356 [
357 mergeRequestWithStats(input, mergeRequestDetail(input)),
358 Cache.get(
359 projectMergeCapabilities,
360 JSON.stringify([input.cwd, input.repository, input.host]),
361 ),
362 ],
363 { concurrency: 2 },
364 ).pipe(
365 Effect.mapError(fail("getChangeRequest")),
366 Effect.map(([mergeRequest, mergeCapabilities]): ProviderChangeRequestDetail => ({
367 ...mergeRequest,
368 mergeCapabilities,
369 viewerPermissions: gitLabViewerPermissions(mergeRequest),
370 // Missing divergence counts mean unknown, not up to date.
371 baseComparison:
372 mergeRequest.divergedCommits === undefined
373 ? "unknown"
374 : mergeRequest.divergedCommits > 0
375 ? "behind"
376 : "up-to-date",
377 ...(mergeRequest.divergedCommits === undefined
378 ? {}
379 : { behindBy: mergeRequest.divergedCommits }),
380 })),
381 ),
382​
383 getChangeRequestWatchFingerprint: (input) =>
384 cli
385 .getMergeRequestWatchFingerprint(input)
386 .pipe(Effect.mapError(fail("getChangeRequestWatchFingerprint"))),
387​
388 getChangeRequestActivity: (input) =>
389 Effect.all(
390 [
391 recoverRead(cli.listNotes(input), { comments: [], truncated: true }),
392 recoverRead(cli.listCommits(input), []),
393 recoverRead(cli.listDiscussions(input), {
394 threads: [],
395 diffRefsByThreadId: new Map(),
396 overviewFindingIds: [],
397 truncated: true,
398 }),
399 recoverRead(cli.listReactions(input), {
400 reactions: [] as ReadonlyArray<PullRequestReaction>,
401 reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
402 editedAtByNoteId: new Map<string, string>(),
403 botLogins: new Set<string>(),
404 }),
405 // Fresh, not the cached detail: refs from before a push would mark every thread outdated.
406 recoverRead(
407 cli.getMergeRequestDetail({ ...input, downstreamChecks: false }).pipe(
408 Effect.map((mergeRequest) => ({
409 url: mergeRequest.url,
410 diffRefs: mergeRequest.diffRefs,
411 })),
412 ),
413 null,
414 ),
415 ],
416 { concurrency: 5 },
417 ).pipe(
418 Effect.mapError(fail("getChangeRequestActivity")),
419 Effect.map(
420 ([notes, commits, discussions, awards, detail]): ProviderChangeRequestActivity => {
421 const noteUrl = (id: string) => (detail === null ? null : `${detail.url}#note_${id}`);
422 const findingIds = new Set(discussions.overviewFindingIds);
423 const edited = (id: string) => {
424 const editedAt = awards.editedAtByNoteId.get(id);
425 return editedAt === undefined ? {} : { editedAt };
426 };
427 const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));
428 const withBotFlag = (author: PullRequestActor | null) =>
429 author !== null && botLogins.has(author.login.toLowerCase())
430 ? { ...author, isBot: true }
431 : author;
432 const withNoteDetails = (comment: PullRequestThreadComment) => ({
433 ...comment,
434 ...edited(comment.id),
435 author: withBotFlag(comment.author),
436 url: noteUrl(comment.id),
437 reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
438 });
439 return {
440 reactions: awards.reactions,
441 comments: notes.comments.map((comment) => ({
442 ...comment,
443 ...(findingIds.has(comment.id) ? { kind: "review-comment" as const } : {}),
444 ...edited(comment.id),
445 author: withBotFlag(comment.author),
446 url: noteUrl(comment.id),
447 reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
448 })),
449 commentCount: notes.comments.length,
450 commentsTruncated: notes.truncated || discussions.truncated,
451 reviewThreads: discussions.threads.flatMap((thread) =>
452 thread.path === null
453 ? []
454 : [
455 {
456 ...thread,
457 isOutdated: isOutdated(
458 discussions.diffRefsByThreadId.get(thread.id),
459 detail?.diffRefs,
460 ),
461 comments: thread.comments.map(withNoteDetails),
462 },
463 ],
464 ),
465 overviewThreads: discussions.threads.flatMap((thread) =>
466 thread.path === null
467 ? [{ ...thread, comments: thread.comments.map(withNoteDetails) }]
468 : [],
469 ),
470 commits,
471 };
472 },
473 ),
474 ),
475​
476 // Straight from the host, never the shared read: this is what a write is refused or let
477 // through on, and access granted or withdrawn within the minute must count.
478 getViewerPermissions: (input) =>
479 cli
480 .getMergeRequestDetail({ ...input, downstreamChecks: false })
481 .pipe(Effect.mapError(fail("getViewerPermissions")), Effect.map(gitLabViewerPermissions)),
482​
483 forgetChangeRequestReads: (scope) =>
484 Cache.keys(mergeRequestDetails).pipe(
485 Effect.flatMap((keys) =>
486 Effect.forEach(
487 Array.from(keys).filter((key) => {
488 if (scope === undefined) return true;
489 const [, repository, number] = JSON.parse(key) as [string, string, number];
490 return (
491 repository.toLowerCase() === scope.repository.toLowerCase() &&
492 (scope.number === undefined || number === scope.number)
493 );
494 }),
495 (key) => Cache.invalidate(mergeRequestDetails, key),
496 { discard: true },
497 ),
498 ),
499 ),
500​
501 getDiff: (input) => cli.getMergeRequestDiff(input).pipe(Effect.mapError(fail("getDiff"))),
502​
503 getDiffFileContents: (input) =>
504 cli.getMergeRequestDiffFileContents(input).pipe(Effect.mapError(fail("getDiffFileContents"))),
505​
506 getFileRevisions: (input) =>
507 cli.getFileRevisions(input).pipe(
508 Effect.mapError(fail("getFileRevisions")),
509 Effect.map((revisions) => ({ revisions })),
510 ),
511​
512 // MR reviewers are users; groups belong to approval rules.
513 listReviewerCandidates: (input) =>
514 cli
515 .listReviewerCandidates({
516 cwd: input.cwd,
517 host: input.host,
518 repository: input.repository,
519 number: input.number,
520 query: input.query,
521 })
522 .pipe(Effect.mapError(fail("listReviewerCandidates"))),
523​
524 listLabelCandidates: (input) =>
525 cli
526 .listLabelCandidates({
527 cwd: input.cwd,
528 host: input.host,
529 repository: input.repository,
530 number: input.number,
531 })
532 .pipe(Effect.mapError(fail("listLabelCandidates"))),
533​
534 setLabels: writing((input) =>
535 cli
536 .setLabels({
537 cwd: input.cwd,
538 host: input.host,
539 repository: input.repository,
540 number: input.number,
541 labels: input.labels,
542 applied: input.applied,
543 })
544 .pipe(Effect.mapError(fail("setLabels"))),
545 ),
546​
547 listRepositoryLabels: (input) =>
548 cli
549 .listProjectLabels({
550 cwd: input.cwd,
551 host: input.host,
552 repository: input.repository,
553 search: input.query,
554 })
555 .pipe(Effect.mapError(fail("listRepositoryLabels"))),
556​
557 searchRepositoryAuthors: (input) =>
558 cli
559 .listProjectUsers({
560 cwd: input.cwd,
561 host: input.host,
562 repository: input.repository,
563 search: input.query,
564 })
565 .pipe(Effect.mapError(fail("searchRepositoryAuthors"))),
566​
567 searchRepositoryReferences: (input) =>
568 cli
569 .searchProjectReferences({
570 cwd: input.cwd,
571 host: input.host,
572 repository: input.repository,
573 search: input.query,
574 sigil: input.sigil,
575 })
576 .pipe(Effect.mapError(fail("searchRepositoryReferences"))),
577​
578 setReviewerRequest: writing((input) =>
579 cli
580 .setReviewerRequest({
581 cwd: input.cwd,
582 host: input.host,
583 repository: input.repository,
584 number: input.number,
585 reviewers: input.reviewers,
586 requested: input.requested,
587 })
588 .pipe(Effect.mapError(fail("setReviewerRequest"))),
589 ),
590​
591 runAction: writing((input) =>
592 cli
593 .runMergeRequestAction({
594 cwd: input.cwd,
595 host: input.host,
596 repository: input.repository,
597 number: input.number,
598 action: input.action,
599 ...(input.mergeMethod === undefined ? {} : { mergeMethod: input.mergeMethod }),
600 ...(input.removeAgentCreditsOnMerge === true ? { removeAgentCreditsOnMerge: true } : {}),
601 })
602 .pipe(Effect.mapError(fail("runAction"))),
603 ),
604​
605 updateChangeRequest: writing((input) =>
606 cli
607 .updateMergeRequest({
608 cwd: input.cwd,
609 host: input.host,
610 repository: input.repository,
611 number: input.number,
612 ...(input.title === undefined ? {} : { title: input.title }),
613 ...(input.body === undefined ? {} : { description: input.body }),
614 ...(input.maintainerCanModify === undefined
615 ? {}
616 : { allowCollaboration: input.maintainerCanModify }),
617 })
618 .pipe(Effect.mapError(fail("updateChangeRequest"))),
619 ),
620​
621 comment: writing((input) =>
622 cli.commentOnMergeRequest(input).pipe(Effect.mapError(fail("comment"))),
623 ),
624​
625 updateComment: writing((input) =>
626 cli
627 .updateNote({
628 cwd: input.cwd,
629 host: input.host,
630 repository: input.repository,
631 number: input.number,
632 noteId: input.commentId,
633 body: input.body,
634 })
635 .pipe(Effect.mapError(fail("updateComment"))),
636 ),
637​
638 submitReview: writing((input) =>
639 cli.submitReview(input).pipe(Effect.mapError(fail("submitReview"))),
640 ),
641​
642 replyToThread: writing((input) =>
643 cli
644 .replyToDiscussion({
645 cwd: input.cwd,
646 host: input.host,
647 repository: input.repository,
648 number: input.number,
649 discussionId: input.threadId,
650 body: input.body,
651 })
652 .pipe(Effect.mapError(fail("replyToThread"))),
653 ),
654​
655 setReaction: writing((input) =>
656 cli
657 .setReaction({
658 cwd: input.cwd,
659 host: input.host,
660 repository: input.repository,
661 number: input.number,
662 ...(input.subjectId === undefined ? {} : { noteId: input.subjectId }),
663 content: input.content,
664 reacted: input.reacted,
665 })
666 .pipe(Effect.mapError(fail("setReaction"))),
667 ),
668​
669 setThreadResolution: writing((input) =>
670 cli
671 .setDiscussionResolution({
672 cwd: input.cwd,
673 host: input.host,
674 repository: input.repository,
675 number: input.number,
676 discussionId: input.threadId,
677 resolved: input.resolved,
678 })
679 .pipe(Effect.mapError(fail("setThreadResolution"))),
680 ),
681 };
682​
683 return provider;
684});
685​
686function withListState<Item extends { readonly number: number }>(
687 item: Item,
688 states: ReadonlyMap<number, GitLabMergeRequestListState>,
689): Item & Partial<GitLabMergeRequestListState> {
690 const state = states.get(item.number);
691 return state === undefined ? item : { ...item, ...state };