bea71ab85b
- Resolve 57 merge conflicts from codebase restructure - Port dev feature code to new directory structure: * Update import paths to use @/ aliases * Add backward-compatible API signatures (createInstance, startInstance, deleteInstance) * Add missing type exports (ProjectWithRepos, InstanceHealth, Branch, BranchesResponse) * Extend Session and GitRepository types for dev features * Extend TerminalComponent props for mobile terminal wrapper * Add missing icon names (bell, drag, undo) Quality gates: tsc pass (0 errors), build pass, 127/131 tests pass (4 pre-existing failures unrelated to merge)
213 lines
5.0 KiB
TypeScript
213 lines
5.0 KiB
TypeScript
import { apiClient } from "./client";
|
|
import type {
|
|
CommitDetail,
|
|
CommitHistoryResponse,
|
|
CommitResponse,
|
|
GitRepository,
|
|
GitRepositoryCreate,
|
|
GitStatus,
|
|
MergeResponse,
|
|
URLParseResult,
|
|
} from "../types/git-repository";
|
|
|
|
export type {
|
|
CommitDetail,
|
|
CommitHistoryEntry,
|
|
CommitHistoryResponse,
|
|
CommitResponse,
|
|
GitRepository,
|
|
GitRepositoryCreate,
|
|
GitStatus,
|
|
MergeResponse,
|
|
URLParseResult,
|
|
} from "../types/git-repository";
|
|
|
|
export interface Branch {
|
|
name: string;
|
|
is_default: boolean;
|
|
last_commit: string | null;
|
|
}
|
|
|
|
export interface BranchesResponse {
|
|
branches: Branch[];
|
|
default_branch: string;
|
|
}
|
|
|
|
export async function parseGitUrl(url: string): Promise<URLParseResult> {
|
|
const response = await apiClient.post("/projects/repositories/parse-url", {
|
|
url,
|
|
});
|
|
return response.data;
|
|
}
|
|
|
|
export async function listRepositories(
|
|
projectId: string,
|
|
): Promise<GitRepository[]> {
|
|
const response = await apiClient.get(`/projects/${projectId}/repositories`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function listRepositoryBranches(
|
|
projectId: string,
|
|
repoId: string,
|
|
): Promise<BranchesResponse> {
|
|
const response = await apiClient.get(
|
|
`/projects/${projectId}/repositories/${repoId}/branches`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function createRepository(
|
|
projectId: string,
|
|
data: GitRepositoryCreate,
|
|
): Promise<GitRepository> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories`,
|
|
data,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function deleteRepository(
|
|
projectId: string,
|
|
repoId: string,
|
|
): Promise<void> {
|
|
await apiClient.delete(`/projects/${projectId}/repositories/${repoId}`);
|
|
}
|
|
|
|
export async function getRepositoryHistory(
|
|
projectId: string,
|
|
repoId: string,
|
|
branch?: string,
|
|
limit?: number,
|
|
): Promise<CommitHistoryResponse> {
|
|
const searchParams = new URLSearchParams();
|
|
if (branch) searchParams.set("branch", branch);
|
|
if (limit) searchParams.set("limit", String(limit));
|
|
const queryString = searchParams.toString();
|
|
const params = queryString ? `?${queryString}` : "";
|
|
const response = await apiClient.get(
|
|
`/projects/${projectId}/repositories/${repoId}/history${params}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getCommitDetail(
|
|
projectId: string,
|
|
repoId: string,
|
|
commitHash: string,
|
|
): Promise<CommitDetail> {
|
|
const response = await apiClient.get(
|
|
`/projects/${projectId}/repositories/${repoId}/commits/${commitHash}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getRepositoryStatus(
|
|
projectId: string,
|
|
repoId: string,
|
|
): Promise<GitStatus> {
|
|
const response = await apiClient.get(
|
|
`/projects/${projectId}/repositories/${repoId}/status`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function createBranch(
|
|
projectId: string,
|
|
repoId: string,
|
|
name: string,
|
|
baseBranch: string = "HEAD",
|
|
): Promise<{ message: string; branch: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/branches`,
|
|
{ name, base_branch: baseBranch },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function deleteBranch(
|
|
projectId: string,
|
|
repoId: string,
|
|
branchName: string,
|
|
force: boolean = false,
|
|
): Promise<{ message: string }> {
|
|
const response = await apiClient.delete(
|
|
`/projects/${projectId}/repositories/${repoId}/branches/${branchName}?force=${force}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function checkoutBranch(
|
|
projectId: string,
|
|
repoId: string,
|
|
branch: string,
|
|
): Promise<{ message: string; branch: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/checkout`,
|
|
{ branch },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function commitChanges(
|
|
projectId: string,
|
|
repoId: string,
|
|
message: string,
|
|
files?: string[],
|
|
): Promise<CommitResponse> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/commit`,
|
|
{ message, files },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function fetchRepository(
|
|
projectId: string,
|
|
repoId: string,
|
|
): Promise<{ message: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/fetch`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function pullRepository(
|
|
projectId: string,
|
|
repoId: string,
|
|
branch?: string,
|
|
): Promise<{ message: string }> {
|
|
const params = branch ? `?branch=${branch}` : "";
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/pull${params}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function pushRepository(
|
|
projectId: string,
|
|
repoId: string,
|
|
branch?: string,
|
|
): Promise<{ message: string }> {
|
|
const params = branch ? `?branch=${branch}` : "";
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/push${params}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function mergeBranches(
|
|
projectId: string,
|
|
repoId: string,
|
|
sourceBranch: string,
|
|
targetBranch?: string,
|
|
message?: string,
|
|
): Promise<MergeResponse> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/merge`,
|
|
{ source_branch: sourceBranch, target_branch: targetBranch, message },
|
|
);
|
|
return response.data;
|
|
}
|