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

GetPullRequest.ts

59 lines2.0 KB

1import type * as Pulls from "@distilled.cloud/github/pulls";
2import * as Binding from "alchemy/Binding";
3import type { RuntimeContext } from "alchemy/RuntimeContext";
4import type * as Effect from "effect/Effect";
5import type { Repository } from "./Repository.ts";
6​
7/** The `accept` media types GitHub answers with text instead of JSON. */
8export type PullRequestTextMediaType = Exclude<
9 Pulls.GetRequestAccept,
10 "application/vnd.github+json"
11>;
12​
13export interface GetPullRequestRequest extends Omit<Pulls.GetRequest, "owner" | "repo" | "accept"> {
14 /** `application/vnd.github.diff` or `.patch` returns the text instead of the JSON object. */
15 readonly accept?: Pulls.GetRequestAccept;
17​
18export type GetPullRequestResponse = Pulls.PullRequest;
19​
20/**
21 * Get a pull request by number (`pulls.get`). Like the API, `accept` selects
22 * the media type: `application/vnd.github.diff` or
23 * `application/vnd.github.patch` return the diff or patch text instead of the
24 * JSON object.
25 *
26 * Provide `GitHub.GetPullRequestHttp` on a Worker or Function, or
27 * `GitHub.GetPullRequestLocal` on an Action.
28 *
29 * ### Reading Pull Requests at Runtime
30 * **Example:** Get a pull request and its diff
31 * ```typescript
32 * const getPullRequest = yield* GitHub.GetPullRequest(yield* Repo);
33 * const pull = yield* getPullRequest({ pull_number: 9 });
34 * const diff = yield* getPullRequest({
35 * pull_number: 9,
36 * accept: "application/vnd.github.diff",
37 * });
38 * ```
39 *
40 * @binding
41 * @product Pull Request
42 */
43export interface GetPullRequest extends Binding.Service<
44 GetPullRequest,
45 "GitHub.GetPullRequest",
46 (
47 repo: Repository,
48 ) => Effect.Effect<
49 <Accept extends GetPullRequestRequest["accept"] = undefined>(
50 request: GetPullRequestRequest & { readonly accept?: Accept },
51 ) => Effect.Effect<
52 Accept extends PullRequestTextMediaType ? string : GetPullRequestResponse,
53 Pulls.GetError,
54 RuntimeContext
55 >
56 >
57> {}
58​
59export const GetPullRequest = Binding.Service<GetPullRequest>("GitHub.GetPullRequest");