-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add AI code review workflows (ChatGPT, Claude, Kimi) #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
da58400
95b2ba4
4e1e1be
dce2a32
9bd4a16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "attribution": { | ||
| "commit": "", | ||
| "pr": "" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: PR Review - ChatGPT | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| pull_request_review_comment: | ||
| types: [created] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| chatgpt-review: | ||
| name: ChatGPT Code Review | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: ChatGPT Code Review | ||
| uses: anc95/ChatGPT-CodeReview@main | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
| with: | ||
| openai_engine: gpt-4o | ||
| language: en | ||
| review_comment_lgtm: false | ||
| max_tokens: 4096 | ||
| prompt: | | ||
| You are a senior code reviewer for spawned, a Rust actor framework with support for both async (tokio) and thread-based backends. | ||
|
|
||
| Review this PR focusing on: | ||
| - Code correctness and potential bugs | ||
| - Concurrency issues (race conditions, deadlocks, data races) | ||
| - Performance implications | ||
| - Rust best practices and idiomatic patterns | ||
| - Memory safety and proper error handling | ||
| - Code readability and maintainability | ||
|
|
||
| Actor framework-specific considerations: | ||
| - Actor lifecycle management (init, shutdown, cancellation) | ||
| - Message passing correctness and ordering | ||
| - Proper use of CancellationToken and graceful shutdown | ||
| - Thread safety and synchronization primitives | ||
| - Timer and interval handling | ||
|
|
||
| Be concise and specific. Provide line references when suggesting changes. | ||
| If the code looks good, acknowledge it briefly. | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: PR Review - Claude | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| pull_request_review_comment: | ||
| types: [created] | ||
| issue_comment: | ||
| types: [created] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| issues: write | ||
| id-token: write | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| claude-review: | ||
| name: Claude Code Review | ||
| if: | | ||
| github.event_name == 'pull_request' || | ||
| (github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Claude Code Review | ||
| uses: anthropics/claude-code-action@beta | ||
| with: | ||
| anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} | ||
| model: claude-sonnet-4-20250514 | ||
| trigger_phrase: "@claude" | ||
| timeout_minutes: 30 | ||
| direct_prompt: | | ||
| You are a senior code reviewer for spawned, a Rust actor framework with support for both async (tokio) and thread-based backends. | ||
|
|
||
| Review this PR focusing on: | ||
| - Code correctness and potential bugs | ||
| - Concurrency issues (race conditions, deadlocks, data races) | ||
| - Performance implications | ||
| - Rust best practices and idiomatic patterns | ||
| - Memory safety and proper error handling | ||
| - Code readability and maintainability | ||
|
|
||
| Actor framework-specific considerations: | ||
| - Actor lifecycle management (init, shutdown, cancellation) | ||
| - Message passing correctness and ordering | ||
| - Proper use of CancellationToken and graceful shutdown | ||
| - Thread safety and synchronization primitives | ||
| - Timer and interval handling | ||
|
|
||
| Be concise and specific. Provide line references when suggesting changes. | ||
| If the code looks good, acknowledge it briefly. | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| name: PR Review - Kimi | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change made at the modified line uses
Overall, while the code change is small and functionally correct, I'd recommend adding error handling related to file existence and perhaps adding a comment explaining why Please address these suggestions before merging. |
||
| 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) | ||
ElFantasma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # 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 | ||
ElFantasma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $REVIEW_CONTENT | ||
|
|
||
| --- | ||
| *Automated review by Kimi (Moonshot AI)*" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review Comments
ConclusionThese points indicate there are potential bugs and risks associated with the current implementation that need to be addressed before merging. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code patch introduces a JSON structure, but it lacks crucial information in the 'commit' and 'pr' fields, which are currently empty strings. This suggests that it might be part of a larger code management strategy, and information is missing that could hinder traceability. Additionally:
Validation: There are no checks or validations on the values that should be stored in the 'commit' and 'pr' fields. They should ideally contain valid commit hashes and pull request identifiers, respectively. Adding validation can prevent potential bugs later on.
Documentation: There's no indication of how this structure will be utilized in the surrounding codebase. A comment or documentation would be beneficial to clarify its intended purpose.
Version Control: If this JSON structure is expected to be modified frequently, consider versioning it within the structure for better manageability in the future.
As it stands, the patch should be revised to address these potential issues before merging.