Open History to see the last commit
1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import type { SourceControlProviderKind } from "@t3tools/contracts";
5
6import * as AzureDevOpsCli from "../sourceControl/AzureDevOpsCli.ts";
7import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
8import * as GitHubCli from "../sourceControl/GitHubCli.ts";
9import * as GitHubGraphQlBudget from "../sourceControl/githubGraphQlBudget.ts";
10import * as GitLabCli from "../sourceControl/GitLabCli.ts";
11import * as AzureDevOpsPullRequestCli from "./AzureDevOpsPullRequestCli.ts";
12import * as AzureDevOpsPullRequestProvider from "./AzureDevOpsPullRequestProvider.ts";
13import * as BitbucketPullRequestApi from "./BitbucketPullRequestApi.ts";
14import * as BitbucketPullRequestProvider from "./BitbucketPullRequestProvider.ts";
15import * as GitHubPullRequestCli from "./GitHubPullRequestCli.ts";
16import * as GitHubPullRequestProvider from "./GitHubPullRequestProvider.ts";
17import * as GitLabPullRequestCli from "./GitLabPullRequestCli.ts";
18import * as GitLabPullRequestProvider from "./GitLabPullRequestProvider.ts";
19import type { PullRequestProviderApi } from "./PullRequestProvider.ts";
20
21export class PullRequestProviderRegistry extends Context.Service<
22 PullRequestProviderRegistry,
23 {
24 /** Null for a host with no implementation, which the service reports as unsupported. */
25 readonly get: (kind: SourceControlProviderKind) => PullRequestProviderApi | null;
26 readonly kinds: ReadonlyArray<SourceControlProviderKind>;
27 }
28>()("t3/pullRequest/PullRequestProviderRegistry") {}
29
30/** Exported for tests, which stand a registry up from providers they supply themselves. */
31export function fromProviders(
32 providers: ReadonlyArray<PullRequestProviderApi>,
33): PullRequestProviderRegistry["Service"] {
34 const byKind = new Map(providers.map((provider) => [provider.kind, provider]));
35 return {
36 get: (kind) => byKind.get(kind) ?? null,
37 kinds: providers.map((provider) => provider.kind),
38 };
39}
40
41/**
42 * The hosts this build can read change requests from. A host with no entry here still shows up
43 * in the provider list as unimplemented, so its projects are explained rather than missing.
44 */
45export const make = Effect.map(
46 Effect.all([
47 GitHubPullRequestProvider.make,
48 GitLabPullRequestProvider.make,
49 BitbucketPullRequestProvider.make,
50 AzureDevOpsPullRequestProvider.make,
51 ]),
52 fromProviders,
53);
54
55export const layer = Layer.effect(PullRequestProviderRegistry, make).pipe(
56 Layer.provide(
57 GitHubPullRequestCli.layer.pipe(
58 Layer.provide(GitHubCli.layer),
59 Layer.provide(GitHubGraphQlBudget.layer),
60 ),
61 ),
62 Layer.provide(GitLabPullRequestCli.layer.pipe(Layer.provide(GitLabCli.layer))),
63 Layer.provide(BitbucketPullRequestApi.layer.pipe(Layer.provide(BitbucketApi.layer))),
64 Layer.provide(AzureDevOpsPullRequestCli.layer.pipe(Layer.provide(AzureDevOpsCli.layer))),
65);