fix pr list
This commit is contained in:
@@ -1,68 +1,73 @@
|
|||||||
import { tool } from "@opencode-ai/plugin"
|
import { tool } from "@opencode-ai/plugin";
|
||||||
import { $ } from "bun"
|
import { $ } from "bun";
|
||||||
|
|
||||||
export const prList = tool({
|
export const prList = tool({
|
||||||
description: "List pull requests with their current state, useful for tracking work in progress or finding PRs to review",
|
description:
|
||||||
|
"List pull requests with their current state, useful for tracking work in progress or finding PRs to review",
|
||||||
args: {
|
args: {
|
||||||
state: tool.schema.enum(["open", "closed", "all"]).default("open").describe("Filter by state"),
|
state: tool.schema
|
||||||
author: tool.schema.string().optional().describe("Filter by author username"),
|
.enum(["open", "closed", "all"])
|
||||||
|
.default("open")
|
||||||
|
.describe("Filter by state"),
|
||||||
limit: tool.schema.number().default(30).describe("Number of PRs to return"),
|
limit: tool.schema.number().default(30).describe("Number of PRs to return"),
|
||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
try {
|
try {
|
||||||
const cmd = args.author
|
const cmd = $`tea pr list --output json --state ${args.state} --limit ${args.limit ?? 30}`;
|
||||||
? $`tea pr list --output json --state ${args.state} --author ${args.author} --limit ${args.limit}`
|
|
||||||
: $`tea pr list --output json --state ${args.state} --limit ${args.limit}`
|
const result = await cmd.text();
|
||||||
|
return result;
|
||||||
const result = await cmd.text()
|
|
||||||
return result
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
error: "Failed to list pull requests",
|
error: "Failed to list pull requests",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stderr: error.stderr?.toString(),
|
stderr: error.stderr?.toString(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
export const prCreate = tool({
|
export const prCreate = tool({
|
||||||
description: "Create a new pull request with title, body, base branch, head branch, and optional labels and milestone",
|
description:
|
||||||
|
"Create a new pull request with title, body, base branch, head branch, and optional labels and milestone",
|
||||||
args: {
|
args: {
|
||||||
title: tool.schema.string().describe("PR title"),
|
title: tool.schema.string().describe("PR title"),
|
||||||
body: tool.schema.string().optional().describe("PR description/body"),
|
body: tool.schema.string().optional().describe("PR description/body"),
|
||||||
base: tool.schema.string().describe("Base branch name"),
|
base: tool.schema.string().describe("Base branch name"),
|
||||||
head: tool.schema.string().describe("Head branch name"),
|
head: tool.schema.string().describe("Head branch name"),
|
||||||
labels: tool.schema.array(tool.schema.string()).optional().describe("Comma-separated list of label names"),
|
labels: tool.schema
|
||||||
|
.array(tool.schema.string())
|
||||||
|
.optional()
|
||||||
|
.describe("Comma-separated list of label names"),
|
||||||
milestone: tool.schema.string().optional().describe("Milestone name"),
|
milestone: tool.schema.string().optional().describe("Milestone name"),
|
||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
try {
|
try {
|
||||||
let cmd = $`tea pr create --output json --title ${args.title} --base ${args.base} --head ${args.head}`
|
let cmd = $`tea pr create --output json --title ${args.title} --base ${args.base} --head ${args.head}`;
|
||||||
|
|
||||||
if (args.body) {
|
if (args.body) {
|
||||||
cmd = cmd`--body ${args.body}`
|
cmd = cmd`--body ${args.body}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.labels) {
|
if (args.labels) {
|
||||||
cmd = cmd`--labels ${args.labels.join(",")}`
|
cmd = cmd`--labels ${args.labels.join(",")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.milestone) {
|
if (args.milestone) {
|
||||||
cmd = cmd`--milestone ${args.milestone}`
|
cmd = cmd`--milestone ${args.milestone}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await cmd.text()
|
const result = await cmd.text();
|
||||||
return result
|
return result;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
error: "Failed to create pull request",
|
error: "Failed to create pull request",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stderr: error.stderr?.toString(),
|
stderr: error.stderr?.toString(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
export const prCheckout = tool({
|
export const prCheckout = tool({
|
||||||
description: "Checkout a pull request locally to work on it",
|
description: "Checkout a pull request locally to work on it",
|
||||||
@@ -71,20 +76,20 @@ export const prCheckout = tool({
|
|||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
try {
|
try {
|
||||||
const result = await $`tea pr checkout ${args.prNumber}`.text()
|
const result = await $`tea pr checkout ${args.prNumber}`.text();
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: result,
|
message: result,
|
||||||
}
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
error: "Failed to checkout pull request",
|
error: "Failed to checkout pull request",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stderr: error.stderr?.toString(),
|
stderr: error.stderr?.toString(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
export const prMerge = tool({
|
export const prMerge = tool({
|
||||||
description: "Merge a pull request using rebase merge style",
|
description: "Merge a pull request using rebase merge style",
|
||||||
@@ -95,43 +100,45 @@ export const prMerge = tool({
|
|||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
try {
|
try {
|
||||||
let cmd = $`tea pr merge --style rebase --output json ${args.prNumber}`
|
let cmd = $`tea pr merge --style rebase --output json ${args.prNumber}`;
|
||||||
|
|
||||||
if (args.title) {
|
if (args.title) {
|
||||||
cmd = cmd`--title ${args.title}`
|
cmd = cmd`--title ${args.title}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.message) {
|
if (args.message) {
|
||||||
cmd = cmd`--message ${args.message}`
|
cmd = cmd`--message ${args.message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await cmd.text()
|
const result = await cmd.text();
|
||||||
return result
|
return result;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
error: "Failed to merge pull request",
|
error: "Failed to merge pull request",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stderr: error.stderr?.toString(),
|
stderr: error.stderr?.toString(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
export const prDetails = tool({
|
export const prDetails = tool({
|
||||||
description: "Get detailed information about a specific pull request including review status and comments",
|
description:
|
||||||
|
"Get detailed information about a specific pull request including review status and comments",
|
||||||
args: {
|
args: {
|
||||||
prNumber: tool.schema.number().describe("Pull request number"),
|
prNumber: tool.schema.number().describe("Pull request number"),
|
||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
try {
|
try {
|
||||||
const result = await $`tea pr ${args.prNumber} --output json --comments`.text()
|
const result =
|
||||||
return result
|
await $`tea pr ${args.prNumber} --output json --comments`.text();
|
||||||
|
return result;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
error: "Failed to get pull request details",
|
error: "Failed to get pull request details",
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stderr: error.stderr?.toString(),
|
stderr: error.stderr?.toString(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user