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:
1 parent
eb459b5afa
commit
8d1858d9d6
33 files changed
+253
-63
No files matched your search
@@ -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,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,151 +0,0 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import * as BitbucketApi from "./BitbucketApi.ts";
|
||||
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
|
||||
|
||||
function makeProvider(bitbucket: Partial<BitbucketApi.BitbucketApi["Service"]>) {
|
||||
return BitbucketSourceControlProvider.make.pipe(
|
||||
Effect.provide(Layer.mock(BitbucketApi.BitbucketApi)(bitbucket)),
|
||||
);
|
||||
}
|
||||
|
||||
it.effect("maps Bitbucket PR summaries into provider-neutral change requests", () =>
|
||||
Effect.gen(function* () {
|
||||
const provider = yield* makeProvider({
|
||||
getPullRequest: () =>
|
||||
Effect.succeed({
|
||||
number: 42,
|
||||
title: "Add Bitbucket provider",
|
||||
url: "https://bitbucket.org/pingdotgg/t3code/pull-requests/42",
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/source-control",
|
||||
state: "open",
|
||||
updatedAt: Option.none(),
|
||||
isCrossRepository: true,
|
||||
headRepositoryNameWithOwner: "fork/t3code",
|
||||
headRepositoryOwnerLogin: "fork",
|
||||
}),
|
||||
});
|
||||
|
||||
const changeRequest = yield* provider.getChangeRequest({
|
||||
cwd: "/repo",
|
||||
reference: "42",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(changeRequest, {
|
||||
provider: "bitbucket",
|
||||
number: 42,
|
||||
title: "Add Bitbucket provider",
|
||||
url: "https://bitbucket.org/pingdotgg/t3code/pull-requests/42",
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/source-control",
|
||||
state: "open",
|
||||
updatedAt: Option.none(),
|
||||
isCrossRepository: true,
|
||||
headRepositoryNameWithOwner: "fork/t3code",
|
||||
headRepositoryOwnerLogin: "fork",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("adds repository context while retaining Bitbucket API causes", () =>
|
||||
Effect.gen(function* () {
|
||||
const upstreamCause = new Error("raw upstream failure");
|
||||
const cause = new BitbucketApi.BitbucketRequestError({
|
||||
operation: "getRepository",
|
||||
cause: upstreamCause,
|
||||
});
|
||||
const provider = yield* makeProvider({
|
||||
getRepositoryCloneUrls: () => Effect.fail(cause),
|
||||
});
|
||||
|
||||
const error = yield* provider
|
||||
.getRepositoryCloneUrls({ cwd: "/repo", repository: "owner/repo" })
|
||||
.pipe(Effect.flip);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
{
|
||||
provider: error.provider,
|
||||
operation: error.operation,
|
||||
command: error.command,
|
||||
cwd: error.cwd,
|
||||
repository: error.repository,
|
||||
detail: error.detail,
|
||||
},
|
||||
{
|
||||
provider: "bitbucket",
|
||||
operation: "getRepositoryCloneUrls",
|
||||
command: undefined,
|
||||
cwd: "/repo",
|
||||
repository: "owner/repo",
|
||||
detail: "Failed to get repository clone URLs.",
|
||||
},
|
||||
);
|
||||
assert.strictEqual(error.cause, cause);
|
||||
assert.equal(error.message.includes(upstreamCause.message), false);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("lists Bitbucket PRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let listInput: Parameters<BitbucketApi.BitbucketApi["Service"]["listPullRequests"]>[0] | null =
|
||||
null;
|
||||
const provider = yield* makeProvider({
|
||||
listPullRequests: (input) => {
|
||||
listInput = input;
|
||||
return Effect.succeed([]);
|
||||
},
|
||||
});
|
||||
|
||||
yield* provider.listChangeRequests({
|
||||
cwd: "/repo",
|
||||
headSelector: "feature/provider",
|
||||
state: "all",
|
||||
limit: 10,
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(listInput, {
|
||||
cwd: "/repo",
|
||||
headSelector: "feature/provider",
|
||||
state: "all",
|
||||
limit: 10,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("creates Bitbucket PRs through provider-neutral input names", () =>
|
||||
Effect.gen(function* () {
|
||||
let createInput:
|
||||
| Parameters<BitbucketApi.BitbucketApi["Service"]["createPullRequest"]>[0]
|
||||
| null = null;
|
||||
const provider = yield* makeProvider({
|
||||
createPullRequest: (input) => {
|
||||
createInput = input;
|
||||
return Effect.void;
|
||||
},
|
||||
});
|
||||
|
||||
yield* provider.createChangeRequest({
|
||||
cwd: "/repo",
|
||||
baseRefName: "main",
|
||||
headSelector: "owner:feature/provider",
|
||||
title: "Provider PR",
|
||||
bodyFile: "/tmp/body.md",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(createInput, {
|
||||
cwd: "/repo",
|
||||
baseBranch: "main",
|
||||
headSelector: "owner:feature/provider",
|
||||
source: {
|
||||
owner: "owner",
|
||||
refName: "feature/provider",
|
||||
},
|
||||
title: "Provider PR",
|
||||
bodyFile: "/tmp/body.md",
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -1,198 +0,0 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contracts";
|
||||
|
||||
import * as BitbucketApi from "./BitbucketApi.ts";
|
||||
import type { NormalizedBitbucketPullRequestRecord } from "./bitbucketPullRequests.ts";
|
||||
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
|
||||
import type { SourceControlApiDiscoverySpec } from "@t3tools/source-control-core/server/discovery";
|
||||
|
||||
function toChangeRequest(summary: NormalizedBitbucketPullRequestRecord): ChangeRequest {
|
||||
return {
|
||||
provider: "bitbucket",
|
||||
number: summary.number,
|
||||
title: summary.title,
|
||||
url: summary.url,
|
||||
baseRefName: summary.baseRefName,
|
||||
headRefName: summary.headRefName,
|
||||
state: summary.state,
|
||||
...(summary.isDraft === true ? { isDraft: true } : {}),
|
||||
updatedAt: summary.updatedAt ?? Option.none(),
|
||||
...(summary.isCrossRepository !== undefined
|
||||
? { isCrossRepository: summary.isCrossRepository }
|
||||
: {}),
|
||||
...(summary.headRepositoryNameWithOwner !== undefined
|
||||
? { headRepositoryNameWithOwner: summary.headRepositoryNameWithOwner }
|
||||
: {}),
|
||||
...(summary.headRepositoryOwnerLogin !== undefined
|
||||
? { headRepositoryOwnerLogin: summary.headRepositoryOwnerLogin }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
export const make = Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
|
||||
return SourceControlProvider.SourceControlProvider.of({
|
||||
kind: "bitbucket",
|
||||
listChangeRequests: (input) => {
|
||||
const source = SourceControlProvider.sourceControlRefFromInput(input);
|
||||
return bitbucket
|
||||
.listPullRequests({
|
||||
cwd: input.cwd,
|
||||
...(input.context ? { context: input.context } : {}),
|
||||
headSelector: input.headSelector,
|
||||
...(source ? { source } : {}),
|
||||
state: input.state,
|
||||
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
||||
})
|
||||
.pipe(
|
||||
Effect.map((items) => items.map(toChangeRequest)),
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "listChangeRequests",
|
||||
cwd: input.cwd,
|
||||
reference: SourceControlProvider.transportSafeSourceControlErrorValue(
|
||||
input.headSelector,
|
||||
),
|
||||
detail: "Failed to list change requests.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
getChangeRequest: (input) =>
|
||||
bitbucket.getPullRequest(input).pipe(
|
||||
Effect.map(toChangeRequest),
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "getChangeRequest",
|
||||
cwd: input.cwd,
|
||||
reference: SourceControlProvider.transportSafeSourceControlErrorValue(
|
||||
input.reference,
|
||||
),
|
||||
detail: "Failed to get change request.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
),
|
||||
createChangeRequest: (input) => {
|
||||
const source = SourceControlProvider.sourceControlRefFromInput(input);
|
||||
return bitbucket
|
||||
.createPullRequest({
|
||||
cwd: input.cwd,
|
||||
...(input.context ? { context: input.context } : {}),
|
||||
baseBranch: input.baseRefName,
|
||||
headSelector: input.headSelector,
|
||||
...(source ? { source } : {}),
|
||||
...(input.target ? { target: input.target } : {}),
|
||||
title: input.title,
|
||||
bodyFile: input.bodyFile,
|
||||
})
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "createChangeRequest",
|
||||
cwd: input.cwd,
|
||||
reference: SourceControlProvider.transportSafeSourceControlErrorValue(
|
||||
input.headSelector,
|
||||
),
|
||||
detail: "Failed to create change request.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
getRepositoryCloneUrls: (input) =>
|
||||
bitbucket.getRepositoryCloneUrls(input).pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "getRepositoryCloneUrls",
|
||||
cwd: input.cwd,
|
||||
repository: SourceControlProvider.transportSafeSourceControlErrorValue(
|
||||
input.repository,
|
||||
),
|
||||
detail: "Failed to get repository clone URLs.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
),
|
||||
createRepository: (input) =>
|
||||
bitbucket.createRepository(input).pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "createRepository",
|
||||
cwd: input.cwd,
|
||||
repository: SourceControlProvider.transportSafeSourceControlErrorValue(
|
||||
input.repository,
|
||||
),
|
||||
detail: "Failed to create repository.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
),
|
||||
getDefaultBranch: (input) =>
|
||||
bitbucket
|
||||
.getDefaultBranch({
|
||||
cwd: input.cwd,
|
||||
...(input.context ? { context: input.context } : {}),
|
||||
})
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "getDefaultBranch",
|
||||
cwd: input.cwd,
|
||||
detail: "Failed to get default branch.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
),
|
||||
checkoutChangeRequest: (input) =>
|
||||
bitbucket
|
||||
.checkoutPullRequest({
|
||||
cwd: input.cwd,
|
||||
...(input.context ? { context: input.context } : {}),
|
||||
reference: input.reference,
|
||||
...(input.force !== undefined ? { force: input.force } : {}),
|
||||
})
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "checkoutChangeRequest",
|
||||
cwd: input.cwd,
|
||||
reference: SourceControlProvider.transportSafeSourceControlErrorValue(
|
||||
input.reference,
|
||||
),
|
||||
detail: "Failed to check out change request.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
export const makeDiscovery = Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
|
||||
return {
|
||||
type: "api",
|
||||
kind: "bitbucket",
|
||||
label: "Bitbucket",
|
||||
installHint: "Add a Bitbucket token in Settings → Source Control.",
|
||||
probeAuth: bitbucket.probeAuth,
|
||||
} satisfies SourceControlApiDiscoverySpec;
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { PositiveInt, TrimmedNonEmptyString } from "@t3tools/contracts";
|
||||
|
||||
export interface NormalizedBitbucketPullRequestRecord {
|
||||
readonly number: number;
|
||||
readonly title: string;
|
||||
readonly url: string;
|
||||
readonly baseRefName: string;
|
||||
readonly headRefName: string;
|
||||
readonly state: "open" | "closed" | "merged";
|
||||
readonly isDraft?: boolean;
|
||||
readonly updatedAt: Option.Option<DateTime.Utc>;
|
||||
readonly isCrossRepository?: boolean;
|
||||
readonly headRepositoryNameWithOwner?: string | null;
|
||||
readonly headRepositoryOwnerLogin?: string | null;
|
||||
}
|
||||
|
||||
export const BitbucketRepositoryRefSchema = Schema.Struct({
|
||||
full_name: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
workspace: Schema.optional(
|
||||
Schema.NullOr(
|
||||
Schema.Struct({
|
||||
slug: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
}),
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
export const BitbucketPullRequestBranchSchema = Schema.Struct({
|
||||
repository: Schema.optional(Schema.NullOr(BitbucketRepositoryRefSchema)),
|
||||
branch: Schema.Struct({
|
||||
name: TrimmedNonEmptyString,
|
||||
}),
|
||||
});
|
||||
|
||||
export const BitbucketPullRequestSchema = Schema.Struct({
|
||||
id: PositiveInt,
|
||||
title: TrimmedNonEmptyString,
|
||||
state: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
draft: Schema.optional(Schema.Boolean),
|
||||
updated_on: Schema.optional(Schema.OptionFromNullOr(Schema.DateTimeUtcFromString)),
|
||||
links: Schema.Struct({
|
||||
html: Schema.Struct({
|
||||
href: TrimmedNonEmptyString,
|
||||
}),
|
||||
}),
|
||||
source: BitbucketPullRequestBranchSchema,
|
||||
destination: BitbucketPullRequestBranchSchema,
|
||||
});
|
||||
|
||||
export const BitbucketPullRequestListSchema = Schema.Struct({
|
||||
values: Schema.Array(BitbucketPullRequestSchema),
|
||||
next: Schema.optional(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
function trimOptionalString(value: string | null | undefined): string | null {
|
||||
const trimmed = value?.trim() ?? "";
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
function repositoryOwner(repository: Schema.Schema.Type<typeof BitbucketRepositoryRefSchema>) {
|
||||
return (
|
||||
trimOptionalString(repository.workspace?.slug) ??
|
||||
(repository.full_name?.includes("/") ? (repository.full_name.split("/")[0] ?? null) : null)
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeBitbucketPullRequestState(state: string | null | undefined) {
|
||||
switch (state?.trim().toUpperCase()) {
|
||||
case "MERGED":
|
||||
return "merged" as const;
|
||||
case "DECLINED":
|
||||
case "SUPERSEDED":
|
||||
return "closed" as const;
|
||||
case "OPEN":
|
||||
default:
|
||||
return "open" as const;
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeBitbucketPullRequestRecord(
|
||||
raw: Schema.Schema.Type<typeof BitbucketPullRequestSchema>,
|
||||
): NormalizedBitbucketPullRequestRecord {
|
||||
const headRepositoryNameWithOwner = trimOptionalString(raw.source.repository?.full_name);
|
||||
const baseRepositoryNameWithOwner = trimOptionalString(raw.destination.repository?.full_name);
|
||||
const headRepositoryOwnerLogin = raw.source.repository
|
||||
? repositoryOwner(raw.source.repository)
|
||||
: null;
|
||||
const isCrossRepository =
|
||||
headRepositoryNameWithOwner !== null &&
|
||||
baseRepositoryNameWithOwner !== null &&
|
||||
headRepositoryNameWithOwner !== baseRepositoryNameWithOwner;
|
||||
|
||||
return {
|
||||
number: raw.id,
|
||||
title: raw.title,
|
||||
url: raw.links.html.href,
|
||||
baseRefName: raw.destination.branch.name,
|
||||
headRefName: raw.source.branch.name,
|
||||
state: normalizeBitbucketPullRequestState(raw.state),
|
||||
...(raw.draft === true ? { isDraft: true } : {}),
|
||||
updatedAt: raw.updated_on ?? Option.none(),
|
||||
...(isCrossRepository ? { isCrossRepository: true } : {}),
|
||||
...(headRepositoryNameWithOwner ? { headRepositoryNameWithOwner } : {}),
|
||||
...(headRepositoryOwnerLogin ? { headRepositoryOwnerLogin } : {}),
|
||||
};
|
||||
}
|
||||
@@ -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));
|
||||
Reference in new issue
Block a user