pull/787/head
f 2 weeks ago
parent 3ef8f03ca9
commit a29a12721a

@ -159,50 +159,43 @@ jobs:
return; return;
} }
// Get README from main branch // Get content from main branch
const { data: readmeFile } = await octokit.repos.getContent({ const { data: readmeFile } = await octokit.repos.getContent({
owner: event.repository.owner.login, owner: event.repository.owner.login,
repo: event.repository.name, repo: event.repository.name,
path: 'README.md', path: 'README.md',
ref: 'main' ref: 'main' // Get from main branch
}); });
// Get CSV from main branch
const { data: csvFile } = await octokit.repos.getContent({ const { data: csvFile } = await octokit.repos.getContent({
owner: event.repository.owner.login, owner: event.repository.owner.login,
repo: event.repository.name, repo: event.repository.name,
path: 'prompts.csv', path: 'prompts.csv',
ref: 'main' ref: 'main' // Get from main branch
}); });
// Prepare new README content // Format the new prompt section
let readmeContent = Buffer.from(readmeFile.content, 'base64').toString('utf-8');
const newSection = `\n## ${actName}\n${contributorInfo ? contributorInfo + '\n' : ''}\n> ${newPrompt}\n`; const newSection = `\n## ${actName}\n${contributorInfo ? contributorInfo + '\n' : ''}\n> ${newPrompt}\n`;
readmeContent += newSection;
// Update files in PR branch
// 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
await octokit.repos.createOrUpdateFileContents({ await octokit.repos.createOrUpdateFileContents({
owner: event.repository.owner.login, owner: event.repository.owner.login,
repo: event.repository.name, repo: event.repository.name,
path: 'README.md', path: 'README.md',
message: `feat: Add "${actName}" to README`, message: `feat: Add "${actName}" to README`,
content: Buffer.from(readmeContent).toString('base64'), content: Buffer.from(Buffer.from(readmeFile.content, 'base64').toString('utf-8') + newSection).toString('base64'),
branch: pr.head.ref, branch: pr.head.ref, // Update PR's branch
sha: readmeFile.sha sha: readmeFile.sha
}); });
// Update CSV in PR branch
await octokit.repos.createOrUpdateFileContents({ await octokit.repos.createOrUpdateFileContents({
owner: event.repository.owner.login, owner: event.repository.owner.login,
repo: event.repository.name, repo: event.repository.name,
path: 'prompts.csv', path: 'prompts.csv',
message: `feat: Add "${actName}" to prompts.csv`, message: `feat: Add "${actName}" to prompts.csv`,
content: Buffer.from(csvContent).toString('base64'), content: Buffer.from(Buffer.from(csvFile.content, 'base64').toString('utf-8') +
branch: pr.head.ref, `\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`).toString('base64'),
branch: pr.head.ref, // Update PR's branch
sha: csvFile.sha sha: csvFile.sha
}); });
@ -210,7 +203,7 @@ jobs:
owner: event.repository.owner.login, owner: event.repository.owner.login,
repo: event.repository.name, repo: event.repository.name,
issue_number: issueNumber, 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) { } catch (error) {

Loading…
Cancel
Save