添加仓库管理功能,包括创建、删除和列出代码仓库,更新依赖安装逻辑,修复环境变量配置
This commit is contained in:
@@ -1,108 +1,2 @@
|
||||
import { app, cnb } from '../../app.ts';
|
||||
import { createSkill, Skill } from '@kevisual/router'
|
||||
import { tool } from "@opencode-ai/plugin/tool"
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'create-repo',
|
||||
description: '创建代码仓库, 参数name, visibility, description',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'create-repo',
|
||||
title: '创建代码仓库',
|
||||
args: {
|
||||
name: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
|
||||
visibility: tool.schema.string().describe('代码仓库可见性, public 或 private').default('public'),
|
||||
description: tool.schema.string().describe('代码仓库描述'),
|
||||
},
|
||||
summary: '创建一个新的代码仓库',
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const name = ctx.query?.name;
|
||||
const visibility = ctx.query?.visibility ?? 'public';
|
||||
const description = ctx.query?.description ?? '';
|
||||
|
||||
if (!name) {
|
||||
ctx.throw(400, '缺少参数 name');
|
||||
}
|
||||
try {
|
||||
|
||||
const res = await cnb.repo.createRepo({
|
||||
name,
|
||||
visibility,
|
||||
description,
|
||||
});
|
||||
ctx.forward(res);
|
||||
} catch (error) {
|
||||
ctx.code = 200
|
||||
ctx.body = { content: 'JS仓库可能已存在' }
|
||||
}
|
||||
}).addTo(app);
|
||||
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'create-repo-file',
|
||||
description: '在代码仓库中创建文件, repoName, filePath, content, encoding',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'create-repo-file',
|
||||
title: '在代码仓库中创建文件',
|
||||
summary: `在代码仓库中创建文件, encoding 可选,默认 raw`,
|
||||
args: {
|
||||
repoName: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
|
||||
filePath: tool.schema.string().describe('文件路径, 如 src/index.ts'),
|
||||
content: tool.schema.string().describe('文本的字符串的内容'),
|
||||
encoding: tool.schema.string().describe('编码方式,如 raw').optional(),
|
||||
},
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const repoName = ctx.query?.repoName;
|
||||
const filePath = ctx.query?.filePath;
|
||||
const content = ctx.query?.content;
|
||||
const encoding = ctx.query?.encoding ?? 'raw';
|
||||
|
||||
if (!repoName || !filePath || !content) {
|
||||
ctx.throw(400, '缺少参数 repoName, filePath 或 content');
|
||||
}
|
||||
|
||||
const res = await cnb.repo.createCommit(repoName, {
|
||||
message: `添加文件 ${filePath} 通过 API `,
|
||||
files: [
|
||||
{ path: filePath, content, encoding },
|
||||
],
|
||||
});
|
||||
ctx.forward(res);
|
||||
}).addTo(app);
|
||||
|
||||
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'delete-repo',
|
||||
description: '删除代码仓库, 参数name',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'delete-repo',
|
||||
title: '删除代码仓库',
|
||||
args: {
|
||||
name: tool.schema.string().describe('代码仓库名称'),
|
||||
},
|
||||
summary: '删除一个代码仓库',
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const name = ctx.query?.name;
|
||||
|
||||
if (!name) {
|
||||
ctx.throw(400, '缺少参数 name');
|
||||
}
|
||||
|
||||
const res = await cnb.repo.deleteRepo(name);
|
||||
ctx.forward(res);
|
||||
}).addTo(app);
|
||||
import './list.ts'
|
||||
import './repo.ts'
|
||||
Reference in New Issue
Block a user