| 1 | import type { |
| 2 | MergebotPullRequestDetails, |
| 3 | PullRequestCheck, |
| 4 | PullRequestMergeability, |
| 5 | } from "@t3tools/contracts"; |
| 6 | |
| 7 | export function mergebotChecks( |
| 8 | details: MergebotPullRequestDetails, |
| 9 | ): ReadonlyArray<PullRequestCheck> { |
| 10 | return details.checks.map((check) => { |
| 11 | const conclusion = check.conclusion; |
| 12 | const status = |
| 13 | check.status !== "completed" |
| 14 | ? "pending" |
| 15 | : conclusion === "success" || conclusion === "neutral" || conclusion === "skipped" |
| 16 | ? conclusion |
| 17 | : conclusion === "cancelled" |
| 18 | ? "cancelled" |
| 19 | : conclusion === "action_required" |
| 20 | ? "action-required" |
| 21 | : conclusion === "failure" || |
| 22 | conclusion === "timed_out" || |
| 23 | conclusion === "startup_failure" |
| 24 | ? "failure" |
| 25 | : "pending"; |
| 26 | return { |
| 27 | name: check.workflowName === null ? check.name : `${check.workflowName} / ${check.name}`, |
| 28 | status, |
| 29 | description: null, |
| 30 | url: check.url, |
| 31 | ...(check.completedAt === null ? {} : { completedAt: check.completedAt }), |
| 32 | }; |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | export function mergebotMergeability(details: MergebotPullRequestDetails): PullRequestMergeability { |
| 37 | return details.hasConflicts === null |
| 38 | ? "unknown" |
| 39 | : details.hasConflicts |
| 40 | ? "conflicting" |
| 41 | : "mergeable"; |
| 42 | } |
| 43 | |
| 44 | export function mergebotWatchFingerprint(details: MergebotPullRequestDetails) { |
| 45 | return { |
| 46 | status: [ |
| 47 | details.headSha, |
| 48 | details.lifecycle, |
| 49 | details.draft, |
| 50 | details.hasConflicts, |
| 51 | details.updatedAt, |
| 52 | ...details.checks.map((check) => |
| 53 | [check.id, check.status, check.conclusion, check.completedAt].join("\u0000"), |
| 54 | ), |
| 55 | ].join("\u0001"), |
| 56 | remarks: details.comments |
| 57 | .map((comment) => [comment.id, comment.editedAt ?? comment.createdAt].join("\u0000")) |
| 58 | .join("\u0001"), |
| 59 | }; |
| 60 | } |