The best way to control Claude Code, Codex and more from any computer or phone

main
ts 59 lines 1.98 KB
Raw
1 import type * as Pulls from "@distilled.cloud/github/pulls";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import type * as Effect from "effect/Effect";
5 import type { Repository } from "./Repository.ts";
6
7 /** The `accept` media types GitHub answers with text instead of JSON. */
8 export type PullRequestTextMediaType = Exclude<
9 Pulls.GetRequestAccept,
10 "application/vnd.github+json"
11 >;
12
13 export 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;
16 }
17
18 export 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 */
43 export 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
59 export const GetPullRequest = Binding.Service<GetPullRequest>("GitHub.GetPullRequest");