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