Rename git hosting provider fields to source control provider
- Rename shared/server status fields and detectors from hostingProvider to sourceControlProvider - Move provider schema into contracts/sourceControl and update status/event tests - Refresh branch toolbar labels from switchRef to checkout
This commit is contained in:
1 parent
d1bbd73e02
commit
b3d90d4221
12 files changed
+48
-49
No files matched your search
@@ -26,7 +26,7 @@ import {
|
||||
ModelSelection,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
detectGitHostingProviderFromRemoteUrl,
|
||||
detectSourceControlProviderFromGitRemoteUrl,
|
||||
mergeGitStatusParts,
|
||||
resolveAutoFeatureBranchName,
|
||||
sanitizeBranchFragment,
|
||||
@@ -659,13 +659,13 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
.pipe(
|
||||
Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(nonRepositoryStatusDetails)),
|
||||
);
|
||||
const hostingProvider = details.isRepo
|
||||
const sourceControlProvider = details.isRepo
|
||||
? yield* resolveHostingProvider(cwd, details.branch)
|
||||
: null;
|
||||
|
||||
return {
|
||||
isRepo: details.isRepo,
|
||||
...(hostingProvider ? { hostingProvider } : {}),
|
||||
...(sourceControlProvider ? { sourceControlProvider } : {}),
|
||||
hasPrimaryRemote: details.hasOriginRemote,
|
||||
isDefaultRef: details.isDefaultBranch,
|
||||
refName: details.branch,
|
||||
@@ -733,7 +733,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
(yield* readConfigValueNullable(cwd, `remote.${preferredRemoteName}.url`)) ??
|
||||
(yield* readConfigValueNullable(cwd, "remote.origin.url"));
|
||||
|
||||
return remoteUrl ? detectGitHostingProviderFromRemoteUrl(remoteUrl) : null;
|
||||
return remoteUrl ? detectSourceControlProviderFromGitRemoteUrl(remoteUrl) : null;
|
||||
});
|
||||
|
||||
const resolveRemoteRepositoryContext = Effect.fn("resolveRemoteRepositoryContext")(function* (
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { RepositoryIdentity } from "@t3tools/contracts";
|
||||
import { Cache, Duration, Effect, Exit, Layer } from "effect";
|
||||
import { detectGitHostingProviderFromRemoteUrl, normalizeGitRemoteUrl } from "@t3tools/shared/git";
|
||||
import {
|
||||
detectSourceControlProviderFromGitRemoteUrl,
|
||||
normalizeGitRemoteUrl,
|
||||
} from "@t3tools/shared/git";
|
||||
|
||||
import { runProcess } from "../../processRunner.ts";
|
||||
import {
|
||||
@@ -45,7 +48,7 @@ function buildRepositoryIdentity(input: {
|
||||
readonly rootPath: string;
|
||||
}): RepositoryIdentity {
|
||||
const canonicalKey = normalizeGitRemoteUrl(input.remoteUrl);
|
||||
const hostingProvider = detectGitHostingProviderFromRemoteUrl(input.remoteUrl);
|
||||
const sourceControlProvider = detectSourceControlProviderFromGitRemoteUrl(input.remoteUrl);
|
||||
const repositoryPath = canonicalKey.split("/").slice(1).join("/");
|
||||
const repositoryPathSegments = repositoryPath.split("/").filter((segment) => segment.length > 0);
|
||||
const [owner] = repositoryPathSegments;
|
||||
@@ -60,7 +63,7 @@ function buildRepositoryIdentity(input: {
|
||||
},
|
||||
rootPath: input.rootPath,
|
||||
...(repositoryPath ? { displayName: repositoryPath } : {}),
|
||||
...(hostingProvider ? { provider: hostingProvider.kind } : {}),
|
||||
...(sourceControlProvider ? { provider: sourceControlProvider.kind } : {}),
|
||||
...(owner ? { owner } : {}),
|
||||
...(repositoryName ? { name: repositoryName } : {}),
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Cache, Context, Duration, Effect, Exit, Layer } from "effect";
|
||||
import { SourceControlProviderError } from "@t3tools/contracts";
|
||||
import type { SourceControlProviderKind } from "@t3tools/contracts";
|
||||
import { detectGitHostingProviderFromRemoteUrl } from "@t3tools/shared/git";
|
||||
import { detectSourceControlProviderFromGitRemoteUrl } from "@t3tools/shared/git";
|
||||
|
||||
import { SourceControlProvider, type SourceControlProviderShape } from "./SourceControlProvider.ts";
|
||||
import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";
|
||||
@@ -98,7 +98,7 @@ export const make = Effect.fn("makeSourceControlProviderRegistry")(function* ()
|
||||
return "unknown" as const;
|
||||
}
|
||||
|
||||
return detectGitHostingProviderFromRemoteUrl(remoteUrl)?.kind ?? "unknown";
|
||||
return detectSourceControlProviderFromGitRemoteUrl(remoteUrl)?.kind ?? "unknown";
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export interface ExecuteGitResult {
|
||||
|
||||
export interface GitStatusDetails {
|
||||
isRepo: boolean;
|
||||
hostingProvider?: VcsStatusResult["hostingProvider"];
|
||||
sourceControlProvider?: VcsStatusResult["sourceControlProvider"];
|
||||
hasOriginRemote: boolean;
|
||||
isDefaultBranch: boolean;
|
||||
branch: string | null;
|
||||
|
||||
@@ -16,7 +16,7 @@ import { GitWorkflowService, type GitWorkflowServiceShape } from "../git/GitWork
|
||||
|
||||
const baseLocalStatus: VcsStatusLocalResult = {
|
||||
isRepo: true,
|
||||
hostingProvider: {
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
name: "GitHub",
|
||||
baseUrl: "https://github.com",
|
||||
|
||||
@@ -120,7 +120,7 @@ describe("resolveEnvironmentOptionLabel", () => {
|
||||
});
|
||||
|
||||
describe("resolveEffectiveEnvMode", () => {
|
||||
it("treats draft threads already attached to a worktree as current-switchRef mode", () => {
|
||||
it("treats draft threads already attached to a worktree as current-checkout mode", () => {
|
||||
expect(
|
||||
resolveEffectiveEnvMode({
|
||||
activeWorktreePath: "/repo/.t3/worktrees/feature-a",
|
||||
@@ -143,24 +143,24 @@ describe("resolveEffectiveEnvMode", () => {
|
||||
|
||||
describe("resolveEnvModeLabel", () => {
|
||||
it("uses explicit workspace labels", () => {
|
||||
expect(resolveEnvModeLabel("local")).toBe("Current switchRef");
|
||||
expect(resolveEnvModeLabel("local")).toBe("Current checkout");
|
||||
expect(resolveEnvModeLabel("worktree")).toBe("New worktree");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveCurrentWorkspaceLabel", () => {
|
||||
it("describes the main repo switchRef when no worktree path is active", () => {
|
||||
expect(resolveCurrentWorkspaceLabel(null)).toBe("Current switchRef");
|
||||
it("describes the main repo checkout when no worktree path is active", () => {
|
||||
expect(resolveCurrentWorkspaceLabel(null)).toBe("Current checkout");
|
||||
});
|
||||
|
||||
it("describes the active switchRef as a worktree when one is attached", () => {
|
||||
it("describes the active checkout as a worktree when one is attached", () => {
|
||||
expect(resolveCurrentWorkspaceLabel("/repo/.t3/worktrees/feature-a")).toBe("Current worktree");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveLockedWorkspaceLabel", () => {
|
||||
it("uses a shorter label for the main repo switchRef", () => {
|
||||
expect(resolveLockedWorkspaceLabel(null)).toBe("Local switchRef");
|
||||
it("uses a shorter label for the main repo checkout", () => {
|
||||
expect(resolveLockedWorkspaceLabel(null)).toBe("Local checkout");
|
||||
});
|
||||
|
||||
it("uses a shorter label for an attached worktree", () => {
|
||||
@@ -343,7 +343,7 @@ describe("resolveBranchSelectionTarget", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps switchRef in the current worktree for non-default refs", () => {
|
||||
it("keeps checkout in the current worktree for non-default refs", () => {
|
||||
expect(
|
||||
resolveBranchSelectionTarget({
|
||||
activeProjectCwd: "/repo",
|
||||
@@ -362,12 +362,12 @@ describe("resolveBranchSelectionTarget", () => {
|
||||
});
|
||||
|
||||
describe("shouldIncludeBranchPickerItem", () => {
|
||||
it("keeps the synthetic switchRef PR item visible for gh pr switchRef input", () => {
|
||||
it("keeps the synthetic checkout PR item visible for gh pr checkout input", () => {
|
||||
expect(
|
||||
shouldIncludeBranchPickerItem({
|
||||
itemValue: "__checkout_pull_request__:1359",
|
||||
normalizedQuery: "gh pr switchRef 1359",
|
||||
createBranchItemValue: "__create_new_branch__:gh pr switchRef 1359",
|
||||
normalizedQuery: "gh pr checkout 1359",
|
||||
createBranchItemValue: "__create_new_branch__:gh pr checkout 1359",
|
||||
checkoutPullRequestItemValue: "__checkout_pull_request__:1359",
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -388,8 +388,8 @@ describe("shouldIncludeBranchPickerItem", () => {
|
||||
expect(
|
||||
shouldIncludeBranchPickerItem({
|
||||
itemValue: "main",
|
||||
normalizedQuery: "gh pr switchRef 1359",
|
||||
createBranchItemValue: "__create_new_branch__:gh pr switchRef 1359",
|
||||
normalizedQuery: "gh pr checkout 1359",
|
||||
createBranchItemValue: "__create_new_branch__:gh pr checkout 1359",
|
||||
checkoutPullRequestItemValue: "__checkout_pull_request__:1359",
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
@@ -43,7 +43,7 @@ export function resolveEnvironmentOptionLabel(input: {
|
||||
}
|
||||
|
||||
export function resolveEnvModeLabel(mode: EnvMode): string {
|
||||
return mode === "worktree" ? "New worktree" : "Current switchRef";
|
||||
return mode === "worktree" ? "New worktree" : "Current checkout";
|
||||
}
|
||||
|
||||
export function resolveCurrentWorkspaceLabel(activeWorktreePath: string | null): string {
|
||||
@@ -51,7 +51,7 @@ export function resolveCurrentWorkspaceLabel(activeWorktreePath: string | null):
|
||||
}
|
||||
|
||||
export function resolveLockedWorkspaceLabel(activeWorktreePath: string | null): string {
|
||||
return activeWorktreePath ? "Worktree" : "Local switchRef";
|
||||
return activeWorktreePath ? "Worktree" : "Local checkout";
|
||||
}
|
||||
|
||||
export function resolveEffectiveEnvMode(input: {
|
||||
|
||||
@@ -78,7 +78,7 @@ describe("GitRunStackedActionResult", () => {
|
||||
it("decodes a server-authored completion toast", () => {
|
||||
const parsed = decodeRunStackedActionResult({
|
||||
action: "commit_push",
|
||||
refName: {
|
||||
branch: {
|
||||
status: "created",
|
||||
name: "feature/server-owned-toast",
|
||||
},
|
||||
@@ -89,8 +89,8 @@ describe("GitRunStackedActionResult", () => {
|
||||
},
|
||||
push: {
|
||||
status: "pushed",
|
||||
refName: "feature/server-owned-toast",
|
||||
upstreamRef: "origin/feature/server-owned-toast",
|
||||
branch: "feature/server-owned-toast",
|
||||
upstreamBranch: "origin/feature/server-owned-toast",
|
||||
},
|
||||
pr: {
|
||||
status: "skipped_not_requested",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Schema } from "effect";
|
||||
import { NonNegativeInt, PositiveInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
||||
import { SourceControlProviderError } from "./sourceControl.ts";
|
||||
import { SourceControlProviderError, SourceControlProviderInfo } from "./sourceControl.ts";
|
||||
|
||||
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
|
||||
const GIT_LIST_BRANCHES_MAX_LIMIT = 200;
|
||||
@@ -45,19 +45,6 @@ const VcsStatusChangeRequestState = Schema.Literals(["open", "closed", "merged"]
|
||||
const GitPullRequestReference = TrimmedNonEmptyStringSchema;
|
||||
const GitPullRequestState = Schema.Literals(["open", "closed", "merged"]);
|
||||
const GitPreparePullRequestThreadMode = Schema.Literals(["local", "worktree"]);
|
||||
export const GitHostingProviderKind = Schema.Literals([
|
||||
"github",
|
||||
"gitlab",
|
||||
"azure-devops",
|
||||
"unknown",
|
||||
]);
|
||||
export type GitHostingProviderKind = typeof GitHostingProviderKind.Type;
|
||||
export const GitHostingProvider = Schema.Struct({
|
||||
kind: GitHostingProviderKind,
|
||||
name: TrimmedNonEmptyStringSchema,
|
||||
baseUrl: Schema.String,
|
||||
});
|
||||
export type GitHostingProvider = typeof GitHostingProvider.Type;
|
||||
export const GitRunStackedActionToastRunAction = Schema.Struct({
|
||||
kind: GitStackedAction,
|
||||
});
|
||||
@@ -208,7 +195,7 @@ const VcsStatusChangeRequest = Schema.Struct({
|
||||
|
||||
const VcsStatusLocalShape = {
|
||||
isRepo: Schema.Boolean,
|
||||
hostingProvider: Schema.optional(GitHostingProvider),
|
||||
sourceControlProvider: Schema.optional(SourceControlProviderInfo),
|
||||
hasPrimaryRemote: Schema.Boolean,
|
||||
isDefaultRef: Schema.Boolean,
|
||||
refName: Schema.NullOr(TrimmedNonEmptyStringSchema),
|
||||
|
||||
@@ -9,6 +9,13 @@ export const SourceControlProviderKind = Schema.Literals([
|
||||
]);
|
||||
export type SourceControlProviderKind = typeof SourceControlProviderKind.Type;
|
||||
|
||||
export const SourceControlProviderInfo = Schema.Struct({
|
||||
kind: SourceControlProviderKind,
|
||||
name: TrimmedNonEmptyString,
|
||||
baseUrl: Schema.String,
|
||||
});
|
||||
export type SourceControlProviderInfo = typeof SourceControlProviderInfo.Type;
|
||||
|
||||
export const ChangeRequestState = Schema.Literals(["open", "closed", "merged"]);
|
||||
export type ChangeRequestState = typeof ChangeRequestState.Type;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ describe("applyGitStatusStreamEvent", () => {
|
||||
it("preserves local-only fields when applying a remote update", () => {
|
||||
const current: VcsStatusResult = {
|
||||
isRepo: true,
|
||||
hostingProvider: {
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
name: "GitHub",
|
||||
baseUrl: "https://github.com",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type {
|
||||
VcsRef,
|
||||
GitHostingProvider,
|
||||
SourceControlProviderInfo,
|
||||
VcsStatusLocalResult,
|
||||
VcsStatusRemoteResult,
|
||||
VcsStatusResult,
|
||||
@@ -229,9 +229,9 @@ function isAzureDevOpsHost(host: string): boolean {
|
||||
return host === "dev.azure.com" || host.endsWith(".visualstudio.com");
|
||||
}
|
||||
|
||||
export function detectGitHostingProviderFromRemoteUrl(
|
||||
export function detectSourceControlProviderFromGitRemoteUrl(
|
||||
remoteUrl: string,
|
||||
): GitHostingProvider | null {
|
||||
): SourceControlProviderInfo | null {
|
||||
const host = parseGitRemoteHost(remoteUrl);
|
||||
if (!host) {
|
||||
return null;
|
||||
@@ -297,7 +297,9 @@ function toRemoteStatusPart(status: VcsStatusResult): VcsStatusRemoteResult {
|
||||
function toLocalStatusPart(status: VcsStatusResult): VcsStatusLocalResult {
|
||||
return {
|
||||
isRepo: status.isRepo,
|
||||
...(status.hostingProvider ? { hostingProvider: status.hostingProvider } : {}),
|
||||
...(status.sourceControlProvider
|
||||
? { sourceControlProvider: status.sourceControlProvider }
|
||||
: {}),
|
||||
hasPrimaryRemote: status.hasPrimaryRemote,
|
||||
isDefaultRef: status.isDefaultRef,
|
||||
refName: status.refName,
|
||||
|
||||
Reference in new issue
Block a user