Refactor ProjectsManager.cloneProject to accept an options object

This commit is contained in:
Alex Gleason committed 2025-12-23 01:45:12 -06:00
1 parent b99c20c7f7
commit 8b8958f7c8
4 files changed
+26 -6

No files matched your search

+4 -1
View File
@@ -41,7 +41,10 @@ export function RepositoryCard({ repo }: RepositoryCardProps) {
await projectsManager.init();
// Clone the repository using the Nostr URI
const project = await projectsManager.cloneProject(repo.name, nostrURI.toString());
const project = await projectsManager.cloneProject({
name: repo.name,
repoUrl: nostrURI.toString(),
});
toast({
title: t('nostrRepositoryImportedSuccessfully'),
+8 -2
View File
@@ -457,7 +457,10 @@ describe('ProjectsManager', () => {
Object.assign(projectsManager, { git: mockGit });
// Attempt to clone a project
await expect(projectsManager.cloneProject('test-project', 'https://github.com/test/repo.git'))
await expect(projectsManager.cloneProject({
name: 'test-project',
repoUrl: 'https://github.com/test/repo.git',
}))
.rejects.toThrow('Clone failed');
// Verify that the project directory was cleaned up
@@ -488,7 +491,10 @@ describe('ProjectsManager', () => {
try {
// Attempt to clone a project
await expect(projectsManager.cloneProject('test-project', 'https://github.com/test/repo.git'))
await expect(projectsManager.cloneProject({
name: 'test-project',
repoUrl: 'https://github.com/test/repo.git',
}))
.rejects.toThrow('Clone failed');
// Should have logged a cleanup warning
+10 -2
View File
@@ -494,7 +494,14 @@ export class ProjectsManager {
}
}
async cloneProject(name: string, repoUrl: string, customId?: string, options?: { depth?: number }): Promise<Project> {
async cloneProject(options: {
name: string;
repoUrl: string;
customId?: string;
depth?: number;
remote?: string;
}): Promise<Project> {
const { name, repoUrl, customId, depth, remote } = options;
const id = customId || await this.generateUniqueProjectId(name);
// Check if project with this ID already exists when using custom ID
@@ -512,7 +519,8 @@ export class ProjectsManager {
dir: projectPath,
url: repoUrl,
singleBranch: true,
depth: options?.depth, // Use depth if provided, otherwise clone full history
depth, // Use depth if provided, otherwise clone full history
remote, // Use remote if provided, otherwise defaults to 'origin'
});
// Get filesystem stats for timestamps
+4 -1
View File
@@ -156,7 +156,10 @@ export default function Clone() {
const repoName = await extractRepoName(targetUrl);
// Clone the repository (Git class handles both regular Git URLs and Nostr URIs)
const project = await projectsManager.cloneProject(repoName, targetUrl.trim());
const project = await projectsManager.cloneProject({
name: repoName,
repoUrl: targetUrl.trim(),
});
// Determine success message based on URL type
const isNostrUri = targetUrl.startsWith('nostr://');