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

gitCafePullRequestJson.ts

645 lines21.5 KB

1import { quoteGitPatchPath } from "@t3tools/shared/gitPatchPath";
2import { sortChecks } from "@t3tools/source-control-core/server/pullRequestChecks";
3import * as DateTime from "effect/DateTime";
4import * as Schema from "effect/Schema";
5import {
6 IsoDateTime,
7 NonNegativeInt,
8 PositiveInt,
9 TrimmedNonEmptyString,
10 type PullRequestActor,
11 type PullRequestCheck,
12 type PullRequestComment,
13 type PullRequestReaction,
14 type PullRequestReactionContent,
15 type PullRequestReviewerCandidate,
16 type PullRequestReviewThread,
17 type PullRequestViewerPermissions,
18} from "@t3tools/contracts";
19import type {
20 ProviderChangeRequest,
21 ProviderChangeRequestActivity,
22 ProviderChangeRequestStack,
23 ProviderDiffSlice,
24} from "@t3tools/source-control-core/server/PullRequestProvider";
25​
26const Actor = Schema.Union([
27 Schema.Struct({
28 kind: Schema.Literal("local"),
29 actorId: Schema.String,
30 handle: TrimmedNonEmptyString,
31 displayName: Schema.NullOr(Schema.String),
32 avatarUrl: Schema.NullOr(Schema.String),
33 bot: Schema.optional(Schema.Boolean),
34 }),
35 Schema.Struct({
36 kind: Schema.Literal("github"),
37 actorId: Schema.String,
38 login: TrimmedNonEmptyString,
39 avatarUrl: Schema.NullOr(Schema.String),
40 linkedProfile: Schema.optional(
41 Schema.NullOr(
42 Schema.Struct({ handle: TrimmedNonEmptyString, actorId: Schema.optional(Schema.String) }),
43 ),
44 ),
45 }),
46 Schema.Struct({ kind: Schema.Literal("unavailable"), actorId: Schema.String }),
47]);
48type Actor = typeof Actor.Type;
49​
50const PullState = Schema.Literals(["open", "closed", "merged"]);
51​
52export const GitCafePull = Schema.Struct({
53 id: TrimmedNonEmptyString,
54 number: PositiveInt,
55 title: TrimmedNonEmptyString,
56 state: PullState,
57 draft: Schema.Boolean,
58 sourceBranch: Schema.String,
59 targetBranch: Schema.String,
60 headOid: Schema.NullOr(Schema.String),
61 author: Actor,
62 createdAt: IsoDateTime,
63 updatedAt: IsoDateTime,
64 version: NonNegativeInt,
65 reviewers: Schema.optional(Schema.Array(Schema.Struct({ actor: Actor }))),
66 labels: Schema.optional(
67 Schema.Array(
68 Schema.Struct({ name: TrimmedNonEmptyString, color: Schema.NullOr(Schema.String) }),
69 ),
70 ),
71});
72export type GitCafePull = typeof GitCafePull.Type;
73​
74export const GitCafePulls = Schema.Struct({
75 items: Schema.Array(GitCafePull),
76 next: Schema.NullOr(Schema.String),
77});
78​
79export const GitCafePullDetail = Schema.Struct({
80 ...GitCafePull.fields,
81 description: Schema.NullOr(Schema.String),
82 closedAt: Schema.NullOr(IsoDateTime),
83 mergedAt: Schema.NullOr(IsoDateTime),
84 sourceRepo: Schema.NullOr(Schema.Struct({ owner: Schema.String, name: Schema.String })),
85 observedBaseOid: Schema.optional(Schema.NullOr(Schema.String)),
86 mergeRoute: Schema.optional(Schema.Literals(["native", "provider", "unsupported"])),
87 lockedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
88 viewerActorId: Schema.optional(Schema.NullOr(Schema.String)),
89 // Set once GitHub has merged a pull request GitCafe routed there, which can be before the
90 // sync brings the merged state back.
91 providerMerge: Schema.optional(Schema.NullOr(Schema.Struct({ mergedAt: IsoDateTime }))),
92 capabilities: Schema.Struct({
93 comment: Schema.Boolean,
94 review: Schema.Boolean,
95 merge: Schema.Boolean,
96 edit: Schema.Boolean,
97 moderate: Schema.Boolean,
98 }),
99});
100export type GitCafePullDetail = typeof GitCafePullDetail.Type;
101​
102const CommentCapabilities = Schema.Struct({
103 edit: Schema.Boolean,
104 hide: Schema.Boolean,
105 unhide: Schema.Boolean,
106 delete: Schema.Boolean,
107 resolve: Schema.Boolean,
108 unresolve: Schema.Boolean,
109});
110​
111const GitCafeComment = Schema.Struct({
112 id: TrimmedNonEmptyString,
113 threadId: TrimmedNonEmptyString,
114 version: Schema.optional(NonNegativeInt),
115 author: Actor,
116 body: Schema.NullOr(Schema.String),
117 createdAt: IsoDateTime,
118 path: Schema.NullOr(Schema.String),
119 // The API allows any integer here; only a positive line anchors a review thread.
120 line: Schema.NullOr(Schema.Int),
121 side: Schema.NullOr(Schema.Literals(["left", "right"])),
122 commitOid: Schema.NullOr(Schema.String),
123 resolvedAt: Schema.NullOr(IsoDateTime),
124 capabilities: Schema.optional(CommentCapabilities),
125});
126type GitCafeComment = typeof GitCafeComment.Type;
127​
128export const GitCafeComments = Schema.Struct({
129 items: Schema.Array(GitCafeComment),
130 next: Schema.NullOr(Schema.String),
131});
132​
133export const GitCafeReviews = Schema.Struct({
134 items: Schema.Array(
135 Schema.Struct({
136 id: TrimmedNonEmptyString,
137 author: Actor,
138 body: Schema.NullOr(Schema.String),
139 verdict: Schema.Literals(["approve", "request_changes", "comment"]),
140 dismissedAt: Schema.NullOr(IsoDateTime),
141 createdAt: IsoDateTime,
142 }),
143 ),
144 next: Schema.NullOr(Schema.String),
145});
146​
147export const GitCafeCommits = Schema.Struct({
148 items: Schema.Array(
149 Schema.Struct({ oid: TrimmedNonEmptyString, summary: Schema.String, time: Schema.Finite }),
150 ),
151 truncated: Schema.Boolean,
152 next: Schema.NullOr(Schema.String),
153 headOid: Schema.String,
154});
155​
156export const GitCafeLabels = Schema.Struct({
157 items: Schema.Array(
158 Schema.Struct({
159 id: TrimmedNonEmptyString,
160 name: TrimmedNonEmptyString,
161 color: Schema.NullOr(Schema.String),
162 description: Schema.optional(Schema.NullOr(Schema.String)),
163 }),
164 ),
165 next: Schema.NullOr(Schema.String),
166});
167​
168/** A pull request's reviewers and its reviewer candidates, each actor under its id. */
169export const GitCafeActorEntries = Schema.Struct({
170 items: Schema.Array(Schema.Struct({ id: TrimmedNonEmptyString, actor: Actor })),
171 next: Schema.NullOr(Schema.String),
172});
173​
174export const GitCafeReactions = Schema.Struct({
175 items: Schema.Array(
176 Schema.Struct({
177 subject: Schema.Struct({
178 kind: Schema.Literals(["issue", "issue_comment", "pull_request", "pull_request_comment"]),
179 id: TrimmedNonEmptyString,
180 }),
181 emoji: Schema.Union([
182 Schema.Struct({ kind: Schema.Literal("unicode"), value: TrimmedNonEmptyString }),
183 Schema.Struct({ kind: Schema.Literal("custom"), id: TrimmedNonEmptyString }),
184 ]),
185 count: PositiveInt,
186 viewerReactionId: Schema.NullOr(Schema.String),
187 reactors: Schema.Array(Actor),
188 }),
189 ),
190 next: Schema.NullOr(Schema.String),
191});
192​
193const GitCafeStack = Schema.Struct({
194 id: TrimmedNonEmptyString,
195 number: PositiveInt,
196 revision: PositiveInt,
197 landingBase: Schema.String,
198 members: Schema.Array(
199 Schema.Struct({
200 pullRequestNumber: PositiveInt,
201 title: Schema.String,
202 state: PullState,
203 draft: Schema.Boolean,
204 sourceBranch: Schema.String,
205 headOid: Schema.optional(Schema.String),
206 position: PositiveInt,
207 }),
208 ),
209});
210export type GitCafeStack = typeof GitCafeStack.Type;
211​
212export const GitCafeStackEnvelope = Schema.Struct({ stack: Schema.NullOr(GitCafeStack) });
213​
214const GitCafeDiffFile = Schema.Struct({
215 path: TrimmedNonEmptyString,
216 oldPath: Schema.optional(Schema.NullOr(Schema.String)),
217 status: Schema.optional(
218 Schema.Literals([
219 "added",
220 "deleted",
221 "modified",
222 "typeChanged",
223 "conflicted",
224 "renamed",
225 "copied",
226 ]),
227 ),
228 additions: Schema.optional(NonNegativeInt),
229 deletions: Schema.optional(NonNegativeInt),
230 binary: Schema.optional(Schema.Boolean),
231 tooLarge: Schema.optional(Schema.Boolean),
232 hunksOmitted: Schema.optional(Schema.Boolean),
233 isSubmodule: Schema.optional(Schema.Boolean),
234 oldOid: Schema.optional(Schema.String),
235 newOid: Schema.optional(Schema.String),
236 // Structural pages (`/changes`, `/compare`) list files without hunks; the batched reads fill them.
237 hunks: Schema.optional(
238 Schema.Array(
239 Schema.Struct({
240 oldStart: NonNegativeInt,
241 oldLines: NonNegativeInt,
242 newStart: NonNegativeInt,
243 newLines: NonNegativeInt,
244 lines: Schema.Array(Schema.Struct({ origin: Schema.String, content: Schema.String })),
245 }),
246 ),
247 ),
248});
249export type GitCafeDiffFile = typeof GitCafeDiffFile.Type;
250export const GitCafeDiffFiles = Schema.Array(GitCafeDiffFile);
251​
252export const GitCafeDiff = Schema.Struct({
253 items: GitCafeDiffFiles,
254 truncated: Schema.optional(Schema.Boolean),
255});
256​
257export const GitCafeChecks = Schema.Struct({
258 items: Schema.Array(
259 Schema.Struct({
260 name: TrimmedNonEmptyString,
261 status: Schema.Literals(["queued", "in_progress", "completed"]),
262 conclusion: Schema.NullOr(Schema.String),
263 summary: Schema.NullOr(Schema.String),
264 detailsUrl: Schema.NullOr(Schema.String),
265 }),
266 ),
267 next: Schema.NullOr(Schema.String),
268});
269​
270/** A user search answer and a collaborator page carry the same fields a picker shows. */
271export const GitCafePeople = Schema.Struct({
272 items: Schema.Array(
273 Schema.Struct({
274 handle: TrimmedNonEmptyString,
275 displayName: Schema.optional(Schema.NullOr(Schema.String)),
276 avatarUrl: Schema.optional(Schema.NullOr(Schema.String)),
277 }),
278 ),
279 next: Schema.NullOr(Schema.String),
280});
281​
282export function toPeople(
283 people: typeof GitCafePeople.Type,
284 host: string,
285): ReadonlyArray<PullRequestActor> {
286 return people.items.map((person) => ({
287 login: person.handle,
288 name: person.displayName ?? null,
289 avatarUrl: person.avatarUrl == null ? null : new URL(person.avatarUrl, `https://${host}`).href,
290 }));
292​
293interface RepositoryOnHost {
294 readonly repository: string;
295 readonly host: string;
297​
298function toActor(actor: Actor, host: string): PullRequestActor | null {
299 if (actor.kind === "unavailable") return null;
300 return {
301 login: actor.kind === "local" ? actor.handle : actor.login,
302 name: actor.kind === "local" ? actor.displayName : null,
303 ...(actor.kind === "local" && actor.bot === true ? { isBot: true } : {}),
304 // GitCafe serves its own avatars by path, so a relative one is read against the host.
305 avatarUrl: actor.avatarUrl === null ? null : new URL(actor.avatarUrl, `https://${host}`).href,
306 };
308​
309export function toReviewers(
310 pull: Pick<GitCafePull, "reviewers">,
311 host: string,
312): ReadonlyArray<PullRequestActor> {
313 return (pull.reviewers ?? []).flatMap(({ actor }) => {
314 const reviewer = toActor(actor, host);
315 return reviewer === null ? [] : [reviewer];
316 });
318​
319export function toReviewerCandidates(
320 candidates: typeof GitCafeActorEntries.Type,
321 input: {
322 readonly requested: ReadonlySet<string>;
323 readonly authorActorId: string;
324 readonly host: string;
325 },
326): ReadonlyArray<PullRequestReviewerCandidate> {
327 return candidates.items.flatMap(({ id, actor }) => {
328 const reviewer = id === input.authorActorId ? null : toActor(actor, input.host);
329 return reviewer === null
330 ? []
331 : [{ ...reviewer, id, kind: "user" as const, isRequested: input.requested.has(id) }];
332 });
334​
335function reviewerLogins(actor: Actor, host: string): ReadonlyArray<string> {
336 const reviewer = toActor(actor, host);
337 if (reviewer === null) return [];
338 return actor.kind === "github" && actor.linkedProfile
339 ? [reviewer.login, actor.linkedProfile.handle]
340 : [reviewer.login];
342​
343export function toChangeRequest(
344 pull: GitCafePull,
345 target: RepositoryOnHost,
346): ProviderChangeRequest {
347 return {
348 number: pull.number,
349 title: pull.title,
350 url: `https://${target.host}/${target.repository}/pulls/${pull.number}`,
351 author: toActor(pull.author, target.host),
352 headBranch: pull.sourceBranch,
353 baseBranch: pull.targetBranch,
354 state: pull.state,
355 isDraft: pull.draft,
356 mergeability: "unknown",
357 additions: 0,
358 deletions: 0,
359 createdAt: pull.createdAt,
360 updatedAt: pull.updatedAt,
361 reviewRequestLogins: (pull.reviewers ?? []).flatMap(({ actor }) =>
362 reviewerLogins(actor, target.host),
363 ),
364 labels: (pull.labels ?? []).map(({ name, color }) => ({ name, color })),
365 };
367​
368function isViewerAuthor(detail: GitCafePullDetail): boolean {
369 const viewer = detail.viewerActorId;
370 if (viewer == null) return false;
371 const { author } = detail;
372 return (
373 author.actorId === viewer ||
374 (author.kind === "github" && author.linkedProfile?.actorId === viewer)
375 );
377​
378export function toViewerPermissions(detail: GitCafePullDetail): PullRequestViewerPermissions {
379 const { comment, edit, review, merge, moderate } = detail.capabilities;
380 const open = comment && (detail.lockedAt == null || moderate);
381 return {
382 actions: [
383 ...(edit && detail.state === "open"
384 ? ([detail.draft ? "ready" : "draft", "close"] as const)
385 : edit && detail.state === "closed"
386 ? (["reopen"] as const)
387 : []),
388 ...(merge && detail.state === "open" && !detail.draft ? (["merge"] as const) : []),
389 ],
390 stackRebase: merge,
391 comment: open,
392 resolve: open,
393 // GitCafe refuses an author's approval and request for changes, as GitHub does.
394 verdicts: !review
395 ? []
396 : isViewerAuthor(detail)
397 ? ["comment"]
398 : ["approve", "request-changes", "comment"],
399 requestReviewers: edit && detail.state === "open",
400 labels: edit && detail.state === "open",
401 editChangeRequest: edit,
402 // GitCafe's only branch update moves a whole stack.
403 updateMethods: [],
404 };
406​
407const REACTIONS: Readonly<Record<string, PullRequestReactionContent>> = {
408 "πŸ‘": "thumbs-up",
409 "πŸ‘Ž": "thumbs-down",
410 "πŸ˜„": "laugh",
411 "πŸŽ‰": "hooray",
412 "πŸ˜•": "confused",
413 "❀": "heart",
414 "πŸš€": "rocket",
415 "πŸ‘€": "eyes",
416};
417​
418export const REACTION_EMOJI: Readonly<Record<PullRequestReactionContent, string>> = {
419 "thumbs-up": "πŸ‘",
420 "thumbs-down": "πŸ‘Ž",
421 laugh: "πŸ˜„",
422 hooray: "πŸŽ‰",
423 confused: "πŸ˜•",
424 heart: "❀️",
425 rocket: "πŸš€",
426 eyes: "πŸ‘€",
427};
428​
429export function reactionContent(emoji: string): PullRequestReactionContent | undefined {
430 return REACTIONS[emoji.replaceAll("\uFE0F", "")];
432​
433function toReactions(data: typeof GitCafeReactions.Type, host: string) {
434 const reactions: Array<PullRequestReaction> = [];
435 const byComment = new Map<string, Array<PullRequestReaction>>();
436 for (const item of data.items) {
437 const content = item.emoji.kind === "unicode" ? reactionContent(item.emoji.value) : undefined;
438 if (content === undefined) continue;
439 const reaction: PullRequestReaction = {
440 content,
441 count: item.count,
442 actors: item.reactors.flatMap((actor) => {
443 const reactor = toActor(actor, host);
444 return reactor === null ? [] : [reactor.login];
445 }),
446 viewerHasReacted: item.viewerReactionId !== null,
447 };
448 if (item.subject.kind === "pull_request") reactions.push(reaction);
449 else if (item.subject.kind === "pull_request_comment")
450 byComment.set(item.subject.id, [...(byComment.get(item.subject.id) ?? []), reaction]);
451 }
452 return { reactions, byComment };
454​
455const REVIEW_STATES = {
456 approve: "approved",
457 request_changes: "changes_requested",
458 comment: "commented",
459} as const;
460​
461export function toActivity(input: {
462 readonly comments: typeof GitCafeComments.Type;
463 readonly reviews: typeof GitCafeReviews.Type;
464 readonly commits: typeof GitCafeCommits.Type;
465 readonly reactions?: typeof GitCafeReactions.Type;
466 readonly headOid?: string;
467 readonly host: string;
468}): ProviderChangeRequestActivity {
469 const { host } = input;
470 const reactions = input.reactions === undefined ? undefined : toReactions(input.reactions, host);
471 const remark = (comment: GitCafeComment) => ({
472 id: comment.id,
473 author: toActor(comment.author, host),
474 body: comment.body ?? "",
475 createdAt: comment.createdAt,
476 url: null,
477 ...(comment.capabilities === undefined ? {} : { canEdit: comment.capabilities.edit }),
478 ...(reactions === undefined ? {} : { reactions: reactions.byComment.get(comment.id) ?? [] }),
479 });
480 const ordered = input.comments.items.toSorted((a, b) => a.createdAt.localeCompare(b.createdAt));
481 const groups = new Map<string, Array<GitCafeComment>>();
482 for (const comment of ordered) {
483 if (!comment.path || comment.line === null || comment.line < 1 || comment.side === null)
484 continue;
485 groups.set(comment.threadId, [...(groups.get(comment.threadId) ?? []), comment]);
486 }
487 const reviewThreads = [...groups.values()].map((group): PullRequestReviewThread => {
488 const first = group[0]!;
489 const latest = group.at(-1)!;
490 const root = group.find((comment) => comment.id === comment.threadId);
491 return {
492 id: first.threadId,
493 path: first.path!,
494 line: first.line,
495 side: first.side!,
496 isResolved: root?.resolvedAt != null,
497 isOutdated:
498 input.headOid !== undefined &&
499 latest.commitOid !== null &&
500 latest.commitOid !== input.headOid,
501 comments: group.map(remark),
502 ...(root?.capabilities === undefined
503 ? {}
504 : {
505 canResolve:
506 root.resolvedAt === null ? root.capabilities.resolve : root.capabilities.unresolve,
507 }),
508 };
509 });
510 const comments: Array<PullRequestComment> = [
511 ...ordered.map((comment) => ({
512 ...remark(comment),
513 kind: comment.path === null ? ("issue-comment" as const) : ("review-comment" as const),
514 path: comment.path,
515 reviewState: null,
516 })),
517 ...input.reviews.items.map((review) => ({
518 id: review.id,
519 kind: "review" as const,
520 author: toActor(review.author, host),
521 body: review.body ?? "",
522 createdAt: review.createdAt,
523 url: null,
524 path: null,
525 reviewState: review.dismissedAt !== null ? "dismissed" : REVIEW_STATES[review.verdict],
526 })),
527 ];
528 return {
529 comments: comments.toSorted((a, b) => a.createdAt.localeCompare(b.createdAt)),
530 commentCount: input.comments.items.length + input.reviews.items.length,
531 commentsTruncated: input.comments.next !== null || input.reviews.next !== null,
532 reviewThreads,
533 commits: input.commits.items.map((commit) => ({
534 oid: commit.oid,
535 messageHeadline: commit.summary,
536 committedDate: DateTime.formatIso(DateTime.makeUnsafe(commit.time * 1_000)),
537 })),
538 ...(reactions === undefined ? {} : { reactions: reactions.reactions }),
539 };
541​
542export function toStack(stack: GitCafeStack, target: RepositoryOnHost): ProviderChangeRequestStack {
543 return {
544 id: stack.id,
545 number: stack.number,
546 url: `https://${target.host}/${target.repository}/stacks/${stack.number}`,
547 base: stack.landingBase,
548 layers: stack.members
549 .toSorted((a, b) => a.position - b.position)
550 .map((member) => ({
551 number: member.pullRequestNumber,
552 title: member.title,
553 headBranch: member.sourceBranch,
554 state: member.state,
555 isDraft: member.draft,
556 ...(member.headOid === undefined ? {} : { headSha: member.headOid }),
557 })),
558 };
560​
561export function toDiff(diff: typeof GitCafeDiff.Type): ProviderDiffSlice {
562 const chunks: Array<string> = [];
563 const omittedFileStats: Array<{ path: string; additions: number; deletions: number }> = [];
564 for (const file of diff.items) {
565 const oldPath = file.oldPath ?? file.path;
566 const a = quoteGitPatchPath(`a/${oldPath}`);
567 const b = quoteGitPatchPath(`b/${file.path}`);
568 const before = file.status === "added" ? "/dev/null" : a;
569 const after = file.status === "deleted" ? "/dev/null" : b;
570 const mode = file.isSubmodule ? "160000" : "100644";
571 const lines = [`diff --git ${a} ${b}`];
572 if (file.status === "added") lines.push(`new file mode ${mode}`);
573 if (file.status === "deleted") lines.push(`deleted file mode ${mode}`);
574 if (file.status === "renamed" || file.status === "copied") {
575 const action = file.status === "renamed" ? "rename" : "copy";
576 lines.push(
577 `${action} from ${quoteGitPatchPath(oldPath)}`,
578 `${action} to ${quoteGitPatchPath(file.path)}`,
579 );
580 }
581 if (file.binary) {
582 lines.push(`Binary files ${before} and ${after} differ`);
583 } else if (file.tooLarge || file.hunksOmitted) {
584 omittedFileStats.push({
585 path: file.path,
586 additions: file.additions ?? 0,
587 deletions: file.deletions ?? 0,
588 });
589 } else if (file.isSubmodule) {
590 const hasOld = file.status !== "added" && file.oldOid !== undefined;
591 const hasNew = file.status !== "deleted" && file.newOid !== undefined;
592 lines.push(`--- ${before}`, `+++ ${after}`);
593 lines.push(`@@ -${hasOld ? "1" : "0,0"} +${hasNew ? "1" : "0,0"} @@`);
594 if (hasOld) lines.push(`-Subproject commit ${file.oldOid}`);
595 if (hasNew) lines.push(`+Subproject commit ${file.newOid}`);
596 } else {
597 const hunks = file.hunks ?? [];
598 if (hunks.length > 0) lines.push(`--- ${before}`, `+++ ${after}`);
599 for (const hunk of hunks) {
600 lines.push(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
601 for (const line of hunk.lines) {
602 // GitCafe marks a missing final newline with libgit2's own origins.
603 if (["=", ">", "<"].includes(line.origin)) lines.push("\\ No newline at end of file");
604 else lines.push(`${line.origin}${line.content.replace(/\n$/u, "")}`);
605 }
606 }
607 }
608 chunks.push(lines.join("\n"));
609 }
610 return {
611 patch: chunks.length === 0 ? "" : `${chunks.join("\n")}\n`,
612 truncated: diff.truncated === true || omittedFileStats.length > 0,
613 nextCursor: null,
614 ...(omittedFileStats.length === 0 ? {} : { omittedFileStats }),
615 };
617​
618function checkStatus(check: (typeof GitCafeChecks.Type.items)[number]): PullRequestCheck["status"] {
619 if (check.status !== "completed") return "pending";
620 switch (check.conclusion) {
621 case "success":
622 return "success";
623 case "neutral":
624 return "neutral";
625 case "skipped":
626 return "skipped";
627 case "cancelled":
628 return "cancelled";
629 case "action_required":
630 return "action-required";
631 default:
632 return "failure";
633 }
635​
636export function toChecks(checks: typeof GitCafeChecks.Type): ReadonlyArray<PullRequestCheck> {
637 return sortChecks(
638 checks.items.map((check) => ({
639 name: check.name,
640 status: checkStatus(check),
641 description: check.summary,
642 url: check.detailsUrl,
643 })),
644 );