update
This commit is contained in:
parent
cd05562974
commit
3b0279fe59
|
@ -212,40 +212,43 @@ jobs:
|
||||||
const csvContent = Buffer.from(csvFile.content, 'base64').toString('utf-8') +
|
const csvContent = Buffer.from(csvFile.content, 'base64').toString('utf-8') +
|
||||||
`\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`;
|
`\n"${actName.replace(/"/g, '""')}","${newPrompt.replace(/"/g, '""')}"`;
|
||||||
|
|
||||||
// Create a tree with both files
|
console.log('Creating Git operations in fork...');
|
||||||
console.log('Creating Git tree...');
|
console.log(`Fork owner: ${pr.head.user.login}`);
|
||||||
console.log(`Using PR head SHA: ${pr.head.sha}`);
|
console.log(`Fork repo: ${pr.head.repo.name}`);
|
||||||
const { data: mainTree } = await octokit.git.getTree({
|
console.log(`Branch: ${pr.head.ref}`);
|
||||||
owner: event.repository.owner.login,
|
|
||||||
repo: event.repository.name,
|
|
||||||
tree_sha: pr.head.sha,
|
|
||||||
recursive: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create blobs for both files
|
// Create blobs in fork
|
||||||
console.log('Creating file blobs...');
|
console.log('Creating file blobs in fork...');
|
||||||
const [readmeBlob, csvBlob] = await Promise.all([
|
const [readmeBlob, csvBlob] = await Promise.all([
|
||||||
octokit.git.createBlob({
|
octokit.git.createBlob({
|
||||||
owner: event.repository.owner.login,
|
owner: pr.head.user.login,
|
||||||
repo: event.repository.name,
|
repo: pr.head.repo.name,
|
||||||
content: Buffer.from(readmeContent).toString('base64'),
|
content: Buffer.from(readmeContent).toString('base64'),
|
||||||
encoding: 'base64'
|
encoding: 'base64'
|
||||||
}),
|
}),
|
||||||
octokit.git.createBlob({
|
octokit.git.createBlob({
|
||||||
owner: event.repository.owner.login,
|
owner: pr.head.user.login,
|
||||||
repo: event.repository.name,
|
repo: pr.head.repo.name,
|
||||||
content: Buffer.from(csvContent).toString('base64'),
|
content: Buffer.from(csvContent).toString('base64'),
|
||||||
encoding: 'base64'
|
encoding: 'base64'
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
console.log('File blobs created');
|
console.log('File blobs created in fork');
|
||||||
|
|
||||||
// Create a new tree
|
// Get current tree from fork
|
||||||
console.log('Creating new tree with updated files...');
|
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({
|
const { data: newTree } = await octokit.git.createTree({
|
||||||
owner: event.repository.owner.login,
|
owner: pr.head.user.login,
|
||||||
repo: event.repository.name,
|
repo: pr.head.repo.name,
|
||||||
base_tree: mainTree.sha,
|
base_tree: currentTree.sha,
|
||||||
tree: [
|
tree: [
|
||||||
{
|
{
|
||||||
path: 'README.md',
|
path: 'README.md',
|
||||||
|
@ -261,28 +264,28 @@ jobs:
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
console.log('New tree created');
|
console.log('New tree created in fork');
|
||||||
|
|
||||||
// Create a commit
|
// Create a commit in fork
|
||||||
console.log('Creating commit...');
|
console.log('Creating commit in fork...');
|
||||||
const { data: newCommit } = await octokit.git.createCommit({
|
const { data: newCommit } = await octokit.git.createCommit({
|
||||||
owner: event.repository.owner.login,
|
owner: pr.head.user.login,
|
||||||
repo: event.repository.name,
|
repo: pr.head.repo.name,
|
||||||
message: `feat: Add "${actName}" to prompts`,
|
message: `feat: Add "${actName}" to prompts`,
|
||||||
tree: newTree.sha,
|
tree: newTree.sha,
|
||||||
parents: [pr.head.sha]
|
parents: [pr.head.sha]
|
||||||
});
|
});
|
||||||
console.log(`New commit created: ${newCommit.sha}`);
|
console.log(`New commit created in fork: ${newCommit.sha}`);
|
||||||
|
|
||||||
// Update the reference
|
// Update the reference in fork
|
||||||
console.log(`Updating branch ${pr.head.ref}...`);
|
console.log(`Updating branch ${pr.head.ref} in fork...`);
|
||||||
await octokit.git.updateRef({
|
await octokit.git.updateRef({
|
||||||
owner: event.repository.owner.login,
|
owner: pr.head.user.login,
|
||||||
repo: event.repository.name,
|
repo: pr.head.repo.name,
|
||||||
ref: `heads/${pr.head.ref}`,
|
ref: `heads/${pr.head.ref}`,
|
||||||
sha: newCommit.sha
|
sha: newCommit.sha
|
||||||
});
|
});
|
||||||
console.log('Branch updated successfully');
|
console.log('Branch updated successfully in fork');
|
||||||
|
|
||||||
console.log('Adding success comment to PR...');
|
console.log('Adding success comment to PR...');
|
||||||
await octokit.issues.createComment({
|
await octokit.issues.createComment({
|
||||||
|
|
Loading…
Reference in New Issue