This commit is contained in:
2026-03-11 16:53:01 +08:00
parent 460979b577
commit a551cbe79d
4 changed files with 49 additions and 21 deletions

View File

@@ -3,6 +3,13 @@ import { app } from './index.ts';
import { useIssueEnv, useCommentEnv, useRepoInfoEnv } from '../src/index.ts'
import { pick } from 'es-toolkit';
const writeToProcess = (message: string) => {
if (process.send) {
process.send(message);
} else {
console.log(message);
}
}
const main = async () => {
const repoInfoEnv = useRepoInfoEnv();
const commentEnv = useCommentEnv();
@@ -10,10 +17,17 @@ 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 isComment = !!commentEnv.commentId;
if (!isComment && !issueLabels.includes('Run')) {
writeToProcess('当前 Issue 不包含 Run 标签,跳过执行');
process.exit(0);
}
const messages = [
{
role: 'system',
content: `你是一个智能的代码助手, 根据用户提供的上下文信息,提供有用的建议和帮助, 如果用户的要求和执行工具不一致请说出你不能这么做。并把最后的结果提交一个评论到对应的issue中。用户提供的上下文信息如下`
content: `你是一个智能的代码助手, 根据用户提供的上下文信息,提供有用的建议和帮助, 如果用户的要求和执行工具不一致请说出你不能这么做。并把最后的结果提交一个评论到对应的issue中,提交的内容必须不能包含 @ 提及。用户提供的上下文信息如下:`
},
{
role: 'system',
@@ -33,10 +47,11 @@ const main = async () => {
}, { appId: app.appId })
if (result.code === 200) {
let _message = result.data.message || []
console.log('执行完成', JSON.stringify(_message, null, 2))
writeToProcess('执行完成')
writeToProcess(JSON.stringify(_message, null, 2))
process.exit(0)
} else {
console.log(result.message || '执行错误')
writeToProcess(result.message || '执行错误')
process.exit(1)
}
}