The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { render, upsert } from "@effect/npm-promote/TrackingIssue" |
| 2 | import { assert, describe, it } from "@effect/vitest" |
| 3 | import * as Effect from "effect/Effect" |
| 4 | import * as HttpClient from "effect/http/HttpClient" |
| 5 | import * as HttpClientResponse from "effect/http/HttpClientResponse" |
| 6 | import * as Redacted from "effect/Redacted" |
| 7 | |
| 8 | interface Issue { |
| 9 | readonly number: number |
| 10 | title: string |
| 11 | body: string |
| 12 | state: "open" | "closed" |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Serves the GitHub issue endpoints used by the tracking issue from `issues`. |
| 17 | */ |
| 18 | const githubClient = (issues: Array<Issue>): HttpClient.HttpClient => |
| 19 | HttpClient.make((request) => |
| 20 | Effect.sync(() => { |
| 21 | const path = new URL(request.url).pathname.replace(/^\/repos\/Effect-TS\/effect/, "") |
| 22 | const body = request.body._tag === "Uint8Array" ? JSON.parse(new TextDecoder().decode(request.body.body)) : {} |
| 23 | const respond = (json: unknown) => HttpClientResponse.fromWeb(request, Response.json(json)) |
| 24 | if (request.method === "GET" && path === "/issues") { |
| 25 | return respond(issues.filter((issue) => issue.state === "open").sort((a, b) => b.number - a.number)) |
| 26 | } |
| 27 | if (request.method === "POST" && path === "/issues") { |
| 28 | const issue: Issue = { number: Math.max(0, ...issues.map((issue) => issue.number)) + 1, state: "open", ...body } |
| 29 | issues.push(issue) |
| 30 | return respond(issue) |
| 31 | } |
| 32 | const match = /^\/issues\/(\d+)(\/comments)?$/.exec(path) |
| 33 | const issue = issues.find((issue) => issue.number === Number(match?.[1])) |
| 34 | if (issue === undefined) { |
| 35 | return HttpClientResponse.fromWeb(request, new Response(null, { status: 404 })) |
| 36 | } |
| 37 | if (request.method === "PATCH" && match?.[2] === undefined) { |
| 38 | Object.assign(issue, body) |
| 39 | } |
| 40 | return respond(issue) |
| 41 | }) |
| 42 | ) |
| 43 | |
| 44 | const content = render({ |
| 45 | version: "4.0.6", |
| 46 | bump: { sha: "a".repeat(40), committedAt: new Date(0) }, |
| 47 | overdueAfterHours: 12, |
| 48 | diagnoses: [{ _tag: "Missing", pkg: { name: "effect", version: "4.0.6" } }] |
| 49 | }) |
| 50 | |
| 51 | describe("TrackingIssue", () => { |
| 52 | it.effect("keeps the oldest open tracking issue and closes duplicates", () => |
| 53 | Effect.gen(function*() { |
| 54 | // Left behind by runs whose issue listing missed the open tracking issue. |
| 55 | const issues: Array<Issue> = [9774, 9776, 9778].map((number) => ({ number, state: "open", ...content })) |
| 56 | |
| 57 | const result = yield* upsert({ repository: "Effect-TS/effect", token: Redacted.make("token") }, content).pipe( |
| 58 | Effect.provideService(HttpClient.HttpClient, githubClient(issues)) |
| 59 | ) |
| 60 | |
| 61 | assert.strictEqual(result.number, 9774) |
| 62 | assert.deepStrictEqual( |
| 63 | issues.filter((issue) => issue.state === "open").map((issue) => issue.number), |
| 64 | [9774] |
| 65 | ) |
| 66 | })) |
| 67 | }) |