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

GetIssueHttp.ts

33 lines1.1 KB

1import * as Issues from "@distilled.cloud/github/issues";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as BindingHttp from "./BindingHttp.ts";
5import { IssueNotFound } from "./Errors.ts";
6import { GetIssue, type GetIssueRequest } from "./GetIssue.ts";
7​
8export const getIssueOperation = BindingHttp.operation(
9 "issues.get",
10 (repo) => (request: GetIssueRequest) =>
11 Issues.get({ owner: repo.owner, repo: repo.repository, ...request }).pipe(
12 Effect.catchTag("NotFound", () =>
13 Effect.fail(
14 new IssueNotFound({
15 owner: repo.owner,
16 repository: repo.repository,
17 number: request.issue_number,
18 }),
19 ),
20 ),
21 ),
22);
23​
24/**
25 * Token-backed implementation of {@link GetIssue}. Provide it on a Worker or
26 * Function: it captures a `GitHub.PersonalAccessToken` for the host and binds
27 * the token and the repository into it.
28 *
29 * @layer
30 * @product Issue
31 * @provides GitHub.GetIssue
32 */
33export const GetIssueHttp = Layer.effect(GetIssue, BindingHttp.make(getIssueOperation));