refactor(source-control): Bitbucket lives in @t3tools/source-control-bitbucket (#17597)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5.5 authored and GitHub committed 2026-10-09 14:50:01 -07:00
1 parent eb459b5afa
commit 8d1858d9d6
33 files changed
+253 -63

No files matched your search

+1
View File
@@ -46,6 +46,7 @@
"@t3tools/provider-opencode": "workspace:*",
"@t3tools/provider-pi": "workspace:*",
"@t3tools/source-control-azure-devops": "workspace:*",
"@t3tools/source-control-bitbucket": "workspace:*",
"@t3tools/source-control-core": "workspace:*",
"@t3tools/source-control-forgejo": "workspace:*",
"@t3tools/source-control-gitlab": "workspace:*",
@@ -25,7 +25,6 @@ import * as ThreadTitleLinks from "../src/textGeneration/ThreadTitleLinks.ts";
import * as SourceControlProviderRegistry from "../src/sourceControl/SourceControlProviderRegistry.ts";
import * as GitHubApi from "../src/sourceControl/GitHubApi.ts";
import * as SourceControlBuiltInDrivers from "../src/sourceControl/builtInDrivers.ts";
import * as BitbucketApi from "../src/sourceControl/BitbucketApi.ts";
import * as ServerSettings from "../src/serverSettings.ts";
import * as VcsProcess from "../src/vcs/VcsProcess.ts";
import * as VcsDriverRegistry from "../src/vcs/VcsDriverRegistry.ts";
@@ -149,12 +148,7 @@ await Effect.runPromise(
ProcessRunner.layer,
SourceControlProviderRegistry.layer.pipe(
Layer.provide(
Layer.mergeAll(
GitHubApi.layerWithDependencies,
SourceControlBuiltInDrivers.layer,
// No saved credentials here; Bitbucket falls back to T3CODE_BITBUCKET_* variables.
BitbucketApi.layer,
),
Layer.mergeAll(GitHubApi.layerWithDependencies, SourceControlBuiltInDrivers.layer),
),
// Default settings: no saved Bitbucket token, gh's own GitHub account choice.
Layer.provide(ServerSettings.layerTest()),
@@ -1,12 +1,12 @@
import { assert, it } from "@effect/vitest";
import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli";
import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as GitHubApi from "../sourceControl/GitHubApi.ts";
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";
import { azureDevOpsProviderFailure } from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestProvider";
import { bitbucketProviderFailure } from "./BitbucketPullRequestProvider.ts";
import { bitbucketProviderFailure } from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestProvider";
import { gitHubProviderFailure } from "./GitHubPullRequestProvider.ts";
import { gitLabProviderFailure } from "@t3tools/source-control-gitlab/server/GitLabPullRequestProvider";
@@ -3,10 +3,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import type { SourceControlProviderKind } from "@t3tools/contracts";
import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
import * as GitHubApi from "../sourceControl/GitHubApi.ts";
import * as BitbucketPullRequestApi from "./BitbucketPullRequestApi.ts";
import * as BitbucketPullRequestProvider from "./BitbucketPullRequestProvider.ts";
import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";
import * as GitHubPullRequestProvider from "./GitHubPullRequestProvider.ts";
import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts";
@@ -39,10 +36,7 @@ export function fromProviders(
* @public Service construction is part of the canonical Effect module API.
*/
export const make = Effect.gen(function* () {
const providers = yield* Effect.all([
GitHubPullRequestProvider.make,
BitbucketPullRequestProvider.make,
]);
const providers = yield* Effect.all([GitHubPullRequestProvider.make]);
const drivers = yield* Effect.forEach(BuiltInDrivers.BUILT_IN_SOURCE_CONTROL_DRIVERS, (driver) =>
driver.make.pipe(Effect.map((instance) => instance.pullRequests)),
);
@@ -62,5 +56,4 @@ export const layer = Layer.effect(PullRequestProviderRegistry, make).pipe(
),
),
Layer.provide(BuiltInDrivers.layer),
Layer.provide(BitbucketPullRequestApi.layer.pipe(Layer.provide(BitbucketApi.layer))),
);
+1 -8
View File
@@ -52,7 +52,6 @@ import * as ProviderHostLive from "./provider/ProviderHostLive.ts";
import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";
import * as CheckpointStore from "./checkpointing/CheckpointStore.ts";
import * as BitbucketApi from "./sourceControl/BitbucketApi.ts";
import * as GitHubApi from "./sourceControl/GitHubApi.ts";
import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";
import * as SourceControlBuiltInDrivers from "./sourceControl/builtInDrivers.ts";
@@ -297,13 +296,7 @@ const layerPersistence = Layer.empty.pipe(Layer.provideMerge(SqlitePersistence.l
const layerVcsDriverRegistry = VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer));
const layerSourceControlProviderRegistry = SourceControlProviderRegistry.layer.pipe(
Layer.provide(
Layer.mergeAll(
BitbucketApi.layer,
GitHubApi.layerWithDependencies,
SourceControlBuiltInDrivers.layer,
),
),
Layer.provide(Layer.mergeAll(GitHubApi.layerWithDependencies, SourceControlBuiltInDrivers.layer)),
Layer.provideMerge(GitVcsDriver.layer),
Layer.provideMerge(layerVcsDriverRegistry),
);
@@ -11,11 +11,13 @@ import * as TestClock from "effect/testing/TestClock";
import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http";
import { GitCommandError } from "@t3tools/contracts";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as ServerSettings from "../serverSettings.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import type * as VcsDriver from "../vcs/VcsDriver.ts";
import * as ServerSourceControlHost from "./ServerSourceControlHost.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
const isBitbucketRepositoryLocatorError = Schema.is(BitbucketApi.BitbucketRepositoryLocatorError);
@@ -139,6 +141,8 @@ function makeLayer(input: {
);
const layer = BitbucketApi.layer.pipe(
Layer.provide(ServerSourceControlHost.layer),
Layer.provide(Layer.mock(VcsProcess.VcsProcess)({})),
Layer.provide(
Layer.succeed(
HttpClient.HttpClient,
@@ -9,6 +9,8 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as ServerSettings from "../serverSettings.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
export const layer = Layer.effect(
@@ -16,9 +18,23 @@ export const layer = Layer.effect(
Effect.gen(function* () {
const serverSettings = yield* ServerSettings.ServerSettingsService;
const process = yield* VcsProcess.VcsProcess;
const git = yield* GitVcsDriver.GitVcsDriver;
const vcsRegistry = yield* VcsDriverRegistry.VcsDriverRegistry;
return SourceControlHost.SourceControlHost.of({
settings: { get: serverSettings.getSettings },
process: { run: process.run },
git: {
remotes: (cwd) =>
vcsRegistry.resolve({ cwd }).pipe(Effect.map((handle) => handle.driver.listRemotes(cwd))),
readConfigValue: git.readConfigValue,
resolvePrimaryRemoteName: git.resolvePrimaryRemoteName,
ensureRemote: git.ensureRemote,
listLocalBranchNames: git.listLocalBranchNames,
fetchRemoteBranch: git.fetchRemoteBranch,
fetchRemoteTrackingBranch: git.fetchRemoteTrackingBranch,
setBranchUpstream: git.setBranchUpstream,
switchRef: git.switchRef,
},
});
}),
);
@@ -18,7 +18,8 @@ import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli";
import * as AzureDevOpsPullRequestCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestCli";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi";
import * as GitHubApi from "./GitHubApi.ts";
import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";
import * as GitLabPullRequestCli from "@t3tools/source-control-gitlab/server/GitLabPullRequestCli";
@@ -43,6 +44,7 @@ const layerSourceControlProviderRegistryTest = (input: {
Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({}),
Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({}),
Layer.mock(BitbucketApi.BitbucketApi)(input.bitbucket),
Layer.mock(BitbucketPullRequestApi.BitbucketPullRequestApi)({}),
ServerSettings.ServerSettingsService.layerTest(),
Layer.mock(GitHubApi.GitHubApi)({}),
Layer.mock(GitVcsDriver.GitVcsDriver)({}),
@@ -53,9 +55,11 @@ const layerSourceControlProviderRegistryTest = (input: {
Layer.mock(VcsProcess.VcsProcess)(input.process),
ServerSourceControlHost.layer.pipe(
Layer.provide(
Layer.merge(
Layer.mergeAll(
Layer.mock(VcsProcess.VcsProcess)(input.process),
ServerSettings.ServerSettingsService.layerTest(),
Layer.mock(GitVcsDriver.GitVcsDriver)({}),
Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({}),
),
),
),
@@ -395,6 +399,7 @@ it.effect(
SourceControlHost.SourceControlHost,
SourceControlHost.SourceControlHost.of({
settings: host.settings,
git: host.git,
process: {
run: (input) => {
if (input.args[0] !== "fetch") return git.run(input);
@@ -529,6 +534,8 @@ it.effect(
ServerSourceControlHost.layer.pipe(
Layer.provideMerge(VcsProcess.layer),
Layer.provideMerge(ServerSettings.ServerSettingsService.layerTest()),
Layer.provideMerge(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
Layer.provideMerge(Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({})),
Layer.provideMerge(NodeServices.layer),
),
),
@@ -15,7 +15,8 @@ import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli";
import * as AzureDevOpsPullRequestCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestCli";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as GitHubApi from "./GitHubApi.ts";
import * as GitHubCredentials from "./GitHubCredentials.ts";
@@ -101,12 +102,18 @@ function makeRegistry(input: {
layerProcess,
ServerSourceControlHost.layer.pipe(
Layer.provide(
Layer.merge(layerProcess, ServerSettings.ServerSettingsService.layerTest()),
Layer.mergeAll(
layerProcess,
layerRegistry,
ServerSettings.ServerSettingsService.layerTest(),
Layer.mock(GitVcsDriver.GitVcsDriver)({}),
),
),
),
Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({}),
Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({}),
Layer.mock(BitbucketApi.BitbucketApi)({}),
Layer.mock(BitbucketPullRequestApi.BitbucketPullRequestApi)({}),
ServerSettings.ServerSettingsService.layerTest(),
Layer.mock(GitHubApi.GitHubApi)({
// No GitHub credential unless a test supplies one, so custom hosts stay unclaimed.
@@ -11,7 +11,6 @@ import {
import type { SourceControlProviderKind } from "@t3tools/contracts";
import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";
import * as BuiltInDrivers from "./builtInDrivers.ts";
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
@@ -305,8 +304,6 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit
export const make = Effect.gen(function* () {
const github = yield* GitHubSourceControlProvider.make;
const githubDiscovery = yield* GitHubSourceControlProvider.makeDiscovery;
const bitbucket = yield* BitbucketSourceControlProvider.make;
const bitbucketDiscovery = yield* BitbucketSourceControlProvider.makeDiscovery;
const drivers = yield* Effect.forEach(BuiltInDrivers.BUILT_IN_SOURCE_CONTROL_DRIVERS, (driver) =>
driver.make.pipe(
Effect.map((instance): SourceControlProviderRegistration => ({
@@ -324,11 +321,6 @@ export const make = Effect.gen(function* () {
provider: github,
discovery: githubDiscovery,
},
{
kind: "bitbucket",
provider: bitbucket,
discovery: bitbucketDiscovery,
},
...drivers,
];
return yield* makeWithProviders(
@@ -13,8 +13,8 @@ import { GitCommandError, SourceControlProviderError } from "@t3tools/contracts"
import * as ServerConfig from "../config.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as BitbucketSourceControlProvider from "@t3tools/source-control-bitbucket/server/BitbucketSourceControlProvider";
import type * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
import * as SourceControlRepositoryService from "./SourceControlRepositoryService.ts";
@@ -27,7 +27,7 @@ import {
type GitCloneProgressLine,
} from "../project/gitCloneProgress.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
const isSourceControlRepositoryError = Schema.is(SourceControlRepositoryError);
const isSourceControlProviderError = Schema.is(SourceControlProviderError);
@@ -10,6 +10,9 @@
import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli";
import * as AzureDevOpsPullRequestCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestCli";
import * as AzureDevOpsDriver from "@t3tools/source-control-azure-devops/server/driver";
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi";
import * as BitbucketDriver from "@t3tools/source-control-bitbucket/server/driver";
import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";
import * as ForgejoDriver from "@t3tools/source-control-forgejo/server/driver";
import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";
@@ -20,7 +23,12 @@ import * as Layer from "effect/Layer";
import * as ServerSourceControlHost from "./ServerSourceControlHost.ts";
const drivers = [GitLabDriver.driver, AzureDevOpsDriver.driver, ForgejoDriver.driver];
const drivers = [
GitLabDriver.driver,
AzureDevOpsDriver.driver,
BitbucketDriver.driver,
ForgejoDriver.driver,
];
/** Every service a built-in driver's `make` needs; the server's layers must provide them all. */
export type BuiltInSourceControlDriversEnv =
@@ -33,6 +41,7 @@ export const BUILT_IN_SOURCE_CONTROL_DRIVERS: ReadonlyArray<
/** The services the built-in drivers' packages own, plus the host port they all run against. */
export const layer = Layer.mergeAll(
AzureDevOpsPullRequestCli.layer.pipe(Layer.provideMerge(AzureDevOpsCli.layer)),
BitbucketPullRequestApi.layer.pipe(Layer.provideMerge(BitbucketApi.layer)),
ForgejoCli.layer,
GitLabPullRequestCli.layer.pipe(Layer.provideMerge(GitLabCli.layer)),
).pipe(Layer.provideMerge(ServerSourceControlHost.layer));
-2
View File
@@ -229,7 +229,6 @@ import * as SqlClient from "effect/sql/SqlClient";
import * as PullRequestSyncReactor from "./orchestration-v2/PullRequestSyncReactor.ts";
import * as SourceControlDiscovery from "./sourceControl/SourceControlDiscovery.ts";
import * as SourceControlRepositoryService from "./sourceControl/SourceControlRepositoryService.ts";
import * as BitbucketApi from "./sourceControl/BitbucketApi.ts";
import * as GitHubApi from "./sourceControl/GitHubApi.ts";
import * as SourceControlBuiltInDrivers from "./sourceControl/builtInDrivers.ts";
import * as SourceControlProviderRegistry from "./sourceControl/SourceControlProviderRegistry.ts";
@@ -3202,7 +3201,6 @@ export const layer = Layer.unwrap(
SourceControlProviderRegistry.layer.pipe(
Layer.provide(
Layer.mergeAll(
BitbucketApi.layer,
GitHubApi.layerWithDependencies,
SourceControlBuiltInDrivers.layer,
),
@@ -27,7 +27,7 @@ What "never got to look at" is belongs to the host, and the contract cannot know
- [Azure DevOps](../../packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts) reads every
version off one iteration listing, so a change too long to follow to its end leaves the paths
past that point out.
- [Bitbucket](../../apps/server/src/pullRequest/BitbucketPullRequestApi.ts) reads them off the
- [Bitbucket](../../packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.ts) reads them off the
pull request's own patch, the only place it states a file's version, so a patch cut short at the
byte ceiling leaves the paths past the cut out.
- [GitLab](../../packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts) asks in batches, so a batch
+1 -1
View File
@@ -28,7 +28,7 @@
"tc": "vp run -r --concurrency-limit 2 typecheck",
"lint": "vp lint --report-unused-disable-directives",
"knip": "knip --preprocessor ./scripts/knip-schemas.ts",
"knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-grok --workspace packages/source-control-core --workspace packages/source-control-azure-devops --workspace packages/source-control-forgejo --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
"knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-grok --workspace packages/source-control-core --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
"knip:production": "knip --production --preprocessor ./scripts/knip-schemas.ts",
"lint:mobile": "node scripts/mobile-native-static-check.ts",
"test": "vp run -r test",
@@ -0,0 +1,51 @@
{
"name": "@t3tools/source-control-bitbucket",
"private": true,
"type": "module",
"exports": {
"./server/BitbucketApi": {
"types": "./src/server/BitbucketApi.ts",
"import": "./src/server/BitbucketApi.ts"
},
"./server/BitbucketPullRequestApi": {
"types": "./src/server/BitbucketPullRequestApi.ts",
"import": "./src/server/BitbucketPullRequestApi.ts"
},
"./server/bitbucketPullRequestJson": {
"types": "./src/server/bitbucketPullRequestJson.ts",
"import": "./src/server/bitbucketPullRequestJson.ts"
},
"./server/BitbucketPullRequestProvider": {
"types": "./src/server/BitbucketPullRequestProvider.ts",
"import": "./src/server/BitbucketPullRequestProvider.ts"
},
"./server/bitbucketPullRequests": {
"types": "./src/server/bitbucketPullRequests.ts",
"import": "./src/server/bitbucketPullRequests.ts"
},
"./server/BitbucketSourceControlProvider": {
"types": "./src/server/BitbucketSourceControlProvider.ts",
"import": "./src/server/BitbucketSourceControlProvider.ts"
},
"./server/driver": {
"types": "./src/server/driver.ts",
"import": "./src/server/driver.ts"
}
},
"scripts": {
"typecheck": "tsc --noEmit",
"test": "vp test run --config ../../vite.config.ts --dir ."
},
"dependencies": {
"@t3tools/contracts": "workspace:*",
"@t3tools/provider-core": "workspace:*",
"@t3tools/shared": "workspace:*",
"@t3tools/source-control-core": "workspace:*",
"effect": "catalog:"
},
"devDependencies": {
"@effect/vitest": "catalog:",
"@types/node": "catalog:",
"vite-plus": "catalog:"
}
}
@@ -30,9 +30,7 @@ import {
} from "./bitbucketPullRequests.ts";
import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
import * as ServerSettings from "../serverSettings.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
import { retryAtFromHeader } from "@t3tools/source-control-core/server/SourceControlRateLimit";
const DEFAULT_API_BASE_URL = "https://api.bitbucket.org/2.0";
@@ -390,7 +388,7 @@ export class BitbucketApi extends Context.Service<
readonly force?: boolean;
}) => Effect.Effect<void, BitbucketApiError>;
}
>()("t3/sourceControl/BitbucketApi") {}
>()("@t3tools/source-control-bitbucket/server/BitbucketApi") {}
function nonEmpty(value: string | undefined): Option.Option<string> {
const trimmed = value?.trim();
@@ -657,16 +655,15 @@ function responseError(
/** @public Service construction is part of the canonical Effect module API. */
export const make = Effect.gen(function* () {
const config = yield* BitbucketApiEnvConfig;
const serverSettings = yield* ServerSettings.ServerSettingsService;
const host = yield* SourceControlHost.SourceControlHost;
const git = host.git;
const httpClient = yield* HttpClient.HttpClient;
const fileSystem = yield* FileSystem.FileSystem;
const git = yield* GitVcsDriver.GitVcsDriver;
const vcsRegistry = yield* VcsDriverRegistry.VcsDriverRegistry;
const apiUrl = (path: string) => `${config.baseUrl.replace(/\/+$/u, "")}${path}`;
// Read on every request so credentials saved in settings apply without a restart.
const currentCredential = serverSettings.getSettings.pipe(
const currentCredential = host.settings.get.pipe(
Effect.map((settings) => resolveCredential(settings.bitbucket, config)),
Effect.catch((error) =>
// No cause: a settings decode error can quote a hand-edited token.
@@ -739,7 +736,7 @@ export const make = Effect.gen(function* () {
: null;
if (fromContext) return fromContext;
const handle = yield* vcsRegistry.resolve({ cwd: input.cwd }).pipe(
const listRemotes = yield* git.remotes(input.cwd).pipe(
Effect.mapError(
(cause) =>
new BitbucketRepositoryVcsResolveError({
@@ -748,7 +745,7 @@ export const make = Effect.gen(function* () {
}),
),
);
const remotes = yield* handle.driver.listRemotes(input.cwd).pipe(
const remotes = yield* listRemotes.pipe(
Effect.mapError(
(cause) =>
new BitbucketRepositoryRemotesListError({
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as TestClock from "effect/testing/TestClock";
import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketPullRequestApi from "./BitbucketPullRequestApi.ts";
const mockedRequest = vi.fn<BitbucketApi.BitbucketApi["Service"]["request"]>();
@@ -21,7 +21,7 @@ import type {
PullRequestReviewerCandidateList,
} from "@t3tools/contracts";
import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
import * as BitbucketApi from "./BitbucketApi.ts";
import { parseDiffFileRevisions } from "@t3tools/source-control-core/server/diffFileRevisions";
import {
buildReviewThreads,
@@ -304,7 +304,7 @@ export class BitbucketPullRequestApi extends Context.Service<
readonly resolved: boolean;
}) => Effect.Effect<void, BitbucketPullRequestApiError>;
}
>()("t3/pullRequest/BitbucketPullRequestApi") {}
>()("@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi") {}
/** `workspace/slug`; Bitbucket has no deeper nesting to address. */
function repositorySegments(
@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Result from "effect/Result";
import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
import * as BitbucketApi from "./BitbucketApi.ts";
import * as BitbucketPullRequestApi from "./BitbucketPullRequestApi.ts";
import { decodePullRequestJson } from "./bitbucketPullRequestJson.ts";
import {
@@ -0,0 +1,20 @@
/**
* The Bitbucket Cloud driver: repository operations, discovery, and pull requests through the
* Bitbucket REST API.
*
* @module source-control-bitbucket/server/driver
*/
import { defineSourceControlDriver } from "@t3tools/source-control-core/server/driver";
import * as Effect from "effect/Effect";
import * as BitbucketPullRequestProvider from "./BitbucketPullRequestProvider.ts";
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
export const driver = defineSourceControlDriver({
kind: "bitbucket",
make: Effect.all({
sourceControl: BitbucketSourceControlProvider.make,
discovery: BitbucketSourceControlProvider.makeDiscovery,
pullRequests: BitbucketPullRequestProvider.make,
}),
});
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["src"]
}
@@ -7,9 +7,20 @@
* its own API and CLI code. HTTP, the filesystem, and paths come from Effect's platform
* services directly.
*
* `git` is the subset of the server's git driver that checking out a change request needs; it
* grows only when a provider needs another operation.
*
* @module source-control-core/server/SourceControlHost
*/
import type { ServerSettings, ServerSettingsError, VcsError } from "@t3tools/contracts";
import type {
GitCommandError,
ServerSettings,
ServerSettingsError,
VcsError,
VcsListRemotesResult,
VcsSwitchRefInput,
VcsSwitchRefResult,
} from "@t3tools/contracts";
import * as Context from "effect/Context";
import type * as Effect from "effect/Effect";
import type * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
@@ -43,6 +54,12 @@ export interface SourceControlProcessOutput {
readonly stderrInvalidUtf8?: boolean;
}
export interface SourceControlGitRemoteBranch {
readonly cwd: string;
readonly remoteName: string;
readonly remoteBranch: string;
}
export class SourceControlHost extends Context.Service<
SourceControlHost,
{
@@ -55,5 +72,38 @@ export class SourceControlHost extends Context.Service<
input: SourceControlProcessInput,
) => Effect.Effect<SourceControlProcessOutput, VcsError>;
};
readonly git: {
/**
* Lists the remotes of the repository at `cwd`. The outer effect resolves the repository
* and fails when the server cannot drive one there; the inner one lists its remotes.
*/
readonly remotes: (
cwd: string,
) => Effect.Effect<Effect.Effect<VcsListRemotesResult, VcsError>, VcsError>;
readonly readConfigValue: (
cwd: string,
key: string,
) => Effect.Effect<string | null, GitCommandError>;
readonly resolvePrimaryRemoteName: (cwd: string) => Effect.Effect<string, GitCommandError>;
/** Adds a remote for `url` unless one exists, and returns the name it is under. */
readonly ensureRemote: (input: {
readonly cwd: string;
readonly preferredName: string;
readonly url: string;
}) => Effect.Effect<string, GitCommandError>;
readonly listLocalBranchNames: (cwd: string) => Effect.Effect<string[], GitCommandError>;
readonly fetchRemoteBranch: (
input: SourceControlGitRemoteBranch & { readonly localBranch: string },
) => Effect.Effect<void, GitCommandError>;
readonly fetchRemoteTrackingBranch: (
input: SourceControlGitRemoteBranch,
) => Effect.Effect<void, GitCommandError>;
readonly setBranchUpstream: (
input: SourceControlGitRemoteBranch & { readonly branch: string },
) => Effect.Effect<void, GitCommandError>;
readonly switchRef: (
input: VcsSwitchRefInput,
) => Effect.Effect<VcsSwitchRefResult, GitCommandError>;
};
}
>()("@t3tools/source-control-core/server/SourceControlHost") {}
@@ -1,7 +1,7 @@
/**
* A `SourceControlHost.SourceControlHost` for provider tests. Settings are fixed unless the test
* supplies its own, and every process run goes to the test's `run`, which fails by default so an
* unexpected CLI call is visible.
* supplies its own. Process runs and git operations go to what the test supplies; anything else
* dies, so an unexpected CLI or git call is visible.
*
* @module source-control-testing/TestSourceControlHost
*/
@@ -14,8 +14,26 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
export interface TestSourceControlHostOptions {
readonly settings?: ServerSettings;
readonly process?: Partial<SourceControlHost.SourceControlHost["Service"]["process"]>;
readonly git?: Partial<SourceControlHost.SourceControlHost["Service"]["git"]>;
}
type Git = SourceControlHost.SourceControlHost["Service"]["git"];
const unexpectedGit = (operation: string) => () =>
Effect.die(`Unexpected git ${operation} in a test that supplied none.`);
const failingGit: Git = {
remotes: unexpectedGit("remotes"),
readConfigValue: unexpectedGit("readConfigValue"),
resolvePrimaryRemoteName: unexpectedGit("resolvePrimaryRemoteName"),
ensureRemote: unexpectedGit("ensureRemote"),
listLocalBranchNames: unexpectedGit("listLocalBranchNames"),
fetchRemoteBranch: unexpectedGit("fetchRemoteBranch"),
fetchRemoteTrackingBranch: unexpectedGit("fetchRemoteTrackingBranch"),
setBranchUpstream: unexpectedGit("setBranchUpstream"),
switchRef: unexpectedGit("switchRef"),
};
export const layer = (
options: TestSourceControlHostOptions = {},
): Layer.Layer<SourceControlHost.SourceControlHost> =>
@@ -28,6 +46,7 @@ export const layer = (
options.process?.run ??
((input) => Effect.die(`Unexpected ${input.command} run in ${input.operation}.`)),
},
git: { ...failingGit, ...options.git },
}),
);
+31
View File
@@ -651,6 +651,9 @@ importers:
'@t3tools/source-control-azure-devops':
specifier: workspace:*
version: link:../../packages/source-control-azure-devops
'@t3tools/source-control-bitbucket':
specifier: workspace:*
version: link:../../packages/source-control-bitbucket
'@t3tools/source-control-core':
specifier: workspace:*
version: link:../../packages/source-control-core
@@ -1556,6 +1559,34 @@ importers:
specifier: 1.0.0
version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
packages/source-control-bitbucket:
dependencies:
'@t3tools/contracts':
specifier: workspace:*
version: link:../contracts
'@t3tools/provider-core':
specifier: workspace:*
version: link:../provider-core
'@t3tools/shared':
specifier: workspace:*
version: link:../shared
'@t3tools/source-control-core':
specifier: workspace:*
version: link:../source-control-core
effect:
specifier: 4.0.2
version: 4.0.2(patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688)
devDependencies:
'@effect/vitest':
specifier: 4.0.2
version: 4.0.2(patch_hash=595b7d26fb635caba9c3d39fcb189bb78a000192f8d3b60ead7174b310d1ade9)(@types/[email protected])(@vitest/[email protected])([email protected])([email protected](patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688))([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
'@types/node':
specifier: 24.12.4
version: 24.12.4
vite-plus:
specifier: 1.0.0
version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])
packages/source-control-core:
dependencies:
'@t3tools/contracts':
+1
View File
@@ -38,6 +38,7 @@ const workspaceFiles = [
"packages/provider-muse/package.json",
"packages/provider-opencode/package.json",
"packages/source-control-azure-devops/package.json",
"packages/source-control-bitbucket/package.json",
"packages/source-control-core/package.json",
"packages/source-control-forgejo/package.json",
"packages/source-control-gitlab/package.json",