import { ConnectionManager, Context, TaskRegistry } from '@things-factory/integration-base' import simpleGit from 'simple-git' import path from 'path' import fs from 'fs-extra' const debug = require('debug')('things-factory:git-pull') async function gitPull(step, { domain, data }: Context) { const { connection, params: { targetDir } } = step // ✅ Git 연결 정보 가져오기 const gitInstance = await ConnectionManager.getConnectionInstanceByName(domain, connection) if (!gitInstance) { debug(`No connection found: ${connection}`) throw new Error(`No connection: ${connection}`) } const { client = simpleGit(), remoteUrl } = gitInstance if (!remoteUrl) { throw new Error(`Remote URL is required for Git repository: ${connection}`) } // ✅ 리포지토리 경로 계산 const repoName = remoteUrl.split('/').pop().replace('.git', '') const repoPath = path.join(targetDir, repoName) if (!fs.existsSync(repoPath)) { throw new Error(`Repository does not exist at ${repoPath}. Please run "git-clone" first.`) } // ✅ Git 저장소인지 확인 const isRepo = await client.cwd(repoPath).checkIsRepo() if (!isRepo) { throw new Error(`Invalid Git repository at ${repoPath}`) } // ✅ 최신 변경사항 가져오기 (fetch + pull) debug(`Fetching latest changes for ${connection}...`) await client.cwd(repoPath).fetch() debug(`Pulling latest changes for ${connection}...`) await client.cwd(repoPath).pull() return { data: repoPath } } // ✅ 파라미터 정의 gitPull.parameterSpec = [{ type: 'string', name: 'targetDir', label: 'git.target-dir' }] // ✅ 도움말 정의 gitPull.help = 'integration/task/git-pull' // ✅ 태스크 등록 TaskRegistry.registerTaskHandler('git-pull', gitPull)