Skip to content

Commit eb35fda

Browse files
author
remote-swe-app[bot]
committed
Add test script for GitHub PR comments tools
1 parent 23cb87c commit eb35fda

File tree

1 file changed

+72
-0
lines changed
  • worker/src/agent/tools/github-pr-comments

1 file changed

+72
-0
lines changed

worker/src/agent/tools/github-pr-comments/index.ts

+72
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,75 @@ export const replyPRCommentTool: ToolDefinition<z.infer<typeof replyPRCommentSch
9292
},
9393
}),
9494
};
95+
96+
// Test script code - only runs when file is executed directly
97+
if (require.main === module) {
98+
const args = process.argv.slice(2);
99+
const command = args[0]?.toLowerCase();
100+
101+
const printUsage = () => {
102+
console.log('Usage:');
103+
console.log(' npx tsx worker/src/agent/tools/github-pr-comments/index.ts get <owner> <repo> <pullRequestId>');
104+
console.log(' npx tsx worker/src/agent/tools/github-pr-comments/index.ts reply <owner> <repo> <pullRequestId> <commentId> <body>');
105+
console.log('\nExamples:');
106+
console.log(' npx tsx worker/src/agent/tools/github-pr-comments/index.ts get aws-samples remote-swe-agents 32');
107+
console.log(' npx tsx worker/src/agent/tools/github-pr-comments/index.ts reply aws-samples remote-swe-agents 32 1234567890 "Thanks for the feedback!"');
108+
};
109+
110+
const runTest = async () => {
111+
try {
112+
switch (command) {
113+
case 'get':
114+
if (args.length < 4) {
115+
console.error('Error: Not enough arguments for get command');
116+
printUsage();
117+
process.exit(1);
118+
}
119+
120+
const [owner, repo, pullRequestId] = args.slice(1);
121+
console.log(`Getting comments for PR #${pullRequestId} in ${owner}/${repo}...`);
122+
123+
const getResult = await getPRCommentsHandler({ owner, repo, pullRequestId });
124+
console.log('Result:');
125+
console.log(getResult);
126+
break;
127+
128+
case 'reply':
129+
if (args.length < 6) {
130+
console.error('Error: Not enough arguments for reply command');
131+
printUsage();
132+
process.exit(1);
133+
}
134+
135+
const [replyOwner, replyRepo, replyPullRequestId, commentId, ...bodyParts] = args.slice(1);
136+
const body = bodyParts.join(' ');
137+
138+
console.log(`Replying to comment ${commentId} in PR #${replyPullRequestId} of ${replyOwner}/${replyRepo}...`);
139+
console.log(`Message: "${body}"`);
140+
141+
const replyResult = await replyPRCommentHandler({
142+
owner: replyOwner,
143+
repo: replyRepo,
144+
pullRequestId: replyPullRequestId,
145+
commentId,
146+
body
147+
});
148+
149+
console.log('Result:');
150+
console.log(replyResult);
151+
break;
152+
153+
default:
154+
console.error('Error: Unknown command. Use "get" or "reply"');
155+
printUsage();
156+
process.exit(1);
157+
}
158+
} catch (error) {
159+
console.error('Error:', error);
160+
process.exit(1);
161+
}
162+
};
163+
164+
// Run the test
165+
runTest();
166+
}

0 commit comments

Comments
 (0)