@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 53 lines 1.93 KB
Raw
1 import * as Array from "effect/Array";
2 import * as Config from "effect/Config";
3 import * as Effect from "effect/Effect";
4 import { flow } from "effect/Function";
5 import * as Option from "effect/Option";
6 import * as String from "effect/String";
7
8 export interface GitHubEnv {
9 /** The commit SHA that triggered the workflow run. */
10 readonly sha: string;
11 /** The repository owner from `GITHUB_REPOSITORY_OWNER`. */
12 readonly owner: string;
13 /** The repository name parsed from `GITHUB_REPOSITORY`. */
14 readonly repository: string;
15 /** The pull request number exported by the Alchemy GitHub Action. */
16 readonly pr: number | undefined;
17 }
18
19 /**
20 * GitHub Actions metadata for conditional resources in `alchemy.run.ts`.
21 *
22 * Resolves to `undefined` outside GitHub Actions. In GitHub Actions, it reads
23 * `GITHUB_SHA`, `GITHUB_REPOSITORY_OWNER`, `GITHUB_REPOSITORY`, and the optional
24 * `PULL_REQUEST` variable exported by the Alchemy GitHub Action.
25 */
26 export const GitHubEnv: Config.Config<GitHubEnv | undefined> = Config.Boolean(
27 "GITHUB_ACTIONS",
28 ).pipe(
29 Config.withDefault(false),
30 // Config has no flatMap in Effect 4; a Config is itself an Effect, so the
31 // enabled branch returns the inner config for mapEffect to evaluate.
32 Config.mapEffect((enabled): Effect.Effect<GitHubEnv | undefined, Config.ConfigError> =>
33 enabled
34 ? Config.all({
35 sha: Config.String("GITHUB_SHA"),
36 owner: Config.String("GITHUB_REPOSITORY_OWNER"),
37 repository: Config.String("GITHUB_REPOSITORY").pipe(
38 Config.mapEffect(
39 flow(
40 String.split("/"),
41 Array.get(1),
42 Effect.fromOption,
43 Effect.catchTags({
44 NoSuchElementError: Effect.die,
45 }),
46 ),
47 ),
48 ),
49 pr: Config.Number("PULL_REQUEST").pipe(Config.option, Config.map(Option.getOrUndefined)),
50 })
51 : Effect.undefined,
52 ),
53 );