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 @@