Rename git APIs around refs
- Replace branch-centric git/VCS types and methods with ref-based names - Update server, web, and tests to use the new pluggable integration shape
This commit is contained in:
1 parent
eb711cc7af
commit
d1bbd73e02
37 files changed
+1138
-1140
No files matched your search
@@ -3,27 +3,27 @@ import { Context, Effect, Layer } from "effect";
|
||||
import {
|
||||
GitManagerError,
|
||||
GitCommandError,
|
||||
type GitCheckoutInput,
|
||||
type GitCheckoutResult,
|
||||
type GitCreateBranchInput,
|
||||
type GitCreateBranchResult,
|
||||
type GitCreateWorktreeInput,
|
||||
type GitCreateWorktreeResult,
|
||||
type GitListBranchesInput,
|
||||
type GitListBranchesResult,
|
||||
type VcsSwitchRefInput,
|
||||
type VcsSwitchRefResult,
|
||||
type VcsCreateRefInput,
|
||||
type VcsCreateRefResult,
|
||||
type VcsCreateWorktreeInput,
|
||||
type VcsCreateWorktreeResult,
|
||||
type VcsListRefsInput,
|
||||
type VcsListRefsResult,
|
||||
type GitManagerServiceError,
|
||||
type GitPreparePullRequestThreadInput,
|
||||
type GitPreparePullRequestThreadResult,
|
||||
type GitPullRequestRefInput,
|
||||
type GitPullResult,
|
||||
type GitRemoveWorktreeInput,
|
||||
type VcsPullResult,
|
||||
type VcsRemoveWorktreeInput,
|
||||
type GitResolvePullRequestResult,
|
||||
type GitRunStackedActionInput,
|
||||
type GitRunStackedActionResult,
|
||||
type GitStatusInput,
|
||||
type GitStatusLocalResult,
|
||||
type GitStatusRemoteResult,
|
||||
type GitStatusResult,
|
||||
type VcsStatusInput,
|
||||
type VcsStatusLocalResult,
|
||||
type VcsStatusRemoteResult,
|
||||
type VcsStatusResult,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import { GitManager, type GitRunStackedActionOptions } from "./Services/GitManager.ts";
|
||||
@@ -32,18 +32,18 @@ import { VcsDriverRegistry } from "../vcs/VcsDriverRegistry.ts";
|
||||
|
||||
export interface GitWorkflowServiceShape {
|
||||
readonly status: (
|
||||
input: GitStatusInput,
|
||||
) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
|
||||
input: VcsStatusInput,
|
||||
) => Effect.Effect<VcsStatusResult, GitManagerServiceError>;
|
||||
readonly localStatus: (
|
||||
input: GitStatusInput,
|
||||
) => Effect.Effect<GitStatusLocalResult, GitManagerServiceError>;
|
||||
input: VcsStatusInput,
|
||||
) => Effect.Effect<VcsStatusLocalResult, GitManagerServiceError>;
|
||||
readonly remoteStatus: (
|
||||
input: GitStatusInput,
|
||||
) => Effect.Effect<GitStatusRemoteResult | null, GitManagerServiceError>;
|
||||
input: VcsStatusInput,
|
||||
) => Effect.Effect<VcsStatusRemoteResult | null, GitManagerServiceError>;
|
||||
readonly invalidateLocalStatus: (cwd: string) => Effect.Effect<void, never>;
|
||||
readonly invalidateRemoteStatus: (cwd: string) => Effect.Effect<void, never>;
|
||||
readonly invalidateStatus: (cwd: string) => Effect.Effect<void, never>;
|
||||
readonly pullCurrentBranch: (cwd: string) => Effect.Effect<GitPullResult, GitCommandError>;
|
||||
readonly pullCurrentBranch: (cwd: string) => Effect.Effect<VcsPullResult, GitCommandError>;
|
||||
readonly runStackedAction: (
|
||||
input: GitRunStackedActionInput,
|
||||
options?: GitRunStackedActionOptions,
|
||||
@@ -54,25 +54,23 @@ export interface GitWorkflowServiceShape {
|
||||
readonly preparePullRequestThread: (
|
||||
input: GitPreparePullRequestThreadInput,
|
||||
) => Effect.Effect<GitPreparePullRequestThreadResult, GitManagerServiceError>;
|
||||
readonly listBranches: (
|
||||
input: GitListBranchesInput,
|
||||
) => Effect.Effect<GitListBranchesResult, GitCommandError>;
|
||||
readonly listRefs: (input: VcsListRefsInput) => Effect.Effect<VcsListRefsResult, GitCommandError>;
|
||||
readonly createWorktree: (
|
||||
input: GitCreateWorktreeInput,
|
||||
) => Effect.Effect<GitCreateWorktreeResult, GitCommandError>;
|
||||
readonly removeWorktree: (input: GitRemoveWorktreeInput) => Effect.Effect<void, GitCommandError>;
|
||||
readonly createBranch: (
|
||||
input: GitCreateBranchInput,
|
||||
) => Effect.Effect<GitCreateBranchResult, GitCommandError>;
|
||||
readonly checkoutBranch: (
|
||||
input: GitCheckoutInput,
|
||||
) => Effect.Effect<GitCheckoutResult, GitCommandError>;
|
||||
input: VcsCreateWorktreeInput,
|
||||
) => Effect.Effect<VcsCreateWorktreeResult, GitCommandError>;
|
||||
readonly removeWorktree: (input: VcsRemoveWorktreeInput) => Effect.Effect<void, GitCommandError>;
|
||||
readonly createRef: (
|
||||
input: VcsCreateRefInput,
|
||||
) => Effect.Effect<VcsCreateRefResult, GitCommandError>;
|
||||
readonly switchRef: (
|
||||
input: VcsSwitchRefInput,
|
||||
) => Effect.Effect<VcsSwitchRefResult, GitCommandError>;
|
||||
readonly initRepo: (input: { readonly cwd: string }) => Effect.Effect<void, GitCommandError>;
|
||||
readonly renameBranch: (input: {
|
||||
readonly cwd: string;
|
||||
readonly oldBranch: string;
|
||||
readonly newBranch: string;
|
||||
}) => Effect.Effect<GitCreateBranchResult, GitManagerServiceError>;
|
||||
}) => Effect.Effect<{ readonly branch: string }, GitManagerServiceError>;
|
||||
}
|
||||
|
||||
export class GitWorkflowService extends Context.Service<
|
||||
@@ -178,9 +176,9 @@ export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
||||
"GitWorkflowService.preparePullRequestThread",
|
||||
gitManager.preparePullRequestThread,
|
||||
),
|
||||
listBranches: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.listBranches", input.cwd).pipe(
|
||||
Effect.andThen(git.listBranches(input)),
|
||||
listRefs: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.listRefs", input.cwd).pipe(
|
||||
Effect.andThen(git.listRefs(input)),
|
||||
),
|
||||
createWorktree: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.createWorktree", input.cwd).pipe(
|
||||
@@ -190,13 +188,13 @@ export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
||||
ensureGitCommand("GitWorkflowService.removeWorktree", input.cwd).pipe(
|
||||
Effect.andThen(git.removeWorktree(input)),
|
||||
),
|
||||
createBranch: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.createBranch", input.cwd).pipe(
|
||||
Effect.andThen(git.createBranch(input)),
|
||||
createRef: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.createRef", input.cwd).pipe(
|
||||
Effect.andThen(git.createRef(input)),
|
||||
),
|
||||
checkoutBranch: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.checkoutBranch", input.cwd).pipe(
|
||||
Effect.andThen(Effect.scoped(git.checkoutBranch(input))),
|
||||
switchRef: (input) =>
|
||||
ensureGitCommand("GitWorkflowService.switchRef", input.cwd).pipe(
|
||||
Effect.andThen(Effect.scoped(git.switchRef(input))),
|
||||
),
|
||||
initRepo: (input) => git.initRepo(input),
|
||||
renameBranch: (input) =>
|
||||
|
||||
@@ -717,15 +717,15 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.isRepo).toBe(true);
|
||||
expect(status.hasOriginRemote).toBe(true);
|
||||
expect(status.isDefaultBranch).toBe(false);
|
||||
expect(status.branch).toBe("feature/status-open-pr");
|
||||
expect(status.hasPrimaryRemote).toBe(true);
|
||||
expect(status.isDefaultRef).toBe(false);
|
||||
expect(status.refName).toBe("feature/status-open-pr");
|
||||
expect(status.pr).toEqual({
|
||||
number: 13,
|
||||
title: "Existing PR",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/13",
|
||||
baseBranch: "main",
|
||||
headBranch: "feature/status-open-pr",
|
||||
baseRef: "main",
|
||||
headRef: "feature/status-open-pr",
|
||||
state: "open",
|
||||
});
|
||||
}),
|
||||
@@ -762,8 +762,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
number: 14,
|
||||
title: "Existing PR title",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/14",
|
||||
baseBranch: "main",
|
||||
headBranch: "feature/status-trimmed-pr",
|
||||
baseRef: "main",
|
||||
headRef: "feature/status-trimmed-pr",
|
||||
state: "open",
|
||||
});
|
||||
}),
|
||||
@@ -813,8 +813,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
number: 15,
|
||||
title: "Valid PR title",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/15",
|
||||
baseBranch: "main",
|
||||
headBranch: "feature/status-valid-pr-entry",
|
||||
baseRef: "main",
|
||||
headRef: "feature/status-valid-pr-entry",
|
||||
state: "open",
|
||||
});
|
||||
}),
|
||||
@@ -862,8 +862,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
number: 17,
|
||||
title: "Merged PR",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/17",
|
||||
baseBranch: "main",
|
||||
headBranch: "feature/status-lowercase-state",
|
||||
baseRef: "main",
|
||||
headRef: "feature/status-lowercase-state",
|
||||
state: "merged",
|
||||
});
|
||||
}),
|
||||
@@ -878,9 +878,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
|
||||
expect(status).toEqual({
|
||||
isRepo: false,
|
||||
hasOriginRemote: false,
|
||||
isDefaultBranch: false,
|
||||
branch: null,
|
||||
hasPrimaryRemote: false,
|
||||
isDefaultRef: false,
|
||||
refName: null,
|
||||
hasWorkingTreeChanges: false,
|
||||
workingTree: {
|
||||
files: [],
|
||||
@@ -907,9 +907,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
|
||||
expect(status).toEqual({
|
||||
isRepo: false,
|
||||
hasOriginRemote: false,
|
||||
isDefaultBranch: false,
|
||||
branch: null,
|
||||
hasPrimaryRemote: false,
|
||||
isDefaultRef: false,
|
||||
refName: null,
|
||||
hasWorkingTreeChanges: false,
|
||||
workingTree: {
|
||||
files: [],
|
||||
@@ -991,7 +991,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("main");
|
||||
expect(status.refName).toBe("main");
|
||||
expect(status.pr).toBeNull();
|
||||
}),
|
||||
);
|
||||
@@ -1045,13 +1045,13 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("t3code/pr-488/statemachine");
|
||||
expect(status.refName).toBe("t3code/pr-488/statemachine");
|
||||
expect(status.pr).toEqual({
|
||||
number: 488,
|
||||
title: "Rebase this PR on latest main",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/488",
|
||||
baseBranch: "main",
|
||||
headBranch: "statemachine",
|
||||
baseRef: "main",
|
||||
headRef: "statemachine",
|
||||
state: "open",
|
||||
});
|
||||
expect(ghCalls).toContain(
|
||||
@@ -1145,13 +1145,13 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("upstream/effect-atom");
|
||||
expect(status.refName).toBe("upstream/effect-atom");
|
||||
expect(status.pr).toEqual({
|
||||
number: 1618,
|
||||
title: "Correct PR",
|
||||
url: "https://github.com/pingdotgg/t3code/pull/1618",
|
||||
baseBranch: "main",
|
||||
headBranch: "effect-atom",
|
||||
baseRef: "main",
|
||||
headRef: "effect-atom",
|
||||
state: "open",
|
||||
});
|
||||
expect(ghCalls.some((call) => call.includes("pr list --head upstream/effect-atom "))).toBe(
|
||||
@@ -1195,13 +1195,13 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("feature/status-merged-pr");
|
||||
expect(status.refName).toBe("feature/status-merged-pr");
|
||||
expect(status.pr).toEqual({
|
||||
number: 22,
|
||||
title: "Merged PR",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/22",
|
||||
baseBranch: "main",
|
||||
headBranch: "feature/status-merged-pr",
|
||||
baseRef: "main",
|
||||
headRef: "feature/status-merged-pr",
|
||||
state: "merged",
|
||||
});
|
||||
}),
|
||||
@@ -1232,7 +1232,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("main");
|
||||
expect(status.refName).toBe("main");
|
||||
expect(status.pr).toBeNull();
|
||||
}),
|
||||
);
|
||||
@@ -1272,13 +1272,13 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("feature/status-open-over-merged");
|
||||
expect(status.refName).toBe("feature/status-open-over-merged");
|
||||
expect(status.pr).toEqual({
|
||||
number: 46,
|
||||
title: "Open PR",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/46",
|
||||
baseBranch: "main",
|
||||
headBranch: "feature/status-open-over-merged",
|
||||
baseRef: "main",
|
||||
headRef: "feature/status-open-over-merged",
|
||||
state: "open",
|
||||
});
|
||||
}),
|
||||
@@ -1303,7 +1303,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
expect(status.branch).toBe("feature/status-no-gh");
|
||||
expect(status.refName).toBe("feature/status-no-gh");
|
||||
expect(status.pr).toBeNull();
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
GitCommandError,
|
||||
GitRunStackedActionResult,
|
||||
GitStackedAction,
|
||||
type GitStatusLocalResult,
|
||||
type GitStatusRemoteResult,
|
||||
type VcsStatusLocalResult,
|
||||
type VcsStatusRemoteResult,
|
||||
ModelSelection,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
@@ -425,16 +425,16 @@ function toStatusPr(pr: PullRequestInfo): {
|
||||
number: number;
|
||||
title: string;
|
||||
url: string;
|
||||
baseBranch: string;
|
||||
headBranch: string;
|
||||
baseRef: string;
|
||||
headRef: string;
|
||||
state: "open" | "closed" | "merged";
|
||||
} {
|
||||
return {
|
||||
number: pr.number,
|
||||
title: pr.title,
|
||||
url: pr.url,
|
||||
baseBranch: pr.baseRefName,
|
||||
headBranch: pr.headRefName,
|
||||
baseRef: pr.baseRefName,
|
||||
headRef: pr.headRefName,
|
||||
state: pr.state,
|
||||
};
|
||||
}
|
||||
@@ -666,12 +666,12 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
return {
|
||||
isRepo: details.isRepo,
|
||||
...(hostingProvider ? { hostingProvider } : {}),
|
||||
hasOriginRemote: details.hasOriginRemote,
|
||||
isDefaultBranch: details.isDefaultBranch,
|
||||
branch: details.branch,
|
||||
hasPrimaryRemote: details.hasOriginRemote,
|
||||
isDefaultRef: details.isDefaultBranch,
|
||||
refName: details.branch,
|
||||
hasWorkingTreeChanges: details.hasWorkingTreeChanges,
|
||||
workingTree: details.workingTree,
|
||||
} satisfies GitStatusLocalResult;
|
||||
} satisfies VcsStatusLocalResult;
|
||||
});
|
||||
const localStatusResultCache = yield* Cache.makeWith(readLocalStatus, {
|
||||
capacity: STATUS_RESULT_CACHE_CAPACITY,
|
||||
@@ -709,7 +709,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
aheadCount: details.aheadCount,
|
||||
behindCount: details.behindCount,
|
||||
pr,
|
||||
} satisfies GitStatusRemoteResult;
|
||||
} satisfies VcsStatusRemoteResult;
|
||||
});
|
||||
const remoteStatusResultCache = yield* Cache.makeWith(readRemoteStatus, {
|
||||
capacity: STATUS_RESULT_CACHE_CAPACITY,
|
||||
@@ -1390,9 +1390,9 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
resolvePullRequestWorktreeLocalBranchName(pullRequestWithRemoteInfo);
|
||||
|
||||
const findLocalHeadBranch = (cwd: string) =>
|
||||
gitCore.listBranches({ cwd }).pipe(
|
||||
gitCore.listRefs({ cwd }).pipe(
|
||||
Effect.map((result) => {
|
||||
const localBranch = result.branches.find(
|
||||
const localBranch = result.refs.find(
|
||||
(branch) => !branch.isRemote && branch.name === localPullRequestBranch,
|
||||
);
|
||||
if (localBranch) {
|
||||
@@ -1402,7 +1402,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
result.branches.find(
|
||||
result.refs.find(
|
||||
(branch) =>
|
||||
!branch.isRemote &&
|
||||
branch.name === pullRequest.headBranch &&
|
||||
@@ -1465,7 +1465,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
|
||||
const worktree = yield* gitCore.createWorktree({
|
||||
cwd: input.cwd,
|
||||
branch: localPullRequestBranch,
|
||||
refName: localPullRequestBranch,
|
||||
path: null,
|
||||
});
|
||||
yield* ensureExistingWorktreeUpstream(worktree.worktree.path);
|
||||
@@ -1473,7 +1473,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
|
||||
return {
|
||||
pullRequest,
|
||||
branch: worktree.worktree.branch,
|
||||
branch: worktree.worktree.refName,
|
||||
worktreePath: worktree.worktree.path,
|
||||
};
|
||||
}).pipe(Effect.ensuring(invalidateStatus(input.cwd)));
|
||||
@@ -1505,8 +1505,8 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
const existingBranchNames = yield* gitCore.listLocalBranchNames(cwd);
|
||||
const resolvedBranch = resolveAutoFeatureBranchName(existingBranchNames, preferredBranch);
|
||||
|
||||
yield* gitCore.createBranch({ cwd, branch: resolvedBranch });
|
||||
yield* Effect.scoped(gitCore.checkoutBranch({ cwd, branch: resolvedBranch }));
|
||||
yield* gitCore.createRef({ cwd, refName: resolvedBranch });
|
||||
yield* Effect.scoped(gitCore.switchRef({ cwd, refName: resolvedBranch }));
|
||||
|
||||
return {
|
||||
branchStep: { status: "created" as const, name: resolvedBranch },
|
||||
|
||||
@@ -14,10 +14,10 @@ import {
|
||||
GitResolvePullRequestResult,
|
||||
GitRunStackedActionInput,
|
||||
GitRunStackedActionResult,
|
||||
GitStatusLocalResult,
|
||||
GitStatusRemoteResult,
|
||||
GitStatusInput,
|
||||
GitStatusResult,
|
||||
VcsStatusLocalResult,
|
||||
VcsStatusRemoteResult,
|
||||
VcsStatusInput,
|
||||
VcsStatusResult,
|
||||
} from "@t3tools/contracts";
|
||||
import { Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
@@ -40,22 +40,22 @@ export interface GitManagerShape {
|
||||
* Read current repository Git status plus open PR metadata when available.
|
||||
*/
|
||||
readonly status: (
|
||||
input: GitStatusInput,
|
||||
) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
|
||||
input: VcsStatusInput,
|
||||
) => Effect.Effect<VcsStatusResult, GitManagerServiceError>;
|
||||
|
||||
/**
|
||||
* Read local repository status without remote hosting enrichment.
|
||||
*/
|
||||
readonly localStatus: (
|
||||
input: GitStatusInput,
|
||||
) => Effect.Effect<GitStatusLocalResult, GitManagerServiceError>;
|
||||
input: VcsStatusInput,
|
||||
) => Effect.Effect<VcsStatusLocalResult, GitManagerServiceError>;
|
||||
|
||||
/**
|
||||
* Read remote tracking / PR status for a repository.
|
||||
*/
|
||||
readonly remoteStatus: (
|
||||
input: GitStatusInput,
|
||||
) => Effect.Effect<GitStatusRemoteResult | null, GitManagerServiceError>;
|
||||
input: VcsStatusInput,
|
||||
) => Effect.Effect<VcsStatusRemoteResult | null, GitManagerServiceError>;
|
||||
|
||||
/**
|
||||
* Clear any cached local status snapshot for a repository.
|
||||
|
||||
Reference in new issue
Block a user