From 3b0279fe5952fc4e6ac81605beac55aef1f37e40 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 6 Jan 2025 00:27:40 +0300 Subject: [PATCH] update --- .github/workflows/ai_bot.yml | 67 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ai_bot.yml b/.github/workflows/ai_bot.yml index 2ca91de..159af29 100644 --- a/.github/workflows/ai_bot.yml +++ b/.github/workflows/ai_bot.yml @@ -212,40 +212,43 @@ jobs: const csvContent = Buffer.from(csvFile.content, 'base64').toString('utf-8') + `\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`; - // Create a tree with both files - console.log('Creating Git tree...'); - console.log(`Using PR head SHA: ${pr.head.sha}`); - const { data: mainTree } = await octokit.git.getTree({ - owner: event.repository.owner.login, - repo: event.repository.name, - tree_sha: pr.head.sha, - recursive: true - }); + console.log('Creating Git operations in fork...'); + console.log(`Fork owner: ${pr.head.user.login}`); + console.log(`Fork repo: ${pr.head.repo.name}`); + console.log(`Branch: ${pr.head.ref}`); - // Create blobs for both files - console.log('Creating file blobs...'); + // Create blobs in fork + console.log('Creating file blobs in fork...'); const [readmeBlob, csvBlob] = await Promise.all([ octokit.git.createBlob({ - owner: event.repository.owner.login, - repo: event.repository.name, + owner: pr.head.user.login, + repo: pr.head.repo.name, content: Buffer.from(readmeContent).toString('base64'), encoding: 'base64' }), octokit.git.createBlob({ - owner: event.repository.owner.login, - repo: event.repository.name, + owner: pr.head.user.login, + repo: pr.head.repo.name, content: Buffer.from(csvContent).toString('base64'), encoding: 'base64' }) ]); - console.log('File blobs created'); + console.log('File blobs created in fork'); - // Create a new tree - console.log('Creating new tree with updated files...'); + // Get current tree from fork + const { data: currentTree } = await octokit.git.getTree({ + owner: pr.head.user.login, + repo: pr.head.repo.name, + tree_sha: pr.head.sha, + recursive: true + }); + + // Create a new tree in fork + console.log('Creating new tree in fork...'); const { data: newTree } = await octokit.git.createTree({ - owner: event.repository.owner.login, - repo: event.repository.name, - base_tree: mainTree.sha, + owner: pr.head.user.login, + repo: pr.head.repo.name, + base_tree: currentTree.sha, tree: [ { path: 'README.md', @@ -261,28 +264,28 @@ jobs: } ] }); - console.log('New tree created'); + console.log('New tree created in fork'); - // Create a commit - console.log('Creating commit...'); + // Create a commit in fork + console.log('Creating commit in fork...'); const { data: newCommit } = await octokit.git.createCommit({ - owner: event.repository.owner.login, - repo: event.repository.name, + owner: pr.head.user.login, + repo: pr.head.repo.name, message: `feat: Add "${actName}" to prompts`, tree: newTree.sha, parents: [pr.head.sha] }); - console.log(`New commit created: ${newCommit.sha}`); + console.log(`New commit created in fork: ${newCommit.sha}`); - // Update the reference - console.log(`Updating branch ${pr.head.ref}...`); + // Update the reference in fork + console.log(`Updating branch ${pr.head.ref} in fork...`); await octokit.git.updateRef({ - owner: event.repository.owner.login, - repo: event.repository.name, + owner: pr.head.user.login, + repo: pr.head.repo.name, ref: `heads/${pr.head.ref}`, sha: newCommit.sha }); - console.log('Branch updated successfully'); + console.log('Branch updated successfully in fork'); console.log('Adding success comment to PR...'); await octokit.issues.createComment({