Skip to content

fix: code review by my shared public key #11

fix: code review by my shared public key

fix: code review by my shared public key #11

Workflow file for this run

name: DeepSeek API Request and PR Comment
permissions:
contents: read
pull-requests: write # 需要写权限才能在 PR 上发表评论
on:
pull_request_target: # 触发目标仓库的 PR 操作
types: [opened, reopened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout the target branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Checkout the source branch
run: |
git fetch origin ${{ github.event.pull_request.head.ref }}
git checkout ${{ github.event.pull_request.head.ref }}
- name: Get pull request diff
id: pr_diff
run: |
# 获取 PR 的 diff 信息
PR_DIFF=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files")
echo "$PR_DIFF" > pr_diff.json
echo "diff_file=pr_diff.json" >> $GITHUB_ENV
- name: Send request to DeepSeek API for Code Review
id: deepseek_response
run: |
PR_DIFF_CONTENT=$(cat ${{ env.diff_file }})
response=$(curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-d5f21dec47a244d5a899a26ba813ed2e" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "我将提供给你一段github pull request的file diff。请你扮演一位专业的开源社区开发者,帮我进行code review。\n\n[[代码审核原则]]\n[代码质量]\n1. 该修改是否有必要,是否相比旧代码有改进或添加了新功能?\n2. 是否有逻辑错误或潜在的运行时错误?\n3. 是否有与其他代码部分的兼容性问题,会不会破坏与修改无关的现有逻辑?\n4. 是否有可以优化的代码结构或逻辑,是否有更简洁或更高效的方式来实现相同功能?\n5. 是否有潜在的性能问题?\n[安全性]\n1. 是否有敏感信息泄露的风险(如硬编码的密钥、密码等)?\n2. 是否有可能运行来路不明的外部代码?\n\n[[结果返回格式]]\n如果发现任何问题或改进建议,请分点详细列出并说明;如果没有问题,请直接输出“LGTM”表示通过。${PR_DIFF_CONTENT}"},
{"role": "user", "content": "${PR_DIFF_CONTENT}"}
],
"stream": false
}')
echo "$response" > response.json
echo "$response" | jq .
- name: Post comment on PR with review result
run: |
COMMENT=$(jq -r '.choices[0].message.content' response.json)
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"body": "'"$COMMENT"'",
"note": "Code Review by DeepSeek"
}' \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"