feat(source-control): support Forgejo and Gitea with fj and tea (#11436)
This commit is contained in:
1 parent
c29976458a
commit
6fd68f5c3e
66 files changed
+4545
-102
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import * as NodeUtil from "node:util";
|
||||
import type {
|
||||
SourceControlProviderAuth,
|
||||
SourceControlProviderDiscoveryItem,
|
||||
@@ -33,6 +34,7 @@ export type SourceControlCliDiscoverySpec = SourceControlDiscoverySpecBase & {
|
||||
readonly executable: string;
|
||||
readonly versionArgs: ReadonlyArray<string>;
|
||||
readonly authArgs: ReadonlyArray<string>;
|
||||
readonly remoteRefinementArgs?: ReadonlyArray<string>;
|
||||
readonly probeTimeoutMs?: number;
|
||||
readonly parseAuth: (input: SourceControlAuthProbeInput) => SourceControlProviderAuth;
|
||||
readonly refineUnknownRemote?: (
|
||||
@@ -45,8 +47,18 @@ export type SourceControlApiDiscoverySpec = SourceControlDiscoverySpecBase & {
|
||||
readonly probeAuth: Effect.Effect<SourceControlProviderAuth, never>;
|
||||
};
|
||||
|
||||
export type SourceControlManagedCliDiscoverySpec = SourceControlDiscoverySpecBase & {
|
||||
readonly type: "managed-cli";
|
||||
readonly probe: (cwd: string) => Effect.Effect<SourceControlProviderDiscoveryItem>;
|
||||
readonly refineUnknownRemote: (input: {
|
||||
readonly cwd: string;
|
||||
readonly context: SourceControlProvider.SourceControlProviderContext;
|
||||
}) => Effect.Effect<SourceControlProviderInfo | null>;
|
||||
};
|
||||
|
||||
export type SourceControlProviderDiscoverySpec =
|
||||
| SourceControlCliDiscoverySpec
|
||||
| SourceControlManagedCliDiscoverySpec
|
||||
| SourceControlApiDiscoverySpec;
|
||||
|
||||
type SourceControlCliRemoteRefinementSpec = SourceControlCliDiscoverySpec & {
|
||||
@@ -72,7 +84,7 @@ interface DiscoveryProbeResult {
|
||||
}
|
||||
|
||||
export function firstNonEmptyLine(text: string): Option.Option<string> {
|
||||
const line = text
|
||||
const line = NodeUtil.stripVTControlCharacters(text)
|
||||
.split(/\r?\n/)
|
||||
.map((entry) => entry.trim())
|
||||
.find((entry) => entry.length > 0);
|
||||
@@ -214,6 +226,7 @@ export function probeSourceControlProvider(input: {
|
||||
readonly process: VcsProcess.VcsProcess["Service"];
|
||||
readonly cwd: string;
|
||||
}): Effect.Effect<SourceControlProviderDiscoveryItem> {
|
||||
if (input.spec.type === "managed-cli") return input.spec.probe(input.cwd);
|
||||
if (input.spec.type === "api") {
|
||||
return input.spec.probeAuth.pipe(
|
||||
Effect.map(
|
||||
@@ -288,12 +301,16 @@ export const refineUnknownRemoteProvider = Effect.fn("refineUnknownRemoteProvide
|
||||
}
|
||||
const context = input.context;
|
||||
|
||||
const providers = yield* Effect.forEach(input.specs.filter(isCliRemoteRefinementSpec), (spec) =>
|
||||
input.process
|
||||
const providers = yield* Effect.forEach(input.specs, (spec) => {
|
||||
if (spec.type === "managed-cli") {
|
||||
return spec.refineUnknownRemote({ cwd: input.cwd, context });
|
||||
}
|
||||
if (!isCliRemoteRefinementSpec(spec)) return Effect.succeed(null);
|
||||
return input.process
|
||||
.run({
|
||||
operation: "source-control.discovery.refine-unknown-remote",
|
||||
command: spec.executable,
|
||||
args: spec.authArgs,
|
||||
args: spec.remoteRefinementArgs ?? spec.authArgs,
|
||||
cwd: input.cwd,
|
||||
allowNonZeroExit: true,
|
||||
timeoutMs: probeTimeoutMs(spec),
|
||||
@@ -309,8 +326,8 @@ export const refineUnknownRemoteProvider = Effect.fn("refineUnknownRemoteProvide
|
||||
}),
|
||||
),
|
||||
Effect.orElseSucceed(() => null),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
const provider = providers.find((candidate) => candidate !== null);
|
||||
|
||||
return provider ? { ...context, provider } : context;
|
||||
|
||||
Reference in new issue
Block a user