Skip to content

feat: add AI code review workflows (ChatGPT, Claude, Kimi) (#143) #6

feat: add AI code review workflows (ChatGPT, Claude, Kimi) (#143)

feat: add AI code review workflows (ChatGPT, Claude, Kimi) (#143) #6

name: PR Review - Kimi
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
kimi-review:
name: Kimi Code Review
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read review prompt
id: prompt
run: |
PROMPT=$(cat .github/prompts/pr_review.md)
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "$PROMPT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Get PR diff
id: diff
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr diff ${{ github.event.pull_request.number }} > pr_diff.txt
# Truncate if too large (Kimi has context limits)
head -c 100000 pr_diff.txt > pr_diff_truncated.txt
- name: Kimi Code Review
id: kimi_review
env:
KIMI_API_KEY: ${{ secrets.KIMI_API_KEY }}
PR_TITLE: ${{ github.event.pull_request.title }}
REVIEW_PROMPT: ${{ steps.prompt.outputs.content }}
run: |
if [ -z "$KIMI_API_KEY" ]; then
echo "Error: KIMI_API_KEY secret is not set" > kimi_review.txt
exit 0
fi
DIFF_CONTENT=$(cat pr_diff_truncated.txt | jq -Rs .)
# Build the request body
REQUEST_BODY=$(jq -n \
--arg diff "$DIFF_CONTENT" \
--arg title "$PR_TITLE" \
--arg prompt "$REVIEW_PROMPT" \
'{
"model": "moonshot-v1-128k",
"messages": [
{
"role": "system",
"content": $prompt
},
{
"role": "user",
"content": ("PR Title: " + $title + "\n\nDiff:\n" + $diff)
}
],
"temperature": 0.3,
"max_tokens": 4096
}')
# Try the API call
HTTP_RESPONSE=$(curl -s -w "\n%{http_code}" https://api.moonshot.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $KIMI_API_KEY" \
-d "$REQUEST_BODY")
HTTP_CODE=$(echo "$HTTP_RESPONSE" | tail -n1)
RESPONSE=$(echo "$HTTP_RESPONSE" | sed '$d')
if [ "$HTTP_CODE" != "200" ]; then
echo "API Error (HTTP $HTTP_CODE): $RESPONSE" > kimi_review.txt
else
# Check for API errors in response
ERROR=$(echo "$RESPONSE" | jq -r '.error.message // empty')
if [ -n "$ERROR" ]; then
echo "API Error: $ERROR" > kimi_review.txt
else
REVIEW=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // "Error: Unexpected API response"')
echo "$REVIEW" > kimi_review.txt
fi
fi
- name: Post review comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }} --body-file kimi_review.txt --body-prefix "## Kimi AI Code Review
" --body-suffix "

Check failure on line 105 in .github/workflows/pr_review_kimi.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/pr_review_kimi.yaml

Invalid workflow file

You have an error in your yaml syntax on line 105
---
*Automated review by Kimi (Moonshot AI)*"
$REVIEW_CONTENT
---
*Automated review by Kimi (Moonshot AI)*"