添加获取单个 Issue 的功能,更新相关类型和环境变量
This commit is contained in:
34
agent/npc.ts
34
agent/npc.ts
@@ -1,6 +1,6 @@
|
||||
import { app } from './index.ts';
|
||||
|
||||
import { useIssueEnv, useCommentEnv, useRepoInfoEnv } from '../src/index.ts'
|
||||
import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
|
||||
import { pick } from 'es-toolkit';
|
||||
|
||||
const writeToProcess = (message: string) => {
|
||||
@@ -10,6 +10,32 @@ const writeToProcess = (message: string) => {
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
const getIssuesLabels = async () => {
|
||||
const issueEnv = useIssueEnv();
|
||||
const repoInfoEnv = useRepoInfoEnv();
|
||||
const issueId = issueEnv.issueId;
|
||||
const repoSlug = repoInfoEnv.repoSlug;
|
||||
if (!issueId || !repoSlug) {
|
||||
return [];
|
||||
}
|
||||
const res = await app.run({
|
||||
path: 'cnb',
|
||||
key: 'getIssue',
|
||||
payload: {
|
||||
repo: repoSlug,
|
||||
issueNumber: issueId
|
||||
}
|
||||
});
|
||||
if (res.code === 200) {
|
||||
const issueData = res.data as any;
|
||||
const labels = issueData.labels || [];
|
||||
return labels as IssueLabel[];
|
||||
}
|
||||
console.error('获取 Issue 详情失败', res);
|
||||
return []
|
||||
|
||||
}
|
||||
|
||||
const main = async () => {
|
||||
const repoInfoEnv = useRepoInfoEnv();
|
||||
const commentEnv = useCommentEnv();
|
||||
@@ -17,7 +43,7 @@ const main = async () => {
|
||||
const pickCommentEnv = pick(commentEnv, ['commentId', 'commentIdLabel']);
|
||||
const pickIssueEnv = pick(issueEnv, ['issueId', 'issueIdLabel', 'issueIid', 'issueIidLabel', 'issueTitle', 'issueTitleLabel', 'issueDescription', 'issueDescriptionLabel']);
|
||||
const pickRepoInfoEnv = pick(repoInfoEnv, ['repoId', 'repoIdLabel', 'repoName', 'repoNameLabel', 'repoSlug', 'repoSlugLabel']);
|
||||
const issueLabels = issueEnv.issueLabels || [];
|
||||
// const issueLabels = issueEnv.issueLabels || [];
|
||||
const isComment = !!commentEnv.commentId;
|
||||
const envList = [
|
||||
...Object.entries(pickRepoInfoEnv).map(([key, value]) => `${key}: ${value}`),
|
||||
@@ -25,8 +51,10 @@ const main = async () => {
|
||||
...Object.entries(pickCommentEnv).map(([key, value]) => `${key}: ${value}`),
|
||||
]
|
||||
writeToProcess('当前环境变量:');
|
||||
const issueLabels = await getIssuesLabels();
|
||||
const issueLabelsNames = issueLabels.map(label => label.name) || [];
|
||||
envList.forEach(item => writeToProcess(item));
|
||||
if (!isComment && !issueLabels.includes('Run')) {
|
||||
if (!isComment && !issueLabelsNames.includes('Run')) {
|
||||
writeToProcess('当前 Issue 不包含 Run 标签,跳过执行');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -49,4 +49,37 @@ app.route({
|
||||
|
||||
const res = await cnb.issue.getList(repo, params);
|
||||
ctx.forward(res);
|
||||
}).addTo(app);
|
||||
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'getIssue',
|
||||
description: '获取 单个 Issue',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'getIssue',
|
||||
title: '获取 单个 Issue',
|
||||
args: {
|
||||
repo: tool.schema.string().optional().describe('代码仓库名称, 如 my-user/my-repo'),
|
||||
issueNumber: tool.schema.union([tool.schema.string(), tool.schema.number()]).describe('Issue 编号'),
|
||||
},
|
||||
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;
|
||||
|
||||
if (!repo) {
|
||||
ctx.throw(400, '缺少参数 repo');
|
||||
}
|
||||
if (!issueNumber) {
|
||||
ctx.throw(400, '缺少参数 issueNumber');
|
||||
}
|
||||
|
||||
const res = await cnb.issue.getItem(repo, issueNumber);
|
||||
ctx.forward(res);
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user