feat: add dedicated issue close/reopen and PR review tools

This commit is contained in:
2026-05-12 13:11:12 +02:00
parent bb2fd20992
commit e8fa47a57d
5 changed files with 546 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
import { tool } from "@opencode-ai/plugin";
import { $ } from "bun";
export const prApprove = tool({
description: "Approve a pull request with an optional comment",
args: {
prNumber: tool.schema.number().describe("Pull request number"),
comment: tool.schema
.string()
.optional()
.describe("Optional review comment"),
},
async execute(args) {
try {
let cmd = $`tea pr review --output json --approve ${args.prNumber}`;
if (args.comment) {
cmd = cmd`--message ${args.comment}`;
}
const result = await cmd.text();
return {
success: true,
message: `Successfully approved PR #${args.prNumber}`,
prNumber: args.prNumber,
output: result,
};
} catch (error: any) {
return {
error: "Failed to approve PR",
message: error.message,
stderr: error.stderr?.toString(),
prNumber: args.prNumber,
};
}
},
});
export const prRequestChanges = tool({
description: "Request changes on a pull request with a comment",
args: {
prNumber: tool.schema.number().describe("Pull request number"),
comment: tool.schema.string().describe("Review comment explaining requested changes"),
},
async execute(args) {
try {
const cmd = $`tea pr review --output json --request-changes ${args.prNumber} --message ${args.comment}`;
const result = await cmd.text();
return {
success: true,
message: `Successfully requested changes on PR #${args.prNumber}`,
prNumber: args.prNumber,
output: result,
};
} catch (error: any) {
return {
error: "Failed to request changes on PR",
message: error.message,
stderr: error.stderr?.toString(),
prNumber: args.prNumber,
};
}
},
});
export const prRequestChangesWithFeedback = tool({
description: "Request changes on a pull request with detailed feedback",
args: {
prNumber: tool.schema.number().describe("Pull request number"),
feedback: tool.schema.string().describe("Detailed feedback explaining requested changes"),
sections: tool.schema
.array(tool.schema.string())
.optional()
.describe("Specific sections requiring changes (e.g., ['authentication', 'tests'])"),
},
async execute(args) {
try {
let feedbackText = args.feedback;
if (args.sections && args.sections.length > 0) {
feedbackText += "\n\nKey areas requiring attention:\n";
for (const section of args.sections) {
feedbackText += `- ${section}\n`;
}
}
const cmd = $`tea pr review --output json --request-changes ${args.prNumber} --message ${feedbackText}`;
const result = await cmd.text();
return {
success: true,
message: `Successfully requested changes on PR #${args.prNumber}`,
prNumber: args.prNumber,
feedback: feedbackText,
output: result,
};
} catch (error: any) {
return {
error: "Failed to request changes on PR",
message: error.message,
stderr: error.stderr?.toString(),
prNumber: args.prNumber,
};
}
},
});