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

GitHubCli.ts

103 lines2.9 KB

1/**
2 * GitHubCli - Effect service contract for `gh` process interactions.
3 *
4 * Provides thin command execution helpers used by Git workflow orchestration.
5 *
6 * @module GitHubCli
7 */
8import { ServiceMap } from "effect";
9import type { Effect } from "effect";
10​
11import type { ProcessRunResult } from "../../processRunner";
12import type { GitHubCliError } from "../Errors.ts";
13​
14export interface GitHubPullRequestSummary {
15 readonly number: number;
16 readonly title: string;
17 readonly url: string;
18 readonly baseRefName: string;
19 readonly headRefName: string;
20 readonly state?: "open" | "closed" | "merged";
21 readonly isCrossRepository?: boolean;
22 readonly headRepositoryNameWithOwner?: string | null;
23 readonly headRepositoryOwnerLogin?: string | null;
25​
26export interface GitHubRepositoryCloneUrls {
27 readonly nameWithOwner: string;
28 readonly url: string;
29 readonly sshUrl: string;
31​
32/**
33 * GitHubCliShape - Service API for executing GitHub CLI commands.
34 */
35export interface GitHubCliShape {
36 /**
37 * Execute a GitHub CLI command and return full process output.
38 */
39 readonly execute: (input: {
40 readonly cwd: string;
41 readonly args: ReadonlyArray<string>;
42 readonly timeoutMs?: number;
43 }) => Effect.Effect<ProcessRunResult, GitHubCliError>;
44​
45 /**
46 * List open pull requests for a head branch.
47 */
48 readonly listOpenPullRequests: (input: {
49 readonly cwd: string;
50 readonly headSelector: string;
51 readonly limit?: number;
52 }) => Effect.Effect<ReadonlyArray<GitHubPullRequestSummary>, GitHubCliError>;
53​
54 /**
55 * Resolve a pull request by URL, number, or branch-ish identifier.
56 */
57 readonly getPullRequest: (input: {
58 readonly cwd: string;
59 readonly reference: string;
60 }) => Effect.Effect<GitHubPullRequestSummary, GitHubCliError>;
61​
62 /**
63 * Resolve clone URLs for a GitHub repository.
64 */
65 readonly getRepositoryCloneUrls: (input: {
66 readonly cwd: string;
67 readonly repository: string;
68 }) => Effect.Effect<GitHubRepositoryCloneUrls, GitHubCliError>;
69​
70 /**
71 * Create a pull request from branch context and body file.
72 */
73 readonly createPullRequest: (input: {
74 readonly cwd: string;
75 readonly baseBranch: string;
76 readonly headSelector: string;
77 readonly title: string;
78 readonly bodyFile: string;
79 }) => Effect.Effect<void, GitHubCliError>;
80​
81 /**
82 * Resolve repository default branch through GitHub metadata.
83 */
84 readonly getDefaultBranch: (input: {
85 readonly cwd: string;
86 }) => Effect.Effect<string | null, GitHubCliError>;
87​
88 /**
89 * Checkout a pull request into the current repository worktree.
90 */
91 readonly checkoutPullRequest: (input: {
92 readonly cwd: string;
93 readonly reference: string;
94 readonly force?: boolean;
95 }) => Effect.Effect<void, GitHubCliError>;
97​
98/**
99 * GitHubCli - Service tag for GitHub CLI process execution.
100 */
101export class GitHubCli extends ServiceMap.Service<GitHubCli, GitHubCliShape>()(
102 "t3/git/Services/GitHubCli",
103) {}