diff --git a/agent/routes/issues/issue.ts b/agent/routes/issues/issue.ts index 3aabb81..c1016d5 100644 --- a/agent/routes/issues/issue.ts +++ b/agent/routes/issues/issue.ts @@ -1,5 +1,6 @@ import { createSkill, tool } from '@kevisual/router'; import { app, cnb } from '../../app.ts'; +import { IssueItem } from '@/index.ts'; // 创建cnb issue, 仓库为 kevisual/kevisual 标题为 "自动化测试创建issue", 内容为 "这是通过API创建的issue,用于测试目的", body: "这是通过API创建的issue,用于测试目的" app.route({ @@ -55,7 +56,7 @@ app.route({ tags: ['opencode'], ...createSkill({ skill: 'complete-issue', - title: '完成 Issue', + title: '完成 CNB的任务Issue', args: { repo: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'), issueNumber: tool.schema.union([tool.schema.string(), tool.schema.number()]).describe('Issue 编号'), @@ -72,9 +73,10 @@ app.route({ if (!repo || !issueNumber) { ctx.throw(400, '缺少参数 repo 或 issueNumber'); } - - const res = await cnb.issue.updateIssue(repo, issueNumber, { - state: state, - }); + const iss: Partial = { state: state }; + if (iss.state === 'closed') { + iss.state_reason = 'completed'; + } + const res = await cnb.issue.updateIssue(repo, issueNumber, iss); ctx.forward(res); }).addTo(app); diff --git a/agent/routes/issues/list.ts b/agent/routes/issues/list.ts index 25466ca..773ae89 100644 --- a/agent/routes/issues/list.ts +++ b/agent/routes/issues/list.ts @@ -1,3 +1,50 @@ import { createSkill, tool } from '@kevisual/router'; import { app, cnb } from '../../app.ts'; +// 查询 Issue 列表 repo是 kevisual/kevisual +app.route({ + path: 'cnb', + key: 'list-issues', + description: '查询 Issue 列表, 参数 repo, state, keyword, labels, page, page_size 等', + middleware: ['auth'], + metadata: { + tags: ['opencode'], + ...createSkill({ + skill: 'list-issues', + title: '查询 Issue 列表', + args: { + repo: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'), + state: tool.schema.string().optional().describe('Issue 状态:open 或 closed'), + keyword: tool.schema.string().optional().describe('问题搜索关键词'), + labels: tool.schema.string().optional().describe('问题标签,多个用逗号分隔'), + page: tool.schema.number().optional().describe('分页页码,默认: 1'), + page_size: tool.schema.number().optional().describe('分页每页大小,默认: 30'), + order_by: tool.schema.string().optional().describe('排序方式,如 created_at, -updated_at'), + }, + summary: '查询 Issue 列表', + }) + } +}).define(async (ctx) => { + const repo = ctx.query?.repo; + const state = ctx.query?.state; + const keyword = ctx.query?.keyword; + const labels = ctx.query?.labels; + const page = ctx.query?.page ? Number(ctx.query.page) : undefined; + const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined; + const order_by = ctx.query?.order_by; + + if (!repo) { + ctx.throw(400, '缺少参数 repo'); + } + + const params: Record = {}; + if (state) params.state = state; + if (keyword) params.keyword = keyword; + if (labels) params.labels = labels; + if (page) params.page = page; + if (page_size) params.page_size = page_size; + if (order_by) params.order_by = order_by; + + const res = await cnb.issue.getList(repo, params); + ctx.forward(res); +}).addTo(app); \ No newline at end of file diff --git a/package.json b/package.json index dc3e7fd..d7865b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cnb", - "version": "0.0.4", + "version": "0.0.6", "description": "", "main": "index.js", "scripts": {