Skip to content

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

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

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

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: 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 }}
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)
# Build the request body
REQUEST_BODY=$(jq -n \
--arg diff "$DIFF_CONTENT" \
--arg title "$PR_TITLE" \
'{
"model": "moonshot-v1-128k",
"messages": [
{
"role": "system",
"content": "You are a senior code reviewer for spawned, a Rust actor framework with support for both async (tokio) and thread-based backends."
},
{
"role": "user",
"content": ("PR Title: " + $title + "\n\nReview this PR focusing on:\n- Code correctness and potential bugs\n- Concurrency issues (race conditions, deadlocks, data races)\n- Performance implications\n- Rust best practices and idiomatic patterns\n- Memory safety and proper error handling\n- Code readability and maintainability\n\nActor framework-specific considerations:\n- Actor lifecycle management (init, shutdown, cancellation)\n- Message passing correctness and ordering\n- Proper use of CancellationToken and graceful shutdown\n- Thread safety and synchronization primitives\n- Timer and interval handling\n\nBe concise and specific. Provide line references when suggesting changes.\nIf the code looks good, acknowledge it briefly.\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: |
REVIEW_CONTENT=$(cat kimi_review.txt)
gh pr comment ${{ github.event.pull_request.number }} --body "## Kimi AI Code Review
$REVIEW_CONTENT
---
*Automated review by Kimi (Moonshot AI)*"