diff --git a/app/git.js b/app/git.js index d7fc88e..1f71689 100644 --- a/app/git.js +++ b/app/git.js @@ -68,6 +68,10 @@ export async function commitAndPush(workspace, repoDir, _spawnSync = spawnSync, await withAskpass(workspace, async credEnv => { run(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir); run(['config', 'user.name', 'AI Review Bot'], repoDir); + if (PR_HEAD_BRANCH) { + run(['fetch', 'origin', PR_HEAD_BRANCH], repoDir, credEnv); + run(['reset', '--hard', `origin/${PR_HEAD_BRANCH}`], repoDir); + } const existingSyncPaths = []; @@ -86,8 +90,14 @@ export async function commitAndPush(workspace, repoDir, _spawnSync = spawnSync, if (existingSyncPaths.length > 0) { run(['add', ...existingSyncPaths], repoDir); } - const generatedSyncPaths = GENERATED_SYNC_PATHS.filter(relPath => fs.existsSync(path.join(repoDir, relPath))); + const generatedSyncPaths = GENERATED_SYNC_PATHS.filter(relPath => fs.existsSync(path.join(workspace, relPath))); if (generatedSyncPaths.length > 0) { + for (const relPath of generatedSyncPaths) { + const src = path.join(workspace, relPath); + const dest = path.join(repoDir, relPath); + fs.mkdirSync(path.dirname(dest), { recursive: true }); + fs.copyFileSync(src, dest); + } run(['add', ...generatedSyncPaths], repoDir); } diff --git a/app/git.test.js b/app/git.test.js index c519d15..a86cd34 100644 --- a/app/git.test.js +++ b/app/git.test.js @@ -95,6 +95,9 @@ describe('commitAndPush', () => { it('adds skill and entry files together with findings', async () => { const repoDir = path.join(workspace, 'repo'); + fs.mkdirSync(path.join(workspace, '.gitea/ai-review'), { recursive: true }); + fs.writeFileSync(path.join(workspace, '.gitea/ai-review/findings.json'), '[]\n'); + fs.writeFileSync(path.join(workspace, '.gitea/ai-review/exclusions.json'), '[]\n'); fs.mkdirSync(path.join(repoDir, '.gitea/ai-review'), { recursive: true }); fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/findings.json'), '[]\n'); fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/exclusions.json'), '[]\n');