[codex] Migrate server source control Effect services (#3186)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
7118e43d16
commit
d9e9539862
42 files changed
+1326
-1328
No files matched your search
@@ -17,7 +17,7 @@ const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({
|
||||
stderrTruncated: false,
|
||||
});
|
||||
|
||||
const mockRun = vi.fn<VcsProcess.VcsProcessShape["run"]>();
|
||||
const mockRun = vi.fn<VcsProcess.VcsProcess["Service"]["run"]>();
|
||||
|
||||
const supportLayer = Layer.mergeAll(
|
||||
Layer.mock(VcsProcess.VcsProcess)({
|
||||
|
||||
@@ -11,7 +11,12 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as AzureDevOpsPullRequests from "./azureDevOpsPullRequests.ts";
|
||||
import {
|
||||
decodeAzureDevOpsPullRequestJson,
|
||||
decodeAzureDevOpsPullRequestListJson,
|
||||
formatAzureDevOpsJsonDecodeError,
|
||||
type NormalizedAzureDevOpsPullRequestRecord,
|
||||
} from "./azureDevOpsPullRequests.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 30_000;
|
||||
@@ -35,67 +40,60 @@ export interface AzureDevOpsRepositoryCloneUrls {
|
||||
readonly sshUrl: string;
|
||||
}
|
||||
|
||||
export interface AzureDevOpsCliShape {
|
||||
readonly execute: (input: {
|
||||
readonly cwd: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => Effect.Effect<VcsProcess.VcsProcessOutput, AzureDevOpsCliError>;
|
||||
export class AzureDevOpsCli extends Context.Service<
|
||||
AzureDevOpsCli,
|
||||
{
|
||||
readonly execute: (input: {
|
||||
readonly cwd: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => Effect.Effect<VcsProcess.VcsProcessOutput, AzureDevOpsCliError>;
|
||||
|
||||
readonly listPullRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly state: "open" | "closed" | "merged" | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<
|
||||
ReadonlyArray<AzureDevOpsPullRequests.NormalizedAzureDevOpsPullRequestRecord>,
|
||||
AzureDevOpsCliError
|
||||
>;
|
||||
readonly listPullRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly state: "open" | "closed" | "merged" | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<NormalizedAzureDevOpsPullRequestRecord>, AzureDevOpsCliError>;
|
||||
|
||||
readonly getPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<
|
||||
AzureDevOpsPullRequests.NormalizedAzureDevOpsPullRequestRecord,
|
||||
AzureDevOpsCliError
|
||||
>;
|
||||
readonly getPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<NormalizedAzureDevOpsPullRequestRecord, AzureDevOpsCliError>;
|
||||
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<AzureDevOpsRepositoryCloneUrls, AzureDevOpsCliError>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<AzureDevOpsRepositoryCloneUrls, AzureDevOpsCliError>;
|
||||
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<AzureDevOpsRepositoryCloneUrls, AzureDevOpsCliError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<AzureDevOpsRepositoryCloneUrls, AzureDevOpsCliError>;
|
||||
|
||||
readonly createPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly target?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, AzureDevOpsCliError>;
|
||||
readonly createPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly target?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, AzureDevOpsCliError>;
|
||||
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<string | null, AzureDevOpsCliError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<string | null, AzureDevOpsCliError>;
|
||||
|
||||
readonly checkoutPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
readonly remoteName?: string;
|
||||
}) => Effect.Effect<void, AzureDevOpsCliError>;
|
||||
}
|
||||
|
||||
export class AzureDevOpsCli extends Context.Service<AzureDevOpsCli, AzureDevOpsCliShape>()(
|
||||
"t3/sourceControl/AzureDevOpsCli",
|
||||
) {}
|
||||
readonly checkoutPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
readonly remoteName?: string;
|
||||
}) => Effect.Effect<void, AzureDevOpsCliError>;
|
||||
}
|
||||
>()("t3/sourceControl/AzureDevOpsCli") {}
|
||||
|
||||
function errorText(error: VcsError | unknown): string {
|
||||
if (typeof error === "object" && error !== null) {
|
||||
@@ -239,10 +237,10 @@ function decodeAzureDevOpsJson<S extends Schema.Top>(
|
||||
);
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeAzureDevOpsCli")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const process = yield* VcsProcess.VcsProcess;
|
||||
|
||||
const execute: AzureDevOpsCliShape["execute"] = (input) =>
|
||||
const execute: AzureDevOpsCli["Service"]["execute"] = (input) =>
|
||||
process
|
||||
.run({
|
||||
operation: "AzureDevOpsCli.execute",
|
||||
@@ -253,7 +251,7 @@ export const make = Effect.fn("makeAzureDevOpsCli")(function* () {
|
||||
})
|
||||
.pipe(Effect.mapError((error) => normalizeAzureDevOpsCliError("execute", error)));
|
||||
|
||||
const executeJson = (input: Parameters<AzureDevOpsCliShape["execute"]>[0]) =>
|
||||
const executeJson = (input: Parameters<AzureDevOpsCli["Service"]["execute"]>[0]) =>
|
||||
execute({
|
||||
...input,
|
||||
args: [...input.args, "--only-show-errors", "--output", "json"],
|
||||
@@ -282,15 +280,13 @@ export const make = Effect.fn("makeAzureDevOpsCli")(function* () {
|
||||
Effect.flatMap((raw) =>
|
||||
raw.length === 0
|
||||
? Effect.succeed([])
|
||||
: Effect.sync(() =>
|
||||
AzureDevOpsPullRequests.decodeAzureDevOpsPullRequestListJson(raw),
|
||||
).pipe(
|
||||
: Effect.sync(() => decodeAzureDevOpsPullRequestListJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) => {
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Effect.fail(
|
||||
new AzureDevOpsCliError({
|
||||
operation: "listPullRequests",
|
||||
detail: `Azure DevOps CLI returned invalid PR list JSON: ${AzureDevOpsPullRequests.formatAzureDevOpsJsonDecodeError(decoded.failure)}`,
|
||||
detail: `Azure DevOps CLI returned invalid PR list JSON: ${formatAzureDevOpsJsonDecodeError(decoded.failure)}`,
|
||||
cause: decoded.failure,
|
||||
}),
|
||||
);
|
||||
@@ -316,13 +312,13 @@ export const make = Effect.fn("makeAzureDevOpsCli")(function* () {
|
||||
}).pipe(
|
||||
Effect.map((result) => result.stdout.trim()),
|
||||
Effect.flatMap((raw) =>
|
||||
Effect.sync(() => AzureDevOpsPullRequests.decodeAzureDevOpsPullRequestJson(raw)).pipe(
|
||||
Effect.sync(() => decodeAzureDevOpsPullRequestJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) => {
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Effect.fail(
|
||||
new AzureDevOpsCliError({
|
||||
operation: "getPullRequest",
|
||||
detail: `Azure DevOps CLI returned invalid pull request JSON: ${AzureDevOpsPullRequests.formatAzureDevOpsJsonDecodeError(decoded.failure)}`,
|
||||
detail: `Azure DevOps CLI returned invalid pull request JSON: ${formatAzureDevOpsJsonDecodeError(decoded.failure)}`,
|
||||
cause: decoded.failure,
|
||||
}),
|
||||
);
|
||||
@@ -434,4 +430,4 @@ export const make = Effect.fn("makeAzureDevOpsCli")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(AzureDevOpsCli, make());
|
||||
export const layer = Layer.effect(AzureDevOpsCli, make);
|
||||
@@ -6,8 +6,8 @@ import * as Option from "effect/Option";
|
||||
import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
|
||||
import * as AzureDevOpsSourceControlProvider from "./AzureDevOpsSourceControlProvider.ts";
|
||||
|
||||
function makeProvider(azure: Partial<AzureDevOpsCli.AzureDevOpsCliShape>) {
|
||||
return AzureDevOpsSourceControlProvider.make().pipe(
|
||||
function makeProvider(azure: Partial<AzureDevOpsCli.AzureDevOpsCli["Service"]>) {
|
||||
return AzureDevOpsSourceControlProvider.make.pipe(
|
||||
Effect.provide(Layer.mock(AzureDevOpsCli.AzureDevOpsCli)(azure)),
|
||||
);
|
||||
}
|
||||
@@ -48,8 +48,9 @@ it.effect("maps Azure DevOps PR summaries into provider-neutral change requests"
|
||||
|
||||
it.effect("creates Azure DevOps PRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let createInput: Parameters<AzureDevOpsCli.AzureDevOpsCliShape["createPullRequest"]>[0] | null =
|
||||
null;
|
||||
let createInput:
|
||||
| Parameters<AzureDevOpsCli.AzureDevOpsCli["Service"]["createPullRequest"]>[0]
|
||||
| null = null;
|
||||
const provider = yield* makeProvider({
|
||||
createPullRequest: (input) => {
|
||||
createInput = input;
|
||||
|
||||
@@ -4,7 +4,13 @@ import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contrac
|
||||
|
||||
import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import {
|
||||
combinedAuthOutput,
|
||||
firstSafeAuthLine,
|
||||
providerAuth,
|
||||
type SourceControlAuthProbeInput,
|
||||
type SourceControlCliDiscoverySpec,
|
||||
} from "./SourceControlProviderDiscovery.ts";
|
||||
|
||||
function providerError(
|
||||
operation: string,
|
||||
@@ -18,28 +24,26 @@ function providerError(
|
||||
});
|
||||
}
|
||||
|
||||
function parseAzureAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) {
|
||||
function parseAzureAuth(input: SourceControlAuthProbeInput) {
|
||||
const account = input.stdout.trim().split(/\r?\n/)[0]?.trim();
|
||||
|
||||
if (input.exitCode !== 0) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unauthenticated",
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(
|
||||
SourceControlProviderDiscovery.combinedAuthOutput(input),
|
||||
) ?? "Run `az login` to authenticate Azure CLI.",
|
||||
firstSafeAuthLine(combinedAuthOutput(input)) ?? "Run `az login` to authenticate Azure CLI.",
|
||||
});
|
||||
}
|
||||
|
||||
if (account !== undefined && account.length > 0) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "authenticated",
|
||||
account,
|
||||
host: "dev.azure.com",
|
||||
});
|
||||
}
|
||||
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unknown",
|
||||
host: "dev.azure.com",
|
||||
detail: "Azure CLI account status could not be parsed.",
|
||||
@@ -56,7 +60,7 @@ export const discovery = {
|
||||
parseAuth: parseAzureAuth,
|
||||
installHint:
|
||||
"Install the Azure command-line tools (`az`), then enable Azure DevOps support with `az extension add --name azure-devops`.",
|
||||
} satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec;
|
||||
} satisfies SourceControlCliDiscoverySpec;
|
||||
|
||||
function toChangeRequest(summary: {
|
||||
readonly number: number;
|
||||
@@ -80,7 +84,7 @@ function toChangeRequest(summary: {
|
||||
};
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeAzureDevOpsSourceControlProvider")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const azure = yield* AzureDevOpsCli.AzureDevOpsCli;
|
||||
|
||||
return SourceControlProvider.SourceControlProvider.of({
|
||||
@@ -142,4 +146,4 @@ export const make = Effect.fn("makeAzureDevOpsSourceControlProvider")(function*
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make());
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make);
|
||||
@@ -53,41 +53,41 @@ const repositoryJson = {
|
||||
|
||||
function makeLayer(input: {
|
||||
readonly response: (request: HttpClientRequest.HttpClientRequest) => Response;
|
||||
readonly git?: Partial<GitVcsDriver.GitVcsDriverShape>;
|
||||
readonly git?: Partial<GitVcsDriver.GitVcsDriver["Service"]>;
|
||||
}) {
|
||||
const execute = vi.fn((request: HttpClientRequest.HttpClientRequest) =>
|
||||
Effect.succeed(HttpClientResponse.fromWeb(request, input.response(request))),
|
||||
);
|
||||
const gitMock = {
|
||||
readConfigValue: vi.fn<GitVcsDriver.GitVcsDriverShape["readConfigValue"]>(() =>
|
||||
readConfigValue: vi.fn<GitVcsDriver.GitVcsDriver["Service"]["readConfigValue"]>(() =>
|
||||
Effect.succeed<string | null>("[email protected]:pingdotgg/t3code.git"),
|
||||
),
|
||||
resolvePrimaryRemoteName: vi.fn<GitVcsDriver.GitVcsDriverShape["resolvePrimaryRemoteName"]>(
|
||||
() => Effect.succeed("origin"),
|
||||
),
|
||||
ensureRemote: vi.fn<GitVcsDriver.GitVcsDriverShape["ensureRemote"]>(() =>
|
||||
resolvePrimaryRemoteName: vi.fn<
|
||||
GitVcsDriver.GitVcsDriver["Service"]["resolvePrimaryRemoteName"]
|
||||
>(() => Effect.succeed("origin")),
|
||||
ensureRemote: vi.fn<GitVcsDriver.GitVcsDriver["Service"]["ensureRemote"]>(() =>
|
||||
Effect.succeed("octocat"),
|
||||
),
|
||||
fetchRemoteBranch: vi.fn<GitVcsDriver.GitVcsDriverShape["fetchRemoteBranch"]>(
|
||||
fetchRemoteBranch: vi.fn<GitVcsDriver.GitVcsDriver["Service"]["fetchRemoteBranch"]>(
|
||||
() => Effect.void,
|
||||
),
|
||||
fetchRemoteTrackingBranch: vi.fn<GitVcsDriver.GitVcsDriverShape["fetchRemoteTrackingBranch"]>(
|
||||
fetchRemoteTrackingBranch: vi.fn<
|
||||
GitVcsDriver.GitVcsDriver["Service"]["fetchRemoteTrackingBranch"]
|
||||
>(() => Effect.void),
|
||||
setBranchUpstream: vi.fn<GitVcsDriver.GitVcsDriver["Service"]["setBranchUpstream"]>(
|
||||
() => Effect.void,
|
||||
),
|
||||
setBranchUpstream: vi.fn<GitVcsDriver.GitVcsDriverShape["setBranchUpstream"]>(
|
||||
() => Effect.void,
|
||||
),
|
||||
switchRef: vi.fn<GitVcsDriver.GitVcsDriverShape["switchRef"]>((request) =>
|
||||
switchRef: vi.fn<GitVcsDriver.GitVcsDriver["Service"]["switchRef"]>((request) =>
|
||||
Effect.succeed({ refName: request.refName }),
|
||||
),
|
||||
listLocalBranchNames: vi.fn<GitVcsDriver.GitVcsDriverShape["listLocalBranchNames"]>(() =>
|
||||
listLocalBranchNames: vi.fn<GitVcsDriver.GitVcsDriver["Service"]["listLocalBranchNames"]>(() =>
|
||||
Effect.succeed([]),
|
||||
),
|
||||
};
|
||||
const git = {
|
||||
...gitMock,
|
||||
...input.git,
|
||||
} satisfies Partial<GitVcsDriver.GitVcsDriverShape>;
|
||||
} satisfies Partial<GitVcsDriver.GitVcsDriver["Service"]>;
|
||||
|
||||
const driver = {
|
||||
listRemotes: () =>
|
||||
@@ -106,7 +106,7 @@ function makeLayer(input: {
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
}),
|
||||
} satisfies Partial<VcsDriver.VcsDriverShape>;
|
||||
} satisfies Partial<VcsDriver.VcsDriver["Service"]>;
|
||||
|
||||
const layer = BitbucketApi.layer.pipe(
|
||||
Layer.provide(
|
||||
@@ -130,7 +130,7 @@ function makeLayer(input: {
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
},
|
||||
driver: driver as unknown as VcsDriver.VcsDriverShape,
|
||||
driver: driver as unknown as VcsDriver.VcsDriver["Service"],
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -15,7 +15,12 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstab
|
||||
import { sanitizeBranchFragment } from "@t3tools/shared/git";
|
||||
import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";
|
||||
|
||||
import * as BitbucketPullRequests from "./bitbucketPullRequests.ts";
|
||||
import {
|
||||
BitbucketPullRequestListSchema,
|
||||
BitbucketPullRequestSchema,
|
||||
normalizeBitbucketPullRequestRecord,
|
||||
type NormalizedBitbucketPullRequestRecord,
|
||||
} from "./bitbucketPullRequests.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
|
||||
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
|
||||
@@ -44,7 +49,7 @@ export class BitbucketApiError extends Schema.TaggedErrorClass<BitbucketApiError
|
||||
return `Bitbucket API failed in ${this.operation}: ${this.detail}`;
|
||||
}
|
||||
}
|
||||
const isBitbucketApiErrorValue = Schema.is(BitbucketApiError);
|
||||
const isBitbucketApiError = Schema.is(BitbucketApiError);
|
||||
|
||||
const RawBitbucketRepositorySchema = Schema.Struct({
|
||||
full_name: TrimmedNonEmptyString,
|
||||
@@ -100,62 +105,55 @@ export interface BitbucketRepositoryLocator {
|
||||
readonly repoSlug: string;
|
||||
}
|
||||
|
||||
export interface BitbucketApiShape {
|
||||
readonly probeAuth: Effect.Effect<SourceControlProviderAuth, never>;
|
||||
readonly listPullRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly state: "open" | "closed" | "merged" | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<
|
||||
ReadonlyArray<BitbucketPullRequests.NormalizedBitbucketPullRequestRecord>,
|
||||
BitbucketApiError
|
||||
>;
|
||||
readonly getPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<
|
||||
BitbucketPullRequests.NormalizedBitbucketPullRequestRecord,
|
||||
BitbucketApiError
|
||||
>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, BitbucketApiError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, BitbucketApiError>;
|
||||
readonly createPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly target?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, BitbucketApiError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
}) => Effect.Effect<string | null, BitbucketApiError>;
|
||||
readonly checkoutPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, BitbucketApiError>;
|
||||
}
|
||||
|
||||
export class BitbucketApi extends Context.Service<BitbucketApi, BitbucketApiShape>()(
|
||||
"t3/sourceControl/BitbucketApi",
|
||||
) {}
|
||||
export class BitbucketApi extends Context.Service<
|
||||
BitbucketApi,
|
||||
{
|
||||
readonly probeAuth: Effect.Effect<SourceControlProviderAuth, never>;
|
||||
readonly listPullRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly state: "open" | "closed" | "merged" | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<NormalizedBitbucketPullRequestRecord>, BitbucketApiError>;
|
||||
readonly getPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<NormalizedBitbucketPullRequestRecord, BitbucketApiError>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, BitbucketApiError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, BitbucketApiError>;
|
||||
readonly createPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly target?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, BitbucketApiError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
}) => Effect.Effect<string | null, BitbucketApiError>;
|
||||
readonly checkoutPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, BitbucketApiError>;
|
||||
}
|
||||
>()("t3/sourceControl/BitbucketApi") {}
|
||||
|
||||
function nonEmpty(value: string | undefined): Option.Option<string> {
|
||||
const trimmed = value?.trim();
|
||||
@@ -299,9 +297,7 @@ function checkoutBranchName(input: {
|
||||
}
|
||||
|
||||
function repositoryNameWithOwner(
|
||||
repository: Schema.Schema.Type<
|
||||
typeof BitbucketPullRequests.BitbucketPullRequestSchema
|
||||
>["source"]["repository"],
|
||||
repository: Schema.Schema.Type<typeof BitbucketPullRequestSchema>["source"]["repository"],
|
||||
): string | null {
|
||||
const fullName = repository?.full_name?.trim() ?? "";
|
||||
return fullName.length > 0 ? fullName : null;
|
||||
@@ -350,10 +346,6 @@ function requestError(operation: string, cause: unknown): BitbucketApiError {
|
||||
});
|
||||
}
|
||||
|
||||
function isBitbucketApiError(cause: unknown): cause is BitbucketApiError {
|
||||
return isBitbucketApiErrorValue(cause);
|
||||
}
|
||||
|
||||
function responseError(
|
||||
operation: string,
|
||||
response: HttpClientResponse.HttpClientResponse,
|
||||
@@ -375,7 +367,7 @@ function responseError(
|
||||
);
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const config = yield* BitbucketApiEnvConfig;
|
||||
const httpClient = yield* HttpClient.HttpClient;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
@@ -511,7 +503,7 @@ export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
`/repositories/${encodeURIComponent(repository.workspace)}/${encodeURIComponent(repository.repoSlug)}/pullrequests/${encodeURIComponent(normalizeChangeRequestId(reference))}`,
|
||||
),
|
||||
),
|
||||
BitbucketPullRequests.BitbucketPullRequestSchema,
|
||||
BitbucketPullRequestSchema,
|
||||
);
|
||||
|
||||
const getRawPullRequest = (input: {
|
||||
@@ -599,17 +591,13 @@ export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
),
|
||||
{ urlParams: query },
|
||||
),
|
||||
BitbucketPullRequests.BitbucketPullRequestListSchema,
|
||||
BitbucketPullRequestListSchema,
|
||||
);
|
||||
}),
|
||||
Effect.map((list) =>
|
||||
list.values.map(BitbucketPullRequests.normalizeBitbucketPullRequestRecord),
|
||||
),
|
||||
Effect.map((list) => list.values.map(normalizeBitbucketPullRequestRecord)),
|
||||
),
|
||||
getPullRequest: (input) =>
|
||||
getRawPullRequest(input).pipe(
|
||||
Effect.map(BitbucketPullRequests.normalizeBitbucketPullRequestRecord),
|
||||
),
|
||||
getRawPullRequest(input).pipe(Effect.map(normalizeBitbucketPullRequestRecord)),
|
||||
getRepositoryCloneUrls: (input) =>
|
||||
getRepository(input).pipe(Effect.map(normalizeRepositoryCloneUrls)),
|
||||
createRepository: (input) =>
|
||||
@@ -675,7 +663,7 @@ export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
`/repositories/${encodeURIComponent(repository.workspace)}/${encodeURIComponent(repository.repoSlug)}/pullrequests`,
|
||||
),
|
||||
).pipe(HttpClientRequest.bodyJsonUnsafe(body)),
|
||||
BitbucketPullRequests.BitbucketPullRequestSchema,
|
||||
BitbucketPullRequestSchema,
|
||||
);
|
||||
}),
|
||||
getDefaultBranch: (input) =>
|
||||
@@ -766,4 +754,4 @@ export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(BitbucketApi, make());
|
||||
export const layer = Layer.effect(BitbucketApi, make);
|
||||
@@ -6,8 +6,8 @@ import * as Option from "effect/Option";
|
||||
import * as BitbucketApi from "./BitbucketApi.ts";
|
||||
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
|
||||
|
||||
function makeProvider(bitbucket: Partial<BitbucketApi.BitbucketApiShape>) {
|
||||
return BitbucketSourceControlProvider.make().pipe(
|
||||
function makeProvider(bitbucket: Partial<BitbucketApi.BitbucketApi["Service"]>) {
|
||||
return BitbucketSourceControlProvider.make.pipe(
|
||||
Effect.provide(Layer.mock(BitbucketApi.BitbucketApi)(bitbucket)),
|
||||
);
|
||||
}
|
||||
@@ -53,7 +53,8 @@ it.effect("maps Bitbucket PR summaries into provider-neutral change requests", (
|
||||
|
||||
it.effect("lists Bitbucket PRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let listInput: Parameters<BitbucketApi.BitbucketApiShape["listPullRequests"]>[0] | null = null;
|
||||
let listInput: Parameters<BitbucketApi.BitbucketApi["Service"]["listPullRequests"]>[0] | null =
|
||||
null;
|
||||
const provider = yield* makeProvider({
|
||||
listPullRequests: (input) => {
|
||||
listInput = input;
|
||||
@@ -79,8 +80,9 @@ it.effect("lists Bitbucket PRs through provider-neutral input names", () =>
|
||||
|
||||
it.effect("creates Bitbucket PRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let createInput: Parameters<BitbucketApi.BitbucketApiShape["createPullRequest"]>[0] | null =
|
||||
null;
|
||||
let createInput:
|
||||
| Parameters<BitbucketApi.BitbucketApi["Service"]["createPullRequest"]>[0]
|
||||
| null = null;
|
||||
const provider = yield* makeProvider({
|
||||
createPullRequest: (input) => {
|
||||
createInput = input;
|
||||
|
||||
@@ -4,9 +4,9 @@ import * as Option from "effect/Option";
|
||||
import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contracts";
|
||||
|
||||
import * as BitbucketApi from "./BitbucketApi.ts";
|
||||
import * as BitbucketPullRequests from "./bitbucketPullRequests.ts";
|
||||
import type { NormalizedBitbucketPullRequestRecord } from "./bitbucketPullRequests.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import type * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import type { SourceControlApiDiscoverySpec } from "./SourceControlProviderDiscovery.ts";
|
||||
|
||||
function providerError(
|
||||
operation: string,
|
||||
@@ -20,9 +20,7 @@ function providerError(
|
||||
});
|
||||
}
|
||||
|
||||
function toChangeRequest(
|
||||
summary: BitbucketPullRequests.NormalizedBitbucketPullRequestRecord,
|
||||
): ChangeRequest {
|
||||
function toChangeRequest(summary: NormalizedBitbucketPullRequestRecord): ChangeRequest {
|
||||
return {
|
||||
provider: "bitbucket",
|
||||
number: summary.number,
|
||||
@@ -44,7 +42,7 @@ function toChangeRequest(
|
||||
};
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeBitbucketSourceControlProvider")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
|
||||
return SourceControlProvider.SourceControlProvider.of({
|
||||
@@ -112,9 +110,9 @@ export const make = Effect.fn("makeBitbucketSourceControlProvider")(function* ()
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make());
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make);
|
||||
|
||||
export const makeDiscovery = Effect.fn("makeBitbucketSourceControlProviderDiscovery")(function* () {
|
||||
export const makeDiscovery = Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
|
||||
return {
|
||||
@@ -124,5 +122,5 @@ export const makeDiscovery = Effect.fn("makeBitbucketSourceControlProviderDiscov
|
||||
installHint:
|
||||
"Set T3CODE_BITBUCKET_EMAIL and T3CODE_BITBUCKET_API_TOKEN on the server (use a Bitbucket API token with pull request and repository scopes).",
|
||||
probeAuth: bitbucket.probeAuth,
|
||||
} satisfies SourceControlProviderDiscovery.SourceControlApiDiscoverySpec;
|
||||
} satisfies SourceControlApiDiscoverySpec;
|
||||
});
|
||||
@@ -15,7 +15,7 @@ const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({
|
||||
stderrTruncated: false,
|
||||
});
|
||||
|
||||
const mockRun = vi.fn<VcsProcess.VcsProcessShape["run"]>();
|
||||
const mockRun = vi.fn<VcsProcess.VcsProcess["Service"]["run"]>();
|
||||
|
||||
const layer = GitHubCli.layer.pipe(
|
||||
Layer.provide(
|
||||
|
||||
@@ -12,7 +12,11 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as GitHubPullRequests from "./gitHubPullRequests.ts";
|
||||
import {
|
||||
decodeGitHubPullRequestJson,
|
||||
decodeGitHubPullRequestListJson,
|
||||
formatGitHubJsonDecodeError,
|
||||
} from "./gitHubPullRequests.ts";
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 30_000;
|
||||
|
||||
@@ -44,57 +48,56 @@ export interface GitHubRepositoryCloneUrls {
|
||||
readonly sshUrl: string;
|
||||
}
|
||||
|
||||
export interface GitHubCliShape {
|
||||
readonly execute: (input: {
|
||||
readonly cwd: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => Effect.Effect<VcsProcess.VcsProcessOutput, GitHubCliError>;
|
||||
export class GitHubCli extends Context.Service<
|
||||
GitHubCli,
|
||||
{
|
||||
readonly execute: (input: {
|
||||
readonly cwd: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => Effect.Effect<VcsProcess.VcsProcessOutput, GitHubCliError>;
|
||||
|
||||
readonly listOpenPullRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly headSelector: string;
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<GitHubPullRequestSummary>, GitHubCliError>;
|
||||
readonly listOpenPullRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly headSelector: string;
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<GitHubPullRequestSummary>, GitHubCliError>;
|
||||
|
||||
readonly getPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<GitHubPullRequestSummary, GitHubCliError>;
|
||||
readonly getPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<GitHubPullRequestSummary, GitHubCliError>;
|
||||
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<GitHubRepositoryCloneUrls, GitHubCliError>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<GitHubRepositoryCloneUrls, GitHubCliError>;
|
||||
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<GitHubRepositoryCloneUrls, GitHubCliError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<GitHubRepositoryCloneUrls, GitHubCliError>;
|
||||
|
||||
readonly createPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, GitHubCliError>;
|
||||
readonly createPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, GitHubCliError>;
|
||||
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<string | null, GitHubCliError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<string | null, GitHubCliError>;
|
||||
|
||||
readonly checkoutPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, GitHubCliError>;
|
||||
}
|
||||
|
||||
export class GitHubCli extends Context.Service<GitHubCli, GitHubCliShape>()(
|
||||
"t3/sourceControl/GitHubCli",
|
||||
) {}
|
||||
readonly checkoutPullRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, GitHubCliError>;
|
||||
}
|
||||
>()("t3/sourceControl/GitHubCli") {}
|
||||
|
||||
function errorText(error: VcsError | unknown): string {
|
||||
if (typeof error === "object" && error !== null) {
|
||||
@@ -226,10 +229,10 @@ function decodeGitHubJson<S extends Schema.Top>(
|
||||
);
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeGitHubCli")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const process = yield* VcsProcess.VcsProcess;
|
||||
|
||||
const execute: GitHubCliShape["execute"] = (input) =>
|
||||
const execute: GitHubCli["Service"]["execute"] = (input) =>
|
||||
process
|
||||
.run({
|
||||
operation: "GitHubCli.execute",
|
||||
@@ -262,13 +265,13 @@ export const make = Effect.fn("makeGitHubCli")(function* () {
|
||||
Effect.flatMap((raw) =>
|
||||
raw.length === 0
|
||||
? Effect.succeed([])
|
||||
: Effect.sync(() => GitHubPullRequests.decodeGitHubPullRequestListJson(raw)).pipe(
|
||||
: Effect.sync(() => decodeGitHubPullRequestListJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) => {
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Effect.fail(
|
||||
new GitHubCliError({
|
||||
operation: "listOpenPullRequests",
|
||||
detail: `GitHub CLI returned invalid PR list JSON: ${GitHubPullRequests.formatGitHubJsonDecodeError(decoded.failure)}`,
|
||||
detail: `GitHub CLI returned invalid PR list JSON: ${formatGitHubJsonDecodeError(decoded.failure)}`,
|
||||
cause: decoded.failure,
|
||||
}),
|
||||
);
|
||||
@@ -294,13 +297,13 @@ export const make = Effect.fn("makeGitHubCli")(function* () {
|
||||
}).pipe(
|
||||
Effect.map((result) => result.stdout.trim()),
|
||||
Effect.flatMap((raw) =>
|
||||
Effect.sync(() => GitHubPullRequests.decodeGitHubPullRequestJson(raw)).pipe(
|
||||
Effect.sync(() => decodeGitHubPullRequestJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) => {
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Effect.fail(
|
||||
new GitHubCliError({
|
||||
operation: "getPullRequest",
|
||||
detail: `GitHub CLI returned invalid pull request JSON: ${GitHubPullRequests.formatGitHubJsonDecodeError(decoded.failure)}`,
|
||||
detail: `GitHub CLI returned invalid pull request JSON: ${formatGitHubJsonDecodeError(decoded.failure)}`,
|
||||
cause: decoded.failure,
|
||||
}),
|
||||
);
|
||||
@@ -372,4 +375,4 @@ export const make = Effect.fn("makeGitHubCli")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(GitHubCli, make());
|
||||
export const layer = Layer.effect(GitHubCli, make);
|
||||
@@ -24,8 +24,8 @@ const processResult = (
|
||||
stderrTruncated: false,
|
||||
});
|
||||
|
||||
function makeProvider(github: Partial<GitHubCli.GitHubCliShape>) {
|
||||
return GitHubSourceControlProvider.make().pipe(
|
||||
function makeProvider(github: Partial<GitHubCli.GitHubCli["Service"]>) {
|
||||
return GitHubSourceControlProvider.make.pipe(
|
||||
Effect.provide(Layer.mock(GitHubCli.GitHubCli)(github)),
|
||||
);
|
||||
}
|
||||
@@ -139,7 +139,8 @@ it.effect("treats empty non-open change request listing output as no results", (
|
||||
|
||||
it.effect("creates GitHub PRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let createInput: Parameters<GitHubCli.GitHubCliShape["createPullRequest"]>[0] | null = null;
|
||||
let createInput: Parameters<GitHubCli.GitHubCli["Service"]["createPullRequest"]>[0] | null =
|
||||
null;
|
||||
const provider = yield* makeProvider({
|
||||
createPullRequest: (input) => {
|
||||
createInput = input;
|
||||
|
||||
@@ -11,9 +11,15 @@ import {
|
||||
|
||||
import * as GitHubCli from "./GitHubCli.ts";
|
||||
import { findAuthenticatedGitHubAccount, parseGitHubAuthStatus } from "./gitHubAuthStatus.ts";
|
||||
import * as GitHubPullRequests from "./gitHubPullRequests.ts";
|
||||
import { decodeGitHubPullRequestListJson } from "./gitHubPullRequests.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import {
|
||||
combinedAuthOutput,
|
||||
firstSafeAuthLine,
|
||||
providerAuth,
|
||||
type SourceControlAuthProbeInput,
|
||||
type SourceControlCliDiscoverySpec,
|
||||
} from "./SourceControlProviderDiscovery.ts";
|
||||
const isSourceControlProviderError = Schema.is(SourceControlProviderError);
|
||||
|
||||
function providerError(
|
||||
@@ -50,14 +56,14 @@ function toChangeRequest(summary: GitHubCli.GitHubPullRequestSummary): ChangeReq
|
||||
};
|
||||
}
|
||||
|
||||
function parseGitHubAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) {
|
||||
const output = SourceControlProviderDiscovery.combinedAuthOutput(input);
|
||||
function parseGitHubAuth(input: SourceControlAuthProbeInput) {
|
||||
const output = combinedAuthOutput(input);
|
||||
const authStatus = parseGitHubAuthStatus(input.stdout);
|
||||
const authenticatedAccount = findAuthenticatedGitHubAccount(authStatus.accounts);
|
||||
const host = authenticatedAccount?.host;
|
||||
|
||||
if (authenticatedAccount) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "authenticated",
|
||||
account: authenticatedAccount.account,
|
||||
host,
|
||||
@@ -66,7 +72,7 @@ function parseGitHubAuth(input: SourceControlProviderDiscovery.SourceControlAuth
|
||||
|
||||
const failedAccount = authStatus.accounts.find((entry) => entry.active) ?? authStatus.accounts[0];
|
||||
if (authStatus.parsed) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unauthenticated",
|
||||
host: failedAccount?.host,
|
||||
detail:
|
||||
@@ -76,21 +82,17 @@ function parseGitHubAuth(input: SourceControlProviderDiscovery.SourceControlAuth
|
||||
}
|
||||
|
||||
if (input.exitCode !== 0) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unauthenticated",
|
||||
host,
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(output) ??
|
||||
"Run `gh auth login` to authenticate GitHub CLI.",
|
||||
detail: firstSafeAuthLine(output) ?? "Run `gh auth login` to authenticate GitHub CLI.",
|
||||
});
|
||||
}
|
||||
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unknown",
|
||||
host,
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(output) ??
|
||||
"GitHub CLI auth status could not be parsed.",
|
||||
detail: firstSafeAuthLine(output) ?? "GitHub CLI auth status could not be parsed.",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,12 +106,12 @@ export const discovery = {
|
||||
parseAuth: parseGitHubAuth,
|
||||
installHint:
|
||||
"Install the GitHub command-line tool (`gh`) via https://cli.github.com/ or your package manager (for example `brew install gh`).",
|
||||
} satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec;
|
||||
} satisfies SourceControlCliDiscoverySpec;
|
||||
|
||||
export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const github = yield* GitHubCli.GitHubCli;
|
||||
|
||||
const listChangeRequests: SourceControlProvider.SourceControlProviderShape["listChangeRequests"] =
|
||||
const listChangeRequests: SourceControlProvider.SourceControlProvider["Service"]["listChangeRequests"] =
|
||||
(input) => {
|
||||
if (input.state === "open") {
|
||||
return github
|
||||
@@ -147,7 +149,7 @@ export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
|
||||
if (raw.length === 0) {
|
||||
return Effect.succeed([]);
|
||||
}
|
||||
return Effect.sync(() => GitHubPullRequests.decodeGitHubPullRequestListJson(raw)).pipe(
|
||||
return Effect.sync(() => decodeGitHubPullRequestListJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) =>
|
||||
Result.isSuccess(decoded)
|
||||
? Effect.succeed(
|
||||
@@ -212,4 +214,4 @@ export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make());
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make);
|
||||
@@ -8,7 +8,7 @@ import { VcsProcessExitError } from "@t3tools/contracts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as GitLabCli from "./GitLabCli.ts";
|
||||
|
||||
const mockedRun = vi.fn<VcsProcess.VcsProcessShape["run"]>();
|
||||
const mockedRun = vi.fn<VcsProcess.VcsProcess["Service"]["run"]>();
|
||||
const layer = it.layer(
|
||||
GitLabCli.layer.pipe(
|
||||
Layer.provide(
|
||||
|
||||
@@ -10,7 +10,11 @@ import type * as DateTime from "effect/DateTime";
|
||||
import { TrimmedNonEmptyString, type SourceControlRepositoryVisibility } from "@t3tools/contracts";
|
||||
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as GitLabMergeRequests from "./gitLabMergeRequests.ts";
|
||||
import {
|
||||
decodeGitLabMergeRequestJson,
|
||||
decodeGitLabMergeRequestListJson,
|
||||
formatGitLabJsonDecodeError,
|
||||
} from "./gitLabMergeRequests.ts";
|
||||
import type * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 30_000;
|
||||
@@ -44,61 +48,60 @@ export interface GitLabRepositoryCloneUrls {
|
||||
readonly sshUrl: string;
|
||||
}
|
||||
|
||||
export interface GitLabCliShape {
|
||||
readonly execute: (input: {
|
||||
readonly cwd: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => Effect.Effect<VcsProcess.VcsProcessOutput, GitLabCliError>;
|
||||
export class GitLabCli extends Context.Service<
|
||||
GitLabCli,
|
||||
{
|
||||
readonly execute: (input: {
|
||||
readonly cwd: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => Effect.Effect<VcsProcess.VcsProcessOutput, GitLabCliError>;
|
||||
|
||||
readonly listMergeRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly state: "open" | "closed" | "merged" | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<GitLabMergeRequestSummary>, GitLabCliError>;
|
||||
readonly listMergeRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly state: "open" | "closed" | "merged" | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<GitLabMergeRequestSummary>, GitLabCliError>;
|
||||
|
||||
readonly getMergeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<GitLabMergeRequestSummary, GitLabCliError>;
|
||||
readonly getMergeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<GitLabMergeRequestSummary, GitLabCliError>;
|
||||
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<GitLabRepositoryCloneUrls, GitLabCliError>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<GitLabRepositoryCloneUrls, GitLabCliError>;
|
||||
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<GitLabRepositoryCloneUrls, GitLabCliError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<GitLabRepositoryCloneUrls, GitLabCliError>;
|
||||
|
||||
readonly createMergeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly target?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, GitLabCliError>;
|
||||
readonly createMergeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly baseBranch: string;
|
||||
readonly headSelector: string;
|
||||
readonly source?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly target?: SourceControlProvider.SourceControlRefSelector;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, GitLabCliError>;
|
||||
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<string | null, GitLabCliError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<string | null, GitLabCliError>;
|
||||
|
||||
readonly checkoutMergeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, GitLabCliError>;
|
||||
}
|
||||
|
||||
export class GitLabCli extends Context.Service<GitLabCli, GitLabCliShape>()(
|
||||
"t3/sourceControl/GitLabCli",
|
||||
) {}
|
||||
readonly checkoutMergeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, GitLabCliError>;
|
||||
}
|
||||
>()("t3/sourceControl/GitLabCli") {}
|
||||
|
||||
function isVcsProcessSpawnError(error: unknown): boolean {
|
||||
return (
|
||||
@@ -259,10 +262,10 @@ function parseRepositoryPath(repository: string): {
|
||||
return { namespacePath, projectPath };
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeGitLabCli")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const process = yield* VcsProcess.VcsProcess;
|
||||
|
||||
const execute: GitLabCliShape["execute"] = (input) =>
|
||||
const execute: GitLabCli["Service"]["execute"] = (input) =>
|
||||
process
|
||||
.run({
|
||||
operation: "GitLabCli.execute",
|
||||
@@ -294,13 +297,13 @@ export const make = Effect.fn("makeGitLabCli")(function* () {
|
||||
Effect.flatMap((raw) =>
|
||||
raw.length === 0
|
||||
? Effect.succeed([])
|
||||
: Effect.sync(() => GitLabMergeRequests.decodeGitLabMergeRequestListJson(raw)).pipe(
|
||||
: Effect.sync(() => decodeGitLabMergeRequestListJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) => {
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Effect.fail(
|
||||
new GitLabCliError({
|
||||
operation: "listMergeRequests",
|
||||
detail: `GitLab CLI returned invalid MR list JSON: ${GitLabMergeRequests.formatGitLabJsonDecodeError(decoded.failure)}`,
|
||||
detail: `GitLab CLI returned invalid MR list JSON: ${formatGitLabJsonDecodeError(decoded.failure)}`,
|
||||
cause: decoded.failure,
|
||||
}),
|
||||
);
|
||||
@@ -318,13 +321,13 @@ export const make = Effect.fn("makeGitLabCli")(function* () {
|
||||
}).pipe(
|
||||
Effect.map((result) => result.stdout.trim()),
|
||||
Effect.flatMap((raw) =>
|
||||
Effect.sync(() => GitLabMergeRequests.decodeGitLabMergeRequestJson(raw)).pipe(
|
||||
Effect.sync(() => decodeGitLabMergeRequestJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) => {
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Effect.fail(
|
||||
new GitLabCliError({
|
||||
operation: "getMergeRequest",
|
||||
detail: `GitLab CLI returned invalid merge request JSON: ${GitLabMergeRequests.formatGitLabJsonDecodeError(decoded.failure)}`,
|
||||
detail: `GitLab CLI returned invalid merge request JSON: ${formatGitLabJsonDecodeError(decoded.failure)}`,
|
||||
cause: decoded.failure,
|
||||
}),
|
||||
);
|
||||
@@ -449,4 +452,4 @@ export const make = Effect.fn("makeGitLabCli")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(GitLabCli, make());
|
||||
export const layer = Layer.effect(GitLabCli, make);
|
||||
@@ -8,8 +8,8 @@ import * as GitLabCli from "./GitLabCli.ts";
|
||||
import { parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
|
||||
import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
|
||||
|
||||
function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) {
|
||||
return GitLabSourceControlProvider.make().pipe(
|
||||
function makeProvider(gitlab: Partial<GitLabCli.GitLabCli["Service"]>) {
|
||||
return GitLabSourceControlProvider.make.pipe(
|
||||
Effect.provide(Layer.mock(GitLabCli.GitLabCli)(gitlab)),
|
||||
);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ it.effect("maps GitLab MR summaries into provider-neutral change requests", () =
|
||||
|
||||
it.effect("lists GitLab MRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let listInput: Parameters<GitLabCli.GitLabCliShape["listMergeRequests"]>[0] | null = null;
|
||||
let listInput: Parameters<GitLabCli.GitLabCli["Service"]["listMergeRequests"]>[0] | null = null;
|
||||
const provider = yield* makeProvider({
|
||||
listMergeRequests: (input) => {
|
||||
listInput = input;
|
||||
@@ -80,7 +80,8 @@ it.effect("lists GitLab MRs through provider-neutral input names", () =>
|
||||
|
||||
it.effect("creates GitLab MRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let createInput: Parameters<GitLabCli.GitLabCliShape["createMergeRequest"]>[0] | null = null;
|
||||
let createInput: Parameters<GitLabCli.GitLabCli["Service"]["createMergeRequest"]>[0] | null =
|
||||
null;
|
||||
const provider = yield* makeProvider({
|
||||
createMergeRequest: (input) => {
|
||||
createInput = input;
|
||||
|
||||
@@ -5,7 +5,16 @@ import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contrac
|
||||
|
||||
import * as GitLabCli from "./GitLabCli.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import {
|
||||
combinedAuthOutput,
|
||||
firstSafeAuthLine,
|
||||
matchFirst,
|
||||
parseCliHost,
|
||||
providerAuth,
|
||||
type SourceControlAuthProbeInput,
|
||||
type SourceControlCliDiscoverySpec,
|
||||
type SourceControlUnknownRemoteRefinementInput,
|
||||
} from "./SourceControlProviderDiscovery.ts";
|
||||
import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
|
||||
|
||||
function providerError(
|
||||
@@ -42,48 +51,42 @@ function toChangeRequest(summary: GitLabCli.GitLabMergeRequestSummary): ChangeRe
|
||||
};
|
||||
}
|
||||
|
||||
function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) {
|
||||
const output = SourceControlProviderDiscovery.combinedAuthOutput(input);
|
||||
function parseGitLabAuth(input: SourceControlAuthProbeInput) {
|
||||
const output = combinedAuthOutput(input);
|
||||
const authenticatedHost = findAuthenticatedGitLabHost(parseGitLabAuthStatusHosts(output));
|
||||
const account =
|
||||
authenticatedHost?.account ??
|
||||
SourceControlProviderDiscovery.matchFirst(output, [
|
||||
matchFirst(output, [
|
||||
/Logged in to .* as\s+([^\s(]+)/iu,
|
||||
/Logged in to .* account\s+([^\s(]+)/iu,
|
||||
/account:\s*([^\s(]+)/iu,
|
||||
]);
|
||||
const host = authenticatedHost?.host ?? SourceControlProviderDiscovery.parseCliHost(output);
|
||||
const host = authenticatedHost?.host ?? parseCliHost(output);
|
||||
|
||||
if (account) {
|
||||
return SourceControlProviderDiscovery.providerAuth({ status: "authenticated", account, host });
|
||||
return providerAuth({ status: "authenticated", account, host });
|
||||
}
|
||||
|
||||
if (input.exitCode !== 0) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unauthenticated",
|
||||
host,
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(output) ??
|
||||
"Run `glab auth login` to authenticate GitLab CLI.",
|
||||
detail: firstSafeAuthLine(output) ?? "Run `glab auth login` to authenticate GitLab CLI.",
|
||||
});
|
||||
}
|
||||
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unknown",
|
||||
host,
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(output) ??
|
||||
"GitLab CLI auth status could not be parsed.",
|
||||
detail: firstSafeAuthLine(output) ?? "GitLab CLI auth status could not be parsed.",
|
||||
});
|
||||
}
|
||||
|
||||
function refineUnknownGitLabRemote(
|
||||
input: SourceControlProviderDiscovery.SourceControlUnknownRemoteRefinementInput,
|
||||
) {
|
||||
function refineUnknownGitLabRemote(input: SourceControlUnknownRemoteRefinementInput) {
|
||||
const host = input.context.provider.name.toLowerCase();
|
||||
const authenticated = parseGitLabAuthStatusHosts(
|
||||
SourceControlProviderDiscovery.combinedAuthOutput(input.auth),
|
||||
).some((entry) => entry.account !== null && entry.host === host);
|
||||
const authenticated = parseGitLabAuthStatusHosts(combinedAuthOutput(input.auth)).some(
|
||||
(entry) => entry.account !== null && entry.host === host,
|
||||
);
|
||||
|
||||
if (!authenticated) {
|
||||
return null;
|
||||
@@ -107,9 +110,9 @@ export const discovery = {
|
||||
refineUnknownRemote: refineUnknownGitLabRemote,
|
||||
installHint:
|
||||
"Install the GitLab command-line tool (`glab`) from https://gitlab.com/gitlab-org/cli or your package manager (for example `brew install glab`).",
|
||||
} satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec;
|
||||
} satisfies SourceControlCliDiscoverySpec;
|
||||
|
||||
export const make = Effect.fn("makeGitLabSourceControlProvider")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const gitlab = yield* GitLabCli.GitLabCli;
|
||||
|
||||
return SourceControlProvider.SourceControlProvider.of({
|
||||
@@ -167,4 +170,4 @@ export const make = Effect.fn("makeGitLabSourceControlProvider")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make());
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make);
|
||||
@@ -6,7 +6,7 @@ import * as Option from "effect/Option";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { VcsProcessSpawnError } from "@t3tools/contracts";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
|
||||
@@ -17,15 +17,15 @@ import * as SourceControlDiscovery from "./SourceControlDiscovery.ts";
|
||||
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
|
||||
|
||||
const sourceControlProviderRegistryTestLayer = (input: {
|
||||
readonly bitbucket: Partial<BitbucketApi.BitbucketApiShape>;
|
||||
readonly process: Partial<VcsProcess.VcsProcessShape>;
|
||||
readonly bitbucket: Partial<BitbucketApi.BitbucketApi["Service"]>;
|
||||
readonly process: Partial<VcsProcess.VcsProcess["Service"]>;
|
||||
}) =>
|
||||
SourceControlProviderRegistry.layer.pipe(
|
||||
Layer.provide(
|
||||
Layer.mergeAll(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-registry-test-" }).pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
),
|
||||
ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-source-control-registry-test-",
|
||||
}).pipe(Layer.provide(NodeServices.layer)),
|
||||
Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({}),
|
||||
Layer.mock(BitbucketApi.BitbucketApi)(input.bitbucket),
|
||||
Layer.mock(GitHubCli.GitHubCli)({}),
|
||||
@@ -88,10 +88,12 @@ it.effect("reports implemented tools separately from locally available executabl
|
||||
}),
|
||||
);
|
||||
},
|
||||
} satisfies Partial<VcsProcess.VcsProcessShape>;
|
||||
} satisfies Partial<VcsProcess.VcsProcess["Service"]>;
|
||||
const testLayer = SourceControlDiscovery.layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
|
||||
ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-source-control-discovery-",
|
||||
}),
|
||||
),
|
||||
Layer.provide(Layer.mock(VcsProcess.VcsProcess)(processMock)),
|
||||
Layer.provide(
|
||||
@@ -215,10 +217,12 @@ Logged in to gitlab.com as gitlab-user
|
||||
}),
|
||||
);
|
||||
},
|
||||
} satisfies Partial<VcsProcess.VcsProcessShape>;
|
||||
} satisfies Partial<VcsProcess.VcsProcess["Service"]>;
|
||||
const testLayer = SourceControlDiscovery.layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-auth-discovery-" }),
|
||||
ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-source-control-auth-discovery-",
|
||||
}),
|
||||
),
|
||||
Layer.provide(Layer.mock(VcsProcess.VcsProcess)(processMock)),
|
||||
Layer.provide(
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as Option from "effect/Option";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import { detailFromCause, firstNonEmptyLine } from "./SourceControlProviderDiscovery.ts";
|
||||
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
|
||||
|
||||
interface DiscoveryProbe {
|
||||
@@ -57,91 +57,86 @@ const VCS_PROBES: ReadonlyArray<VcsProbe> = [
|
||||
},
|
||||
];
|
||||
|
||||
export interface SourceControlDiscoveryShape {
|
||||
readonly discover: Effect.Effect<SourceControlDiscoveryResult>;
|
||||
}
|
||||
|
||||
export class SourceControlDiscovery extends Context.Service<
|
||||
SourceControlDiscovery,
|
||||
SourceControlDiscoveryShape
|
||||
{
|
||||
readonly discover: Effect.Effect<SourceControlDiscoveryResult>;
|
||||
}
|
||||
>()("t3/sourceControl/SourceControlDiscovery") {}
|
||||
|
||||
export const layer = Layer.effect(
|
||||
SourceControlDiscovery,
|
||||
Effect.gen(function* () {
|
||||
const config = yield* ServerConfig;
|
||||
const process = yield* VcsProcess.VcsProcess;
|
||||
const sourceControlProviders =
|
||||
yield* SourceControlProviderRegistry.SourceControlProviderRegistry;
|
||||
export const make = Effect.gen(function* () {
|
||||
const config = yield* ServerConfig;
|
||||
const process = yield* VcsProcess.VcsProcess;
|
||||
const sourceControlProviders = yield* SourceControlProviderRegistry.SourceControlProviderRegistry;
|
||||
|
||||
const probe = <Kind extends VcsDriverKind>(
|
||||
input: DiscoveryProbe & { readonly kind: Kind },
|
||||
): Effect.Effect<DiscoveryProbeResult<Kind>> => {
|
||||
const executable = input.executable;
|
||||
const versionArgs = input.versionArgs;
|
||||
const probe = <Kind extends VcsDriverKind>(
|
||||
input: DiscoveryProbe & { readonly kind: Kind },
|
||||
): Effect.Effect<DiscoveryProbeResult<Kind>> => {
|
||||
const executable = input.executable;
|
||||
const versionArgs = input.versionArgs;
|
||||
|
||||
if (!executable || !versionArgs) {
|
||||
return Effect.succeed({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
implemented: input.implemented,
|
||||
status: "missing" as const,
|
||||
version: Option.none<string>(),
|
||||
installHint: input.installHint,
|
||||
detail: Option.some(input.installHint),
|
||||
} satisfies DiscoveryProbeResult<Kind>);
|
||||
}
|
||||
if (!executable || !versionArgs) {
|
||||
return Effect.succeed({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
implemented: input.implemented,
|
||||
status: "missing" as const,
|
||||
version: Option.none<string>(),
|
||||
installHint: input.installHint,
|
||||
detail: Option.some(input.installHint),
|
||||
} satisfies DiscoveryProbeResult<Kind>);
|
||||
}
|
||||
|
||||
return process
|
||||
.run({
|
||||
operation: "source-control.discovery.probe",
|
||||
command: executable,
|
||||
args: versionArgs,
|
||||
cwd: config.cwd,
|
||||
timeoutMs: 5_000,
|
||||
maxOutputBytes: 8_000,
|
||||
appendTruncationMarker: true,
|
||||
})
|
||||
.pipe(
|
||||
Effect.map(
|
||||
(result) =>
|
||||
({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
executable,
|
||||
implemented: input.implemented,
|
||||
status: "available" as const,
|
||||
version: Option.orElse(
|
||||
SourceControlProviderDiscovery.firstNonEmptyLine(result.stdout),
|
||||
() => SourceControlProviderDiscovery.firstNonEmptyLine(result.stderr),
|
||||
),
|
||||
installHint: input.installHint,
|
||||
detail: Option.none<string>(),
|
||||
}) satisfies DiscoveryProbeResult<Kind>,
|
||||
),
|
||||
Effect.catch((cause) =>
|
||||
Effect.succeed({
|
||||
return process
|
||||
.run({
|
||||
operation: "source-control.discovery.probe",
|
||||
command: executable,
|
||||
args: versionArgs,
|
||||
cwd: config.cwd,
|
||||
timeoutMs: 5_000,
|
||||
maxOutputBytes: 8_000,
|
||||
appendTruncationMarker: true,
|
||||
})
|
||||
.pipe(
|
||||
Effect.map(
|
||||
(result) =>
|
||||
({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
executable,
|
||||
implemented: input.implemented,
|
||||
status: "missing" as const,
|
||||
version: Option.none<string>(),
|
||||
status: "available" as const,
|
||||
version: Option.orElse(firstNonEmptyLine(result.stdout), () =>
|
||||
firstNonEmptyLine(result.stderr),
|
||||
),
|
||||
installHint: input.installHint,
|
||||
detail: SourceControlProviderDiscovery.detailFromCause(cause),
|
||||
} satisfies DiscoveryProbeResult<Kind>),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
return SourceControlDiscovery.of({
|
||||
discover: Effect.all({
|
||||
versionControlSystems: Effect.all(
|
||||
VCS_PROBES.map((entry) => probe(entry)) as ReadonlyArray<Effect.Effect<VcsDiscoveryItem>>,
|
||||
{ concurrency: "unbounded" },
|
||||
detail: Option.none<string>(),
|
||||
}) satisfies DiscoveryProbeResult<Kind>,
|
||||
),
|
||||
sourceControlProviders: sourceControlProviders.discover,
|
||||
}),
|
||||
});
|
||||
}),
|
||||
);
|
||||
Effect.catch((cause) =>
|
||||
Effect.succeed({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
executable,
|
||||
implemented: input.implemented,
|
||||
status: "missing" as const,
|
||||
version: Option.none<string>(),
|
||||
installHint: input.installHint,
|
||||
detail: detailFromCause(cause),
|
||||
} satisfies DiscoveryProbeResult<Kind>),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
return SourceControlDiscovery.of({
|
||||
discover: Effect.all({
|
||||
versionControlSystems: Effect.all(
|
||||
VCS_PROBES.map((entry) => probe(entry)) as ReadonlyArray<Effect.Effect<VcsDiscoveryItem>>,
|
||||
{ concurrency: "unbounded" },
|
||||
),
|
||||
sourceControlProviders: sourceControlProviders.discover,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlDiscovery, make);
|
||||
@@ -49,54 +49,52 @@ export function sourceControlRefFromInput(input: {
|
||||
return input.source ?? parseSourceControlOwnerRef(input.headSelector);
|
||||
}
|
||||
|
||||
export interface SourceControlProviderShape {
|
||||
readonly kind: SourceControlProviderKind;
|
||||
readonly listChangeRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly source?: SourceControlRefSelector;
|
||||
readonly headSelector: string;
|
||||
readonly state: ChangeRequestState | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<ChangeRequest>, SourceControlProviderError>;
|
||||
readonly getChangeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<ChangeRequest, SourceControlProviderError>;
|
||||
readonly createChangeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly source?: SourceControlRefSelector;
|
||||
readonly target?: SourceControlRefSelector;
|
||||
readonly baseRefName: string;
|
||||
readonly headSelector: string;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, SourceControlProviderError>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, SourceControlProviderError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, SourceControlProviderError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
}) => Effect.Effect<string | null, SourceControlProviderError>;
|
||||
readonly checkoutChangeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, SourceControlProviderError>;
|
||||
}
|
||||
|
||||
export class SourceControlProvider extends Context.Service<
|
||||
SourceControlProvider,
|
||||
SourceControlProviderShape
|
||||
{
|
||||
readonly kind: SourceControlProviderKind;
|
||||
readonly listChangeRequests: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly source?: SourceControlRefSelector;
|
||||
readonly headSelector: string;
|
||||
readonly state: ChangeRequestState | "all";
|
||||
readonly limit?: number;
|
||||
}) => Effect.Effect<ReadonlyArray<ChangeRequest>, SourceControlProviderError>;
|
||||
readonly getChangeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
}) => Effect.Effect<ChangeRequest, SourceControlProviderError>;
|
||||
readonly createChangeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly source?: SourceControlRefSelector;
|
||||
readonly target?: SourceControlRefSelector;
|
||||
readonly baseRefName: string;
|
||||
readonly headSelector: string;
|
||||
readonly title: string;
|
||||
readonly bodyFile: string;
|
||||
}) => Effect.Effect<void, SourceControlProviderError>;
|
||||
readonly getRepositoryCloneUrls: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly repository: string;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, SourceControlProviderError>;
|
||||
readonly createRepository: (input: {
|
||||
readonly cwd: string;
|
||||
readonly repository: string;
|
||||
readonly visibility: SourceControlRepositoryVisibility;
|
||||
}) => Effect.Effect<SourceControlRepositoryCloneUrls, SourceControlProviderError>;
|
||||
readonly getDefaultBranch: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
}) => Effect.Effect<string | null, SourceControlProviderError>;
|
||||
readonly checkoutChangeRequest: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProviderContext;
|
||||
readonly reference: string;
|
||||
readonly force?: boolean;
|
||||
}) => Effect.Effect<void, SourceControlProviderError>;
|
||||
}
|
||||
>()("t3/sourceControl/SourceControlProvider") {}
|
||||
@@ -158,7 +158,7 @@ function isCliRemoteRefinementSpec(
|
||||
|
||||
function probeCli(input: {
|
||||
readonly spec: SourceControlCliDiscoverySpec;
|
||||
readonly process: VcsProcess.VcsProcessShape;
|
||||
readonly process: VcsProcess.VcsProcess["Service"];
|
||||
readonly cwd: string;
|
||||
}): Effect.Effect<DiscoveryProbeResult> {
|
||||
return input.process
|
||||
@@ -202,7 +202,7 @@ function probeCli(input: {
|
||||
|
||||
export function probeSourceControlProvider(input: {
|
||||
readonly spec: SourceControlProviderDiscoverySpec;
|
||||
readonly process: VcsProcess.VcsProcessShape;
|
||||
readonly process: VcsProcess.VcsProcess["Service"];
|
||||
readonly cwd: string;
|
||||
}): Effect.Effect<SourceControlProviderDiscoveryItem> {
|
||||
if (input.spec.type === "api") {
|
||||
@@ -270,7 +270,7 @@ export function probeSourceControlProvider(input: {
|
||||
export const refineUnknownRemoteProvider = Effect.fn("refineUnknownRemoteProvider")(
|
||||
function* (input: {
|
||||
readonly specs: ReadonlyArray<SourceControlProviderDiscoverySpec>;
|
||||
readonly process: VcsProcess.VcsProcessShape;
|
||||
readonly process: VcsProcess.VcsProcess["Service"];
|
||||
readonly cwd: string;
|
||||
readonly context: SourceControlProvider.SourceControlProviderContext | null;
|
||||
}): Effect.fn.Return<SourceControlProvider.SourceControlProviderContext | null> {
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import type * as VcsDriver from "../vcs/VcsDriver.ts";
|
||||
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
@@ -37,7 +37,7 @@ function makeRegistry(input: {
|
||||
readonly name: string;
|
||||
readonly url: string;
|
||||
}>;
|
||||
readonly process?: Partial<VcsProcess.VcsProcessShape>;
|
||||
readonly process?: Partial<VcsProcess.VcsProcess["Service"]>;
|
||||
}) {
|
||||
const driver = {
|
||||
listRemotes: () =>
|
||||
@@ -53,10 +53,10 @@ function makeRegistry(input: {
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
}),
|
||||
} satisfies Partial<VcsDriver.VcsDriverShape>;
|
||||
} satisfies Partial<VcsDriver.VcsDriver["Service"]>;
|
||||
|
||||
const registryLayer = Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({
|
||||
get: () => Effect.succeed(driver as unknown as VcsDriver.VcsDriverShape),
|
||||
get: () => Effect.succeed(driver as unknown as VcsDriver.VcsDriver["Service"]),
|
||||
resolve: () =>
|
||||
Effect.succeed({
|
||||
kind: "git",
|
||||
@@ -70,7 +70,7 @@ function makeRegistry(input: {
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
},
|
||||
driver: driver as unknown as VcsDriver.VcsDriverShape,
|
||||
driver: driver as unknown as VcsDriver.VcsDriver["Service"],
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ function makeRegistry(input: {
|
||||
...input.process,
|
||||
});
|
||||
|
||||
return SourceControlProviderRegistry.make().pipe(
|
||||
return SourceControlProviderRegistry.make.pipe(
|
||||
Effect.provide(
|
||||
Layer.mergeAll(
|
||||
registryLayer,
|
||||
@@ -88,9 +88,9 @@ function makeRegistry(input: {
|
||||
Layer.mock(BitbucketApi.BitbucketApi)({}),
|
||||
Layer.mock(GitHubCli.GitHubCli)({}),
|
||||
Layer.mock(GitLabCli.GitLabCli)({}),
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-registry-test-" }).pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
),
|
||||
ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-source-control-registry-test-",
|
||||
}).pipe(Layer.provide(NodeServices.layer)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,11 @@ import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvide
|
||||
import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";
|
||||
import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import {
|
||||
probeSourceControlProvider,
|
||||
refineUnknownRemoteProvider,
|
||||
type SourceControlProviderDiscoverySpec,
|
||||
} from "./SourceControlProviderDiscovery.ts";
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
@@ -26,36 +30,40 @@ const PROVIDER_DETECTION_CACHE_TTL = Duration.seconds(5);
|
||||
|
||||
export interface SourceControlProviderRegistration {
|
||||
readonly kind: SourceControlProviderKind;
|
||||
readonly provider: SourceControlProvider.SourceControlProviderShape;
|
||||
readonly discovery: SourceControlProviderDiscovery.SourceControlProviderDiscoverySpec;
|
||||
readonly provider: SourceControlProvider.SourceControlProvider["Service"];
|
||||
readonly discovery: SourceControlProviderDiscoverySpec;
|
||||
}
|
||||
|
||||
export interface SourceControlProviderHandle {
|
||||
readonly provider: SourceControlProvider.SourceControlProviderShape;
|
||||
readonly provider: SourceControlProvider.SourceControlProvider["Service"];
|
||||
readonly context: SourceControlProvider.SourceControlProviderContext | null;
|
||||
}
|
||||
|
||||
export interface SourceControlProviderRegistryShape {
|
||||
readonly get: (
|
||||
kind: SourceControlProviderKind,
|
||||
) => Effect.Effect<SourceControlProvider.SourceControlProviderShape, SourceControlProviderError>;
|
||||
readonly resolveHandle: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<SourceControlProviderHandle, SourceControlProviderError>;
|
||||
readonly resolve: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<SourceControlProvider.SourceControlProviderShape, SourceControlProviderError>;
|
||||
readonly discover: Effect.Effect<ReadonlyArray<SourceControlProviderDiscoveryItem>>;
|
||||
}
|
||||
|
||||
export class SourceControlProviderRegistry extends Context.Service<
|
||||
SourceControlProviderRegistry,
|
||||
SourceControlProviderRegistryShape
|
||||
{
|
||||
readonly get: (
|
||||
kind: SourceControlProviderKind,
|
||||
) => Effect.Effect<
|
||||
SourceControlProvider.SourceControlProvider["Service"],
|
||||
SourceControlProviderError
|
||||
>;
|
||||
readonly resolveHandle: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<SourceControlProviderHandle, SourceControlProviderError>;
|
||||
readonly resolve: (input: {
|
||||
readonly cwd: string;
|
||||
}) => Effect.Effect<
|
||||
SourceControlProvider.SourceControlProvider["Service"],
|
||||
SourceControlProviderError
|
||||
>;
|
||||
readonly discover: Effect.Effect<ReadonlyArray<SourceControlProviderDiscoveryItem>>;
|
||||
}
|
||||
>()("t3/sourceControl/SourceControlProviderRegistry") {}
|
||||
|
||||
function unsupportedProvider(
|
||||
kind: SourceControlProviderKind,
|
||||
): SourceControlProvider.SourceControlProviderShape {
|
||||
): SourceControlProvider.SourceControlProvider["Service"] {
|
||||
const unsupported = (operation: string) =>
|
||||
Effect.fail(
|
||||
new SourceControlProviderError({
|
||||
@@ -113,9 +121,9 @@ function selectProviderContext(
|
||||
}
|
||||
|
||||
function bindProviderContext(
|
||||
provider: SourceControlProvider.SourceControlProviderShape,
|
||||
provider: SourceControlProvider.SourceControlProvider["Service"],
|
||||
context: SourceControlProvider.SourceControlProviderContext | null,
|
||||
): SourceControlProvider.SourceControlProviderShape {
|
||||
): SourceControlProvider.SourceControlProvider["Service"] {
|
||||
if (context === null) {
|
||||
return provider;
|
||||
}
|
||||
@@ -163,11 +171,11 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit
|
||||
const vcsRegistry = yield* VcsDriverRegistry.VcsDriverRegistry;
|
||||
const providers = new Map<
|
||||
SourceControlProviderKind,
|
||||
SourceControlProvider.SourceControlProviderShape
|
||||
SourceControlProvider.SourceControlProvider["Service"]
|
||||
>(registrations.map((registration) => [registration.kind, registration.provider]));
|
||||
const discoverySpecs = registrations.map((registration) => registration.discovery);
|
||||
|
||||
const get: SourceControlProviderRegistryShape["get"] = (kind) =>
|
||||
const get: SourceControlProviderRegistry["Service"]["get"] = (kind) =>
|
||||
Effect.succeed(providers.get(kind) ?? unsupportedProvider(kind));
|
||||
|
||||
const detectProviderContext = Effect.fn("SourceControlProviderRegistry.detectProviderContext")(
|
||||
@@ -180,7 +188,7 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit
|
||||
.pipe(Effect.mapError((error) => providerDetectionError("detectProvider", cwd, error)));
|
||||
const context = selectProviderContext(remotes.remotes);
|
||||
|
||||
return yield* SourceControlProviderDiscovery.refineUnknownRemoteProvider({
|
||||
return yield* refineUnknownRemoteProvider({
|
||||
specs: discoverySpecs,
|
||||
process,
|
||||
cwd,
|
||||
@@ -198,7 +206,7 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit
|
||||
timeToLive: (exit) => (Exit.isSuccess(exit) ? PROVIDER_DETECTION_CACHE_TTL : Duration.zero),
|
||||
});
|
||||
|
||||
const resolveHandle: SourceControlProviderRegistryShape["resolveHandle"] = (input) =>
|
||||
const resolveHandle: SourceControlProviderRegistry["Service"]["resolveHandle"] = (input) =>
|
||||
Cache.get(providerContextCache, input.cwd).pipe(
|
||||
Effect.map((context) => {
|
||||
const kind = context?.provider.kind ?? "unknown";
|
||||
@@ -216,7 +224,7 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit
|
||||
resolve: (input) => resolveHandle(input).pipe(Effect.map((handle) => handle.provider)),
|
||||
discover: Effect.all(
|
||||
discoverySpecs.map((spec) =>
|
||||
SourceControlProviderDiscovery.probeSourceControlProvider({
|
||||
probeSourceControlProvider({
|
||||
spec,
|
||||
process,
|
||||
cwd: config.cwd,
|
||||
@@ -228,12 +236,12 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit
|
||||
},
|
||||
);
|
||||
|
||||
export const make = Effect.fn("makeSourceControlProviderRegistry")(function* () {
|
||||
const github = yield* GitHubSourceControlProvider.make();
|
||||
const gitlab = yield* GitLabSourceControlProvider.make();
|
||||
const bitbucket = yield* BitbucketSourceControlProvider.make();
|
||||
const bitbucketDiscovery = yield* BitbucketSourceControlProvider.makeDiscovery();
|
||||
const azureDevOps = yield* AzureDevOpsSourceControlProvider.make();
|
||||
export const make = Effect.gen(function* () {
|
||||
const github = yield* GitHubSourceControlProvider.make;
|
||||
const gitlab = yield* GitLabSourceControlProvider.make;
|
||||
const bitbucket = yield* BitbucketSourceControlProvider.make;
|
||||
const bitbucketDiscovery = yield* BitbucketSourceControlProvider.makeDiscovery;
|
||||
const azureDevOps = yield* AzureDevOpsSourceControlProvider.make;
|
||||
return yield* makeWithProviders([
|
||||
{
|
||||
kind: "github",
|
||||
@@ -258,4 +266,4 @@ export const make = Effect.fn("makeSourceControlProviderRegistry")(function* ()
|
||||
]);
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlProviderRegistry, make());
|
||||
export const layer = Layer.effect(SourceControlProviderRegistry, make);
|
||||
@@ -7,7 +7,7 @@ import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { GitCommandError, type SourceControlProviderError } from "@t3tools/contracts";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
|
||||
import type * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
|
||||
@@ -20,8 +20,8 @@ const CLONE_URLS = {
|
||||
};
|
||||
|
||||
function makeProvider(
|
||||
overrides: Partial<SourceControlProvider.SourceControlProviderShape> = {},
|
||||
): SourceControlProvider.SourceControlProviderShape {
|
||||
overrides: Partial<SourceControlProvider.SourceControlProvider["Service"]> = {},
|
||||
): SourceControlProvider.SourceControlProvider["Service"] {
|
||||
const unsupported = (operation: string) =>
|
||||
Effect.die(`unexpected provider operation ${operation}`) as Effect.Effect<
|
||||
never,
|
||||
@@ -52,8 +52,8 @@ function processOutput(): GitVcsDriver.ExecuteGitResult {
|
||||
}
|
||||
|
||||
function makeLayer(input: {
|
||||
readonly provider?: SourceControlProvider.SourceControlProviderShape;
|
||||
readonly git?: Partial<GitVcsDriver.GitVcsDriverShape>;
|
||||
readonly provider?: SourceControlProvider.SourceControlProvider["Service"];
|
||||
readonly git?: Partial<GitVcsDriver.GitVcsDriver["Service"]>;
|
||||
}) {
|
||||
return SourceControlRepositoryService.layer.pipe(
|
||||
Layer.provide(
|
||||
|
||||
@@ -24,21 +24,19 @@ import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
|
||||
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
|
||||
const isSourceControlRepositoryError = Schema.is(SourceControlRepositoryError);
|
||||
|
||||
export interface SourceControlRepositoryServiceShape {
|
||||
readonly lookupRepository: (
|
||||
input: SourceControlRepositoryLookupInput,
|
||||
) => Effect.Effect<SourceControlRepositoryInfo, SourceControlRepositoryError>;
|
||||
readonly cloneRepository: (
|
||||
input: SourceControlCloneRepositoryInput,
|
||||
) => Effect.Effect<SourceControlCloneRepositoryResult, SourceControlRepositoryError>;
|
||||
readonly publishRepository: (
|
||||
input: SourceControlPublishRepositoryInput,
|
||||
) => Effect.Effect<SourceControlPublishRepositoryResult, SourceControlRepositoryError>;
|
||||
}
|
||||
|
||||
export class SourceControlRepositoryService extends Context.Service<
|
||||
SourceControlRepositoryService,
|
||||
SourceControlRepositoryServiceShape
|
||||
{
|
||||
readonly lookupRepository: (
|
||||
input: SourceControlRepositoryLookupInput,
|
||||
) => Effect.Effect<SourceControlRepositoryInfo, SourceControlRepositoryError>;
|
||||
readonly cloneRepository: (
|
||||
input: SourceControlCloneRepositoryInput,
|
||||
) => Effect.Effect<SourceControlCloneRepositoryResult, SourceControlRepositoryError>;
|
||||
readonly publishRepository: (
|
||||
input: SourceControlPublishRepositoryInput,
|
||||
) => Effect.Effect<SourceControlPublishRepositoryResult, SourceControlRepositoryError>;
|
||||
}
|
||||
>()("t3/sourceControl/SourceControlRepositoryService") {}
|
||||
|
||||
function detailFromUnknown(cause: unknown): string {
|
||||
@@ -116,7 +114,7 @@ function expandHomePath(input: string, path: Path.Path): string {
|
||||
return input;
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeSourceControlRepositoryService")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const config = yield* ServerConfig;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const git = yield* GitVcsDriver.GitVcsDriver;
|
||||
@@ -315,4 +313,4 @@ export const make = Effect.fn("makeSourceControlRepositoryService")(function* ()
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlRepositoryService, make());
|
||||
export const layer = Layer.effect(SourceControlRepositoryService, make);
|
||||
Reference in new issue
Block a user