Skip to content

Commit a29a127

Browse files
committed
update
1 parent 3ef8f03 commit a29a127

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

.github/workflows/ai_bot.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,58 +159,51 @@ jobs:
159159
return;
160160
}
161161
162-
// Get README from main branch
162+
// Get content from main branch
163163
const { data: readmeFile } = await octokit.repos.getContent({
164164
owner: event.repository.owner.login,
165165
repo: event.repository.name,
166166
path: 'README.md',
167-
ref: 'main'
167+
ref: 'main' // Get from main branch
168168
});
169169
170-
// Get CSV from main branch
171170
const { data: csvFile } = await octokit.repos.getContent({
172171
owner: event.repository.owner.login,
173172
repo: event.repository.name,
174173
path: 'prompts.csv',
175-
ref: 'main'
174+
ref: 'main' // Get from main branch
176175
});
177176
178-
// Prepare new README content
179-
let readmeContent = Buffer.from(readmeFile.content, 'base64').toString('utf-8');
177+
// Format the new prompt section
180178
const newSection = `\n## ${actName}\n${contributorInfo ? contributorInfo + '\n' : ''}\n> ${newPrompt}\n`;
181-
readmeContent += newSection;
182-
183-
// Prepare new CSV content
184-
let csvContent = Buffer.from(csvFile.content, 'base64').toString('utf-8');
185-
csvContent += `\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`;
186-
187-
// Update README in PR branch
179+
180+
// Update files in PR branch
188181
await octokit.repos.createOrUpdateFileContents({
189182
owner: event.repository.owner.login,
190183
repo: event.repository.name,
191184
path: 'README.md',
192185
message: `feat: Add "${actName}" to README`,
193-
content: Buffer.from(readmeContent).toString('base64'),
194-
branch: pr.head.ref,
186+
content: Buffer.from(Buffer.from(readmeFile.content, 'base64').toString('utf-8') + newSection).toString('base64'),
187+
branch: pr.head.ref, // Update PR's branch
195188
sha: readmeFile.sha
196189
});
197190
198-
// Update CSV in PR branch
199191
await octokit.repos.createOrUpdateFileContents({
200192
owner: event.repository.owner.login,
201193
repo: event.repository.name,
202194
path: 'prompts.csv',
203195
message: `feat: Add "${actName}" to prompts.csv`,
204-
content: Buffer.from(csvContent).toString('base64'),
205-
branch: pr.head.ref,
196+
content: Buffer.from(Buffer.from(csvFile.content, 'base64').toString('utf-8') +
197+
`\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`).toString('base64'),
198+
branch: pr.head.ref, // Update PR's branch
206199
sha: csvFile.sha
207200
});
208201
209202
await octokit.issues.createComment({
210203
owner: event.repository.owner.login,
211204
repo: event.repository.name,
212205
issue_number: issueNumber,
213-
body: `✨ Updated both files:\n1. Added "${actName}" to README.md\n2. Added the prompt to prompts.csv`
206+
body: `✨ Updated files in your PR using main branch as base:\n1. Added "${actName}" to README.md\n2. Added the prompt to prompts.csv`
214207
});
215208
216209
} catch (error) {

0 commit comments

Comments
 (0)