feat(source-control): add Bitbucket & Azure Devops providers (#2473)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
This commit is contained in:
59 files changed
+5852
-2345
No files matched your search
@@ -5,8 +5,34 @@ import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { VcsProcessSpawnError } from "@t3tools/contracts";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import { SourceControlDiscovery, layer } from "./SourceControlDiscovery.ts";
|
||||
import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
|
||||
import * as BitbucketApi from "./BitbucketApi.ts";
|
||||
import * as GitHubCli from "./GitHubCli.ts";
|
||||
import * as GitLabCli from "./GitLabCli.ts";
|
||||
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>;
|
||||
}) =>
|
||||
SourceControlProviderRegistry.layer.pipe(
|
||||
Layer.provide(
|
||||
Layer.mergeAll(
|
||||
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)({}),
|
||||
Layer.mock(GitLabCli.GitLabCli)({}),
|
||||
Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({}),
|
||||
Layer.mock(VcsProcess.VcsProcess)(input.process),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const processOutput = (
|
||||
stdout: string,
|
||||
@@ -22,39 +48,53 @@ const processOutput = (
|
||||
stderrTruncated: false,
|
||||
});
|
||||
|
||||
it.effect("reports implemented tools separately from locally available CLIs", () => {
|
||||
const testLayer = layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(VcsProcess.VcsProcess)({
|
||||
run: (input) => {
|
||||
if (input.command === "git") {
|
||||
return Effect.succeed(processOutput("git version 2.51.0\n"));
|
||||
}
|
||||
if (input.command === "gh" && input.args[0] === "--version") {
|
||||
return Effect.succeed(processOutput("gh version 2.83.0\n"));
|
||||
}
|
||||
if (input.command === "gh" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`github.com
|
||||
it.effect("reports implemented tools separately from locally available executables", () => {
|
||||
const processMock = {
|
||||
run: (input: VcsProcess.VcsProcessInput) => {
|
||||
if (input.command === "git") {
|
||||
return Effect.succeed(processOutput("git version 2.51.0\n"));
|
||||
}
|
||||
if (input.command === "gh" && input.args[0] === "--version") {
|
||||
return Effect.succeed(processOutput("gh version 2.83.0\n"));
|
||||
}
|
||||
if (input.command === "gh" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`github.com
|
||||
Logged in to github.com account juliusmarminge (keyring)
|
||||
- Active account: true
|
||||
- Git operations protocol: ssh
|
||||
- Token: gho_************************************
|
||||
- Token scopes: 'admin:public_key', 'gist', 'read:org', 'repo'
|
||||
`),
|
||||
);
|
||||
}
|
||||
return Effect.fail(
|
||||
new VcsProcessSpawnError({
|
||||
operation: input.operation,
|
||||
command: input.command,
|
||||
cwd: input.cwd,
|
||||
cause: new Error(`${input.command} not found`),
|
||||
}),
|
||||
);
|
||||
);
|
||||
}
|
||||
return Effect.fail(
|
||||
new VcsProcessSpawnError({
|
||||
operation: input.operation,
|
||||
command: input.command,
|
||||
cwd: input.cwd,
|
||||
cause: new Error(`${input.command} not found`),
|
||||
}),
|
||||
);
|
||||
},
|
||||
} satisfies Partial<VcsProcess.VcsProcessShape>;
|
||||
const testLayer = SourceControlDiscovery.layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
|
||||
),
|
||||
Layer.provide(Layer.mock(VcsProcess.VcsProcess)(processMock)),
|
||||
Layer.provide(
|
||||
sourceControlProviderRegistryTestLayer({
|
||||
process: processMock,
|
||||
bitbucket: {
|
||||
probeAuth: Effect.succeed({
|
||||
status: "unauthenticated",
|
||||
account: Option.none(),
|
||||
host: Option.some("bitbucket.org"),
|
||||
detail: Option.some(
|
||||
"Set T3CODE_BITBUCKET_EMAIL and T3CODE_BITBUCKET_API_TOKEN, or T3CODE_BITBUCKET_ACCESS_TOKEN.",
|
||||
),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
),
|
||||
@@ -62,7 +102,7 @@ Logged in to github.com account juliusmarminge (keyring)
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const discovery = yield* SourceControlDiscovery;
|
||||
const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
|
||||
const result = yield* discovery.discover;
|
||||
|
||||
assert.deepStrictEqual(
|
||||
@@ -79,7 +119,6 @@ Logged in to github.com account juliusmarminge (keyring)
|
||||
assert.deepStrictEqual(
|
||||
result.sourceControlProviders.map((item) => ({
|
||||
kind: item.kind,
|
||||
implemented: item.implemented,
|
||||
status: item.status,
|
||||
auth: item.auth.status,
|
||||
account: item.auth.account,
|
||||
@@ -87,88 +126,89 @@ Logged in to github.com account juliusmarminge (keyring)
|
||||
[
|
||||
{
|
||||
kind: "github",
|
||||
implemented: true,
|
||||
status: "available",
|
||||
auth: "authenticated",
|
||||
account: Option.some("juliusmarminge"),
|
||||
},
|
||||
{
|
||||
kind: "gitlab",
|
||||
implemented: true,
|
||||
status: "missing",
|
||||
auth: "unknown",
|
||||
account: Option.none(),
|
||||
},
|
||||
{
|
||||
kind: "azure-devops",
|
||||
implemented: false,
|
||||
status: "missing",
|
||||
auth: "unknown",
|
||||
account: Option.none(),
|
||||
},
|
||||
{
|
||||
kind: "bitbucket",
|
||||
implemented: false,
|
||||
status: "missing",
|
||||
auth: "unknown",
|
||||
status: "available",
|
||||
auth: "unauthenticated",
|
||||
account: Option.none(),
|
||||
},
|
||||
],
|
||||
);
|
||||
const bitbucket = result.sourceControlProviders.find((item) => item.kind === "bitbucket");
|
||||
assert.ok(bitbucket);
|
||||
assert.strictEqual("executable" in bitbucket, false);
|
||||
assert.strictEqual(bitbucket.executable, undefined);
|
||||
}).pipe(Effect.provide(testLayer));
|
||||
});
|
||||
|
||||
it.effect("probes provider authentication without exposing token details", () => {
|
||||
const testLayer = layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-auth-discovery-" }),
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(VcsProcess.VcsProcess)({
|
||||
run: (input) => {
|
||||
if (input.args[0] === "--version") {
|
||||
return Effect.succeed(processOutput(`${input.command} version test\n`));
|
||||
}
|
||||
if (input.command === "gh" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`github.com
|
||||
const processMock = {
|
||||
run: (input: VcsProcess.VcsProcessInput) => {
|
||||
if (input.args[0] === "--version") {
|
||||
return Effect.succeed(processOutput(`${input.command} version test\n`));
|
||||
}
|
||||
if (input.command === "gh" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`github.com
|
||||
Logged in to github.com account octocat (keyring)
|
||||
- Token: gho_************************************
|
||||
- Token scopes: 'repo'
|
||||
`),
|
||||
);
|
||||
}
|
||||
if (input.command === "glab" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`gitlab.com
|
||||
);
|
||||
}
|
||||
if (input.command === "glab" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`gitlab.com
|
||||
Logged in to gitlab.com as gitlab-user
|
||||
`),
|
||||
);
|
||||
}
|
||||
if (
|
||||
input.command === "az" &&
|
||||
input.args.join(" ") === "account show --query user.name -o tsv"
|
||||
) {
|
||||
return Effect.succeed(processOutput("[email protected]\n"));
|
||||
}
|
||||
if (input.command === "bb" && input.args.join(" ") === "auth status") {
|
||||
return Effect.succeed(
|
||||
processOutput(`bitbucket.org
|
||||
Logged in as bitbucket-user
|
||||
`),
|
||||
);
|
||||
}
|
||||
return Effect.fail(
|
||||
new VcsProcessSpawnError({
|
||||
operation: input.operation,
|
||||
command: input.command,
|
||||
cwd: input.cwd,
|
||||
cause: new Error(`${input.command} not found`),
|
||||
}),
|
||||
);
|
||||
);
|
||||
}
|
||||
if (
|
||||
input.command === "az" &&
|
||||
input.args.join(" ") === "account show --query user.name -o tsv"
|
||||
) {
|
||||
return Effect.succeed(processOutput("[email protected]\n"));
|
||||
}
|
||||
return Effect.fail(
|
||||
new VcsProcessSpawnError({
|
||||
operation: input.operation,
|
||||
command: input.command,
|
||||
cwd: input.cwd,
|
||||
cause: new Error(`${input.command} not found`),
|
||||
}),
|
||||
);
|
||||
},
|
||||
} satisfies Partial<VcsProcess.VcsProcessShape>;
|
||||
const testLayer = SourceControlDiscovery.layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-auth-discovery-" }),
|
||||
),
|
||||
Layer.provide(Layer.mock(VcsProcess.VcsProcess)(processMock)),
|
||||
Layer.provide(
|
||||
sourceControlProviderRegistryTestLayer({
|
||||
process: processMock,
|
||||
bitbucket: {
|
||||
probeAuth: Effect.succeed({
|
||||
status: "authenticated",
|
||||
account: Option.some("bitbucket-user"),
|
||||
host: Option.some("bitbucket.org"),
|
||||
detail: Option.none(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
),
|
||||
@@ -176,7 +216,7 @@ Logged in as bitbucket-user
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const discovery = yield* SourceControlDiscovery;
|
||||
const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
|
||||
const result = yield* discovery.discover;
|
||||
|
||||
assert.deepStrictEqual(
|
||||
@@ -207,9 +247,9 @@ Logged in as bitbucket-user
|
||||
},
|
||||
{
|
||||
kind: "bitbucket",
|
||||
auth: "unknown",
|
||||
account: Option.none(),
|
||||
detail: Option.some("Bitbucket provider support is not available yet."),
|
||||
auth: "authenticated",
|
||||
account: Option.some("bitbucket-user"),
|
||||
detail: Option.none(),
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user