From a29a12721a129f47d173b9b0d061ffd2f414ccf9 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 6 Jan 2025 00:10:51 +0300 Subject: [PATCH] update --- .github/workflows/ai_bot.yml | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ai_bot.yml b/.github/workflows/ai_bot.yml index 57227df..51b2f08 100644 --- a/.github/workflows/ai_bot.yml +++ b/.github/workflows/ai_bot.yml @@ -159,50 +159,43 @@ jobs: return; } - // Get README from main branch + // Get content from main branch const { data: readmeFile } = await octokit.repos.getContent({ owner: event.repository.owner.login, repo: event.repository.name, path: 'README.md', - ref: 'main' + ref: 'main' // Get from main branch }); - // Get CSV from main branch const { data: csvFile } = await octokit.repos.getContent({ owner: event.repository.owner.login, repo: event.repository.name, path: 'prompts.csv', - ref: 'main' + ref: 'main' // Get from main branch }); - // Prepare new README content - let readmeContent = Buffer.from(readmeFile.content, 'base64').toString('utf-8'); + // Format the new prompt section const newSection = `\n## ${actName}\n${contributorInfo ? contributorInfo + '\n' : ''}\n> ${newPrompt}\n`; - readmeContent += newSection; - - // Prepare new CSV content - let csvContent = Buffer.from(csvFile.content, 'base64').toString('utf-8'); - csvContent += `\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`; - - // Update README in PR branch + + // Update files in PR branch await octokit.repos.createOrUpdateFileContents({ owner: event.repository.owner.login, repo: event.repository.name, path: 'README.md', message: `feat: Add "${actName}" to README`, - content: Buffer.from(readmeContent).toString('base64'), - branch: pr.head.ref, + content: Buffer.from(Buffer.from(readmeFile.content, 'base64').toString('utf-8') + newSection).toString('base64'), + branch: pr.head.ref, // Update PR's branch sha: readmeFile.sha }); - // Update CSV in PR branch await octokit.repos.createOrUpdateFileContents({ owner: event.repository.owner.login, repo: event.repository.name, path: 'prompts.csv', message: `feat: Add "${actName}" to prompts.csv`, - content: Buffer.from(csvContent).toString('base64'), - branch: pr.head.ref, + content: Buffer.from(Buffer.from(csvFile.content, 'base64').toString('utf-8') + + `\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`).toString('base64'), + branch: pr.head.ref, // Update PR's branch sha: csvFile.sha }); @@ -210,7 +203,7 @@ jobs: owner: event.repository.owner.login, repo: event.repository.name, issue_number: issueNumber, - body: `✨ Updated both files:\n1. Added "${actName}" to README.md\n2. Added the prompt to prompts.csv` + body: `✨ Updated files in your PR using main branch as base:\n1. Added "${actName}" to README.md\n2. Added the prompt to prompts.csv` }); } catch (error) {