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.
This commit is contained in:
66
agent/routes/build/docker.ts
Normal file
66
agent/routes/build/docker.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { execSync } from 'child_process';
|
||||
import { app, notCNBCheck } from '../../app.ts'
|
||||
import { z } from 'zod'
|
||||
import { title } from 'process';
|
||||
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'docker-sync',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tag: ['opencode'],
|
||||
skill: 'cnb-docker-sync',
|
||||
title: 'CNB Docker 镜像同步',
|
||||
args: {
|
||||
image: z.string().describe('Docker 同步的具体的镜像名称.'),
|
||||
toVersion: z.string().optional().describe('修改后的版本号.'),
|
||||
}
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { image, toVersion } = ctx.args;
|
||||
notCNBCheck(ctx);
|
||||
if (!image) {
|
||||
ctx.body = {
|
||||
message: '请提供 Docker 镜像名称.',
|
||||
data: null,
|
||||
}
|
||||
return;
|
||||
}
|
||||
const config = {
|
||||
registry: 'docker.cnb.cool/kevisual/dev-env',
|
||||
dockers: [{ image, toVersion }]
|
||||
}
|
||||
// docker tag ghcr.io/esm-dev/esm.sh:v137 docker.cnb.cool/kevisual/dev-env/esm.sh:v137
|
||||
// docker push docker.cnb.cool/kevisual/dev-env/esm.sh:v137
|
||||
const run = async () => {
|
||||
const dockers = config.dockers;
|
||||
for (const { image, toVersion } of dockers) {
|
||||
const imageName = image.split(':')[0].split('/').slice(-1)[0]
|
||||
const tag = image.split(':')[1]
|
||||
const newImage = `${config.registry}/${imageName}:${toVersion || tag}`
|
||||
// console.log(`docker tag ${image} ${newImage}`)
|
||||
// console.log(`docker push ${newImage}`)
|
||||
const shell = `docker pull ${image} && docker tag ${image} ${newImage} && docker push ${newImage}`
|
||||
console.log(shell)
|
||||
|
||||
console.log('\n-------------new---------------------------------\n')
|
||||
console.log(`${newImage}`)
|
||||
console.log('\n--------------------------------------------------\n')
|
||||
try {
|
||||
execSync(shell, { stdio: 'inherit' })
|
||||
} catch (error) {
|
||||
console.error(`Error: ${error}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
run().then(() => {
|
||||
// TODO: 通知用户同步完成
|
||||
});;
|
||||
ctx.body = {
|
||||
message: 'Docker 镜像同步任务中,请稍后在目标仓库查看.',
|
||||
data: {
|
||||
registry: config.registry,
|
||||
dockers: config.dockers,
|
||||
}
|
||||
}
|
||||
}).addTo(app);
|
||||
1
agent/routes/build/index.ts
Normal file
1
agent/routes/build/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
import './docker.ts'
|
||||
@@ -9,6 +9,7 @@ import './issues/index.ts'
|
||||
import './cnb-board/index.ts';
|
||||
import './share/index.ts';
|
||||
import './cnb-manager/index.ts';
|
||||
import './build/index.ts';
|
||||
|
||||
/**
|
||||
* 验证上下文中的 App ID 是否与指定的 App ID 匹配
|
||||
|
||||
167
agent/routes/issues/comments.ts
Normal file
167
agent/routes/issues/comments.ts
Normal file
@@ -0,0 +1,167 @@
|
||||
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);
|
||||
@@ -1,2 +1,3 @@
|
||||
import './list.ts'
|
||||
import './issue.ts'
|
||||
import './issue.ts'
|
||||
import './comments.ts'
|
||||
@@ -14,7 +14,7 @@ app.route({
|
||||
skill: 'list-issues',
|
||||
title: '查询 Issue 列表',
|
||||
args: {
|
||||
repo: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
|
||||
repo: tool.schema.string().optional().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('问题标签,多个用逗号分隔'),
|
||||
@@ -27,7 +27,7 @@ app.route({
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const cnb = await cnbManager.getContext(ctx);
|
||||
const repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
|
||||
let repo = ctx.query?.repo || useKey('CNB_REPO_SLUG_LOWERCASE');
|
||||
const state = ctx.query?.state;
|
||||
const keyword = ctx.query?.keyword;
|
||||
const labels = ctx.query?.labels;
|
||||
|
||||
Reference in New Issue
Block a user