From a1641e96ccde507a28f56c8083a8e37bd379da6c Mon Sep 17 00:00:00 2001 From: Dawn <2439646234@qq.com> Date: Sat, 28 Dec 2024 17:26:25 +0800 Subject: [PATCH] =?UTF-8?q?perf(component):=20:zap:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=99=9A=E6=8B=9F=E5=88=97=E8=A1=A8=E5=8A=A0=E8=BD=BD=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E5=8A=9F=E8=83=BD=20(#129)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf(component): :zap: 优化虚拟列表加载更多功能 * fix(github): :bug: 修复PR copilot 工作流问题 * fix(github): :bug: 修复PR copilot工作流没安装pnpm问题 * fix(action): :bug: 修改pr分析的机器人为通义千问 * fix(action): :bug: 修复配置通义千问配置问题 * fix(action): :bug: 修复api调用方式 --- .github/workflows/pr-chatbot-review.yml | 91 ++++++++++++++++++++ src/components/common/VirtualList.vue | 46 +++++++--- src/components/rightBox/chatBox/ChatMain.vue | 19 ++-- src/typings/components.d.ts | 2 + 4 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/pr-chatbot-review.yml diff --git a/.github/workflows/pr-chatbot-review.yml b/.github/workflows/pr-chatbot-review.yml new file mode 100644 index 00000000..33fdc220 --- /dev/null +++ b/.github/workflows/pr-chatbot-review.yml @@ -0,0 +1,91 @@ +name: PR Review Bot + +on: + pull_request: + types: [opened, synchronize] + +permissions: + contents: read + pull-requests: write + +jobs: + review: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get PR diff + id: diff + run: | + git fetch origin ${{ github.event.pull_request.base.sha }} + DIFF=$(git diff ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) + echo "DIFF<> $GITHUB_ENV + echo "$DIFF" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 9 + run_install: false + + - name: Install OpenAI SDK + run: | + pnpm config set registry https://registry.npmmirror.com/ + pnpm add openai + + - name: Analyze PR + id: analyze + uses: actions/github-script@v7 + env: + DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }} + with: + script: | + const OpenAI = require('openai'); + + const openai = new OpenAI({ + apiKey: process.env.DASHSCOPE_API_KEY, + baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1" + }); + + const diff = process.env.DIFF; + + try { + const completion = await openai.chat.completions.create({ + model: "qwen-plus", + messages: [{ + role: "system", + content: "你是一个代码审查助手,请用中文分析以下代码变更。" + }, { + role: "user", + content: `请分析以下代码变更并总结主要改动:\n\n${diff}` + }], + temperature: 0.7, + max_tokens: 1000 + }); + + const analysis = completion.choices[0].message.content; + core.setOutput('analysis', analysis); + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `## PR 代码分析 + + ${analysis} + + --- + *这是由通义千问 AI 自动生成的 PR 分析,仅供参考。*` + }); + } catch (error) { + core.setFailed(`分析失败: ${error.message}`); + } \ No newline at end of file diff --git a/src/components/common/VirtualList.vue b/src/components/common/VirtualList.vue index aaf1bee4..a720fdac 100644 --- a/src/components/common/VirtualList.vue +++ b/src/components/common/VirtualList.vue @@ -1,5 +1,9 @@