Open History to see the last commit
1import type { GithubOpContext } from "@distilled.cloud/github";
2import * as Pulls from "@distilled.cloud/github/pulls";
3import type { Self } from "alchemy/Self";
4import type * as Effect from "effect/Effect";
5import * as Layer from "effect/Layer";
6import * as BindingHttp from "./BindingHttp.ts";
7import { GetPullRequest, type GetPullRequestRequest } from "./GetPullRequest.ts";
8
9export const getPullRequestOperation = BindingHttp.operation(
10 "pulls.get",
11 (repo) =>
12 ({
13 accept,
14 ...request
15 }: GetPullRequestRequest): Effect.Effect<
16 Pulls.PullRequest | string,
17 Pulls.GetError,
18 GithubOpContext
19 > => {
20 // One branch per overload: the JSON object, or the text media type's text.
21 const scope = { owner: repo.owner, repo: repo.repository, ...request };
22 return accept === undefined || accept === "application/vnd.github+json"
23 ? Pulls.get({ ...scope, accept })
24 : Pulls.get({ ...scope, accept });
25 },
26);
27
28/**
29 * Token-backed implementation of {@link GetPullRequest}. Provide it on a Worker or
30 * Function: it captures a `GitHub.PersonalAccessToken` for the host and binds
31 * the token and the repository into it.
32 *
33 * @layer
34 * @product Pull Request
35 * @provides GitHub.GetPullRequest
36 */
37export const GetPullRequestHttp: Layer.Layer<GetPullRequest, never, Self> = Layer.effect(
38 GetPullRequest,
39 BindingHttp.make(getPullRequestOperation) as never,
40);