import { ConnectionManager, Context, TaskRegistry } from '@things-factory/integration-base' import path from 'path' import fs from 'fs-extra' const debug = require('debug')('things-factory:git-clone') async function gitClone(step, { domain, data }: Context) { const { connection, params: { targetDir } } = step // ✅ Git 연결 정보 가져오기 const gitInstance = await ConnectionManager.getConnectionInstanceByName(domain, connection) if (!gitInstance) { debug(`No connection: ${connection}`) throw new Error(`No connection: ${connection}`) } const { client, branch, remoteUrl } = gitInstance if (!remoteUrl) { throw new Error(`Remote URL is required for Git repository: ${connection}`) } const repoName = remoteUrl.split('/').pop().replace('.git', '') + `@${branch}` const repoPath = path.join(targetDir, repoName) // ✅ 리포지토리가 이미 존재하면 Pull, 없으면 Clone 실행 if (fs.existsSync(repoPath)) { debug(`Repository already exists at ${repoPath}. Pulling latest changes...`) await client.cwd(repoPath).pull() } else { debug(`Cloning repository ${remoteUrl} into ${repoPath}...`) await client.clone(remoteUrl, repoPath, ['-b', branch]) } return { data: repoPath } } gitClone.parameterSpec = [{ type: 'string', name: 'targetDir', label: 'git.target-dir' }] gitClone.help = 'integration/task/git-clone' TaskRegistry.registerTaskHandler('git-clone', gitClone)