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

GetIssue.ts

48 lines1.4 KB

1import type { NotFound } from "@distilled.cloud/github/Errors";
2import type * as Issues from "@distilled.cloud/github/issues";
3import * as Binding from "alchemy/Binding";
4import type { RuntimeContext } from "alchemy/RuntimeContext";
5import type * as Effect from "effect/Effect";
6import type { IssueNotFound } from "./Errors.ts";
7import type { Repository } from "./Repository.ts";
8​
9export interface GetIssueRequest extends Omit<Issues.GetRequest, "owner" | "repo"> {}
10​
11export type GetIssueResponse = Issues.Issue;
12​
13/**
14 * Get one issue by number (`issues.get`). A missing issue fails with the typed
15 * {@link IssueNotFound}.
16 *
17 * Provide `GitHub.GetIssueHttp` on a Worker or Function, or
18 * `GitHub.GetIssueLocal` on an Action.
19 *
20 * ### Reading Issues at Runtime
21 * **Example:** Get an issue, treating a missing one as absent
22 * ```typescript
23 * const getIssue = yield* GitHub.GetIssue(yield* Repo);
24 * const issue = yield* getIssue({ issue_number: 7 }).pipe(
25 * Effect.catchTag("IssueNotFound", () => Effect.succeed(undefined)),
26 * );
27 * ```
28 *
29 * @binding
30 * @product Issue
31 */
32export interface GetIssue extends Binding.Service<
33 GetIssue,
34 "GitHub.GetIssue",
35 (
36 repo: Repository,
37 ) => Effect.Effect<
38 (
39 request: GetIssueRequest,
40 ) => Effect.Effect<
41 GetIssueResponse,
42 Exclude<Issues.GetError, NotFound> | IssueNotFound,
43 RuntimeContext
44 >
45 >
46> {}
47​
48export const GetIssue = Binding.Service<GetIssue>("GitHub.GetIssue");