Files
cnb/agent/routes/issues/comments.ts
xiongxiao 38ee73e48f feat: update package version to 0.0.42 and add CNB version fetching functionality
- Updated package version in package.json from 0.0.40 to 0.0.42.
- Added getCNBVersion function to fetch CNB version information from the API.
- Enhanced Issue class with methods for managing comments (list, create, get, update).
- Introduced new NPC and comment environment hooks for better context management.
- Implemented Docker image synchronization route for CNB.
- Added tests for version fetching and issue comment functionalities.
2026-03-10 03:45:02 +08:00

168 lines
5.1 KiB
TypeScript

import { createSkill, tool } from '@kevisual/router';
import { app, cnbManager } from '../../app.ts';
import { useKey } from '@kevisual/context';
// 查询 Issue 评论列表
app.route({
path: 'cnb',
key: 'list-issue-comments',
description: '查询 Issue 评论列表, 参数 repo, issueNumber, page, page_size',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'list-issue-comments',
title: '查询 Issue 评论列表',
args: {
repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
issueNumber: tool.schema.number().describe('Issue 编号'),
page: tool.schema.number().optional().describe('分页页码,默认: 1'),
page_size: tool.schema.number().optional().describe('分页每页大小,默认: 30'),
},
summary: '查询 Issue 评论列表',
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
const issueNumber = ctx.query?.issueNumber;
const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
if (!repo) {
ctx.throw(400, '缺少参数 repo');
}
if (!issueNumber) {
ctx.throw(400, '缺少参数 issueNumber');
}
const params: Record<string, any> = {};
if (page) params.page = page;
if (page_size) params.page_size = page_size;
const res = await cnb.issue.getCommentList(repo, issueNumber, params);
ctx.forward(res);
}).addTo(app);
// 创建 Issue 评论
app.route({
path: 'cnb',
key: 'create-issue-comment',
description: '创建 Issue 评论, 参数 repo, issueNumber, body',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'create-issue-comment',
title: '创建 Issue 评论',
args: {
repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
issueNumber: tool.schema.number().describe('Issue 编号'),
body: tool.schema.string().describe('评论内容'),
},
summary: '创建 Issue 评论',
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
const issueNumber = ctx.query?.issueNumber;
const body = ctx.query?.body;
if (!repo) {
ctx.throw(400, '缺少参数 repo');
}
if (!issueNumber) {
ctx.throw(400, '缺少参数 issueNumber');
}
if (!body) {
ctx.throw(400, '缺少参数 body');
}
const res = await cnb.issue.createComment(repo, issueNumber, body);
ctx.forward(res);
}).addTo(app);
// 获取 Issue 指定评论
app.route({
path: 'cnb',
key: 'get-issue-comment',
description: '获取 Issue 指定评论, 参数 repo, issueNumber, commentId',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'get-issue-comment',
title: '获取 Issue 评论',
args: {
repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
issueNumber: tool.schema.number().describe('Issue 编号'),
commentId: tool.schema.number().describe('评论 ID'),
},
summary: '获取 Issue 评论',
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
const issueNumber = ctx.query?.issueNumber;
const commentId = ctx.query?.commentId;
if (!repo) {
ctx.throw(400, '缺少参数 repo');
}
if (!issueNumber) {
ctx.throw(400, '缺少参数 issueNumber');
}
if (!commentId) {
ctx.throw(400, '缺少参数 commentId');
}
const res = await cnb.issue.getComment(repo, issueNumber, commentId);
ctx.forward(res);
}).addTo(app);
// 修改 Issue 评论
app.route({
path: 'cnb',
key: 'update-issue-comment',
description: '修改 Issue 评论, 参数 repo, issueNumber, commentId, body',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'update-issue-comment',
title: '修改 Issue 评论',
args: {
repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
issueNumber: tool.schema.number().describe('Issue 编号'),
commentId: tool.schema.number().describe('评论 ID'),
body: tool.schema.string().describe('评论内容'),
},
summary: '修改 Issue 评论',
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
const issueNumber = ctx.query?.issueNumber;
const commentId = ctx.query?.commentId;
const body = ctx.query?.body;
if (!repo) {
ctx.throw(400, '缺少参数 repo');
}
if (!issueNumber) {
ctx.throw(400, '缺少参数 issueNumber');
}
if (!commentId) {
ctx.throw(400, '缺少参数 commentId');
}
if (!body) {
ctx.throw(400, '缺少参数 body');
}
const res = await cnb.issue.updateComment(repo, issueNumber, commentId, body);
ctx.forward(res);
}).addTo(app);