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 *
45 * @public Service construction is part of the canonical Effect module API.
46 */
47export const make = Effect.map(
48 Effect.all([
49 GitHubPullRequestProvider.make,
50 GitLabPullRequestProvider.make,
51 BitbucketPullRequestProvider.make,
52 AzureDevOpsPullRequestProvider.make,
53 ]),
54 fromProviders,
55);
56
57export const layer = Layer.effect(PullRequestProviderRegistry, make).pipe(
58 Layer.provide(
59 GitHubPullRequestCli.layer.pipe(
60 Layer.provide(GitHubCli.layer),
61 Layer.provide(GitHubGraphQlBudget.layer),
62 ),
63 ),
64 Layer.provide(GitLabPullRequestCli.layer.pipe(Layer.provide(GitLabCli.layer))),
65 Layer.provide(BitbucketPullRequestApi.layer.pipe(Layer.provide(BitbucketApi.layer))),
66 Layer.provide(AzureDevOpsPullRequestCli.layer.pipe(Layer.provide(AzureDevOpsCli.layer))),
67);