Skip to content

Commit 17562b0

Browse files
Merge pull request #5 from EuclidStellar/keployAI
feat: KeployAI code review action
2 parents e10b728 + 7fe49f5 commit 17562b0

File tree

11 files changed

+177
-615
lines changed

11 files changed

+177
-615
lines changed

.github/workflows/ai-review.yml

Lines changed: 0 additions & 468 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
name: Build and Push Test Image
3+
4+
on:
5+
push:
6+
branches:
7+
- keployAI
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-push-test-image:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Log in to the GitHub Container Registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.repository_owner }}
29+
password: ${{ secrets.GB_TOKEN }}
30+
31+
# FIX: Use metadata-action to generate valid, lowercase tags automatically.
32+
- name: Extract metadata (tags, labels) for Docker
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
# This will be automatically converted to lowercase: ghcr.io/euclidstellar/code-review-agent
37+
images: ghcr.io/${{ github.repository }}
38+
# For this workflow, we only want to generate a single tag: 'test'
39+
tags: type=raw,value=test
40+
41+
- name: Build and push multi-platform image
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
push: true
46+
platforms: linux/amd64,linux/arm64
47+
# Use the valid tags generated by the metadata-action step
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/test.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# name: Test Code Review Action
2+
3+
# on:
4+
# pull_request:
5+
# types: [opened, synchronize, reopened]
6+
# workflow_dispatch: # Allows manual triggering
7+
8+
# permissions:
9+
# contents: read
10+
# pull-requests: write
11+
12+
# jobs:
13+
# test-action:
14+
# runs-on: ubuntu-latest
15+
# steps:
16+
# - name: Checkout Repository
17+
# uses: actions/checkout@v4
18+
# with:
19+
# fetch-depth: 0 # Required for git diff operations
20+
21+
# - name: Test Local Action
22+
# uses: ./ # Now this will work
23+
# with:
24+
# github-token: ${{ secrets.GH_SECRET }}
25+
# model: 'gpt-4o-mini' # Fix: Use available model
26+
# max-tokens: 6700
27+
# temperature: 0.1
28+
# ignore-patterns: '*.md,node_modules/**'
29+
130
name: Test Code Review Action
231

332
on:
@@ -18,11 +47,16 @@ jobs:
1847
with:
1948
fetch-depth: 0 # Required for git diff operations
2049

21-
- name: Test Local Action
22-
uses: ./ # Now this will work
50+
- name: Test Pre-built Action from GHCR
51+
# FIX: Instead of building locally with 'uses: ./', we now pull the pre-built
52+
# image from the GitHub Container Registry, just like a real user would.
53+
uses: docker://ghcr.io/euclidstellar/testtt:test
54+
#uses: ./
2355
with:
56+
# BEST PRACTICE: Use the built-in GITHUB_TOKEN. It's more secure
57+
# and avoids potential formatting issues with custom secrets.
2458
github-token: ${{ secrets.GH_SECRET }}
25-
model: 'gpt-4o-mini' # Fix: Use available model
59+
model: 'gpt-4o-mini'
2660
max-tokens: 6700
2761
temperature: 0.1
2862
ignore-patterns: '*.md,node_modules/**'

.golangci.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
# Smart AI Code Review Action
1+
# KeployAI Code Review Action
22

33
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Smart%20AI%20Code%20Review-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=github)](https://github.com/marketplace/actions/smart-ai-code-review-action)
44

5-
An intelligent GitHub Action that provides automated, AI-powered code reviews on your pull requests. It features a resilient fallback system, using **GitHub Models** as the primary provider and **Ollama** for local models as a backup, ensuring you always get a review.
5+
An intelligent GitHub Action that provides automated, AI-powered code reviews on your pull requests. It features a resilient fallback system, visual summaries, and smart diff analysis to deliver professional-grade feedback.
66

77
## Key Features
88

9+
- 📊 **Visual PR Summary**: Each review starts with a Mermaid sequence diagram summarizing the changes.
910
- 🧠 **Intelligent Diff Analysis**: Automatically prioritizes critical files in large pull requests to stay within token limits.
10-
- 🔄 **Resilient Fallback System**: If GitHub Models API fails or is rate-limited, it seamlessly switches to a self-hosted Ollama model.
11+
- 🔄 **Resilient Fallback System**: If the primary GitHub Models API fails, it seamlessly switches to a self-hosted Ollama model.
1112
- 🤖 **Multi-Provider Support**: Natively supports GitHub Models and any model compatible with Ollama.
12-
-**Comprehensive Reviews**: Analyzes code for security vulnerabilities, performance bottlenecks, best practices, and style.
13-
- ⚙️ **Highly Configurable**: Fine-tune models, ignore specific files, and adjust AI parameters.
13+
-**Comprehensive Reviews**: Analyzes code for security, performance, best practices, and style.
1414
- 🚀 **Zero-Setup Ready**: Works out of the box with the standard `GITHUB_TOKEN`.
1515

16-
## How It Works
16+
## Usage
1717

18-
1. **GitHub Models First**: The action first attempts to generate a high-quality review using the specified GitHub Model (e.g., `gpt-4o-mini`).
19-
2. **Ollama Fallback**: If the primary API call fails (due to errors, rate limits, etc.), the action automatically installs Ollama inside the runner, pulls your specified model (e.g., `qwen2:7b`), and generates the review.
20-
3. **Static Fallback**: If both AI providers fail, a structured error report is posted, ensuring you are never left without feedback.
18+
### Workflow Permissions
2119

22-
## Usage
20+
This action requires the following permissions in your workflow file to read code and post comments.
2321

24-
Create a workflow file (e.g., `.github/workflows/code-review.yml`) in your repository.
22+
```yaml
23+
permissions:
24+
contents: read
25+
pull-requests: write
26+
```
2527
2628
### Basic Example
2729
28-
This configuration uses the default settings and is the quickest way to get started.
30+
This configuration uses the default settings and is the quickest way to get started. Create a file like `.github/workflows/code-review.yml`:
2931

3032
```yaml
31-
name: AI Code Review
33+
name: KeployAI Code Review
3234
3335
on:
3436
pull_request:
@@ -48,17 +50,17 @@ jobs:
4850
fetch-depth: 0 # Required to get the full git history for diffing
4951
5052
- name: Run Smart AI Code Review
51-
uses: euclidstellar/code-review-agent@v1 # Replace with your repo name
53+
uses: euclidstellar/code-review-agent@v1
5254
with:
53-
github-token: ${{ secrets.GITHUB_TOKEN }}
55+
github-token: ${{ secrets.GH_TOKEN }}
5456
```
5557

5658
### Advanced Example
5759

5860
This configuration customizes the models, temperature, and file patterns.
5961

6062
```yaml
61-
name: Advanced AI Code Review
63+
name: Advanced KeployAI Code Review
6264
6365
on:
6466
pull_request:
@@ -78,12 +80,12 @@ jobs:
7880
fetch-depth: 0
7981
8082
- name: Run Smart AI Code Review
81-
uses: euclidstellar/code-review-agent@v1 # Replace with your repo name
83+
uses: euclidstellar/code-review-agent@v1
8284
with:
83-
github-token: ${{ secrets.GITHUB_TOKEN }}
85+
github-token: ${{ secrets.GH_TOKEN }}
8486
model: 'gpt-4o'
85-
ollama-model: 'llama3:8b'
86-
temperature: 0.5
87+
ollama-model: 'gemma3n:e4b'
88+
temperature: 0.1
8789
ignore-patterns: '*.md,*.lock,dist/**'
8890
```
8991

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ outputs:
4747

4848
runs:
4949
using: 'docker'
50-
image: 'Dockerfile'
50+
image: 'docker://ghcr.io/euclidstellar/code-review-agent:v1'

entrypoint.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

internal/reviewer/github_models.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ func (c *GitHubModelsClient) buildPrompt(diff string) string {
118118
119119
## Code Review Summary
120120
Brief overview of changes and overall quality assessment.
121+
**Include a small Mermaid sequence diagram summarizing the PR.**
122+
123+
Example Mermaid Diagram:
124+
`+"```mermaid\n"+`sequenceDiagram
125+
Mermaid code the diagram should show the concise logical changes in the codebase between old code and new code.
126+
`+"```\n"+`
121127
122128
## Critical Issues
123129
List high-priority issues requiring immediate attention with clear impact explanations.
@@ -155,8 +161,6 @@ Present corrected versions with detailed explanations.
155161
## Testing Recommendations
156162
Specific test suggestions for the changes.
157163
158-
## Documentation Notes
159-
Documentation improvements or additions needed.
160164
161165
---
162166

internal/reviewer/ollama_reviewer.go

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,68 @@ func (c *OllamaClient) GenerateReview(diff string) (string, error) {
154154
}
155155

156156
func (c *OllamaClient) buildPrompt(diff string) string {
157-
return fmt.Sprintf(`You are an expert code reviewer. Your task is to analyze the provided git diff, identify potential issues, suggest improvements, and summarize the key changes. Pay close attention to:
158-
- Readability and code style adherence
159-
- Potential bugs or edge cases
160-
- Security vulnerabilities
161-
- Performance implications
162-
- Adherence to best practices
163-
- Missing tests or documentation
164-
165-
Here is the git diff:
166-
` + "```diff\n" + diff + "\n```" + `
167-
168-
Provide your review in a concise and actionable manner, using markdown formatting including code blocks where necessary. Start with a brief summary, then list specific findings and suggestions. Output only the review comments for the code changes. Do not include your reasoning or thinking process.
169-
End with a summary of the most critical issues found.`)
157+
return fmt.Sprintf(`You are an expert code reviewer. Analyze the provided git diff and deliver a comprehensive, professional code review following the exact structure below.
158+
159+
### FORMATTING REQUIREMENTS:
160+
- Use proper markdown with clear sections
161+
- Include specific code snippets with language tags
162+
- Provide concrete examples for improvements
163+
- Use tables for structured findings
164+
- Reference specific file locations
165+
- Professional tone, no emojis
166+
167+
### REQUIRED STRUCTURE:
168+
169+
## Code Review Summary
170+
Brief overview of changes and overall quality assessment.
171+
**Include a small Mermaid sequence diagram summarizing the PR.**
172+
173+
Example Mermaid Diagram:
174+
`+"```mermaid\n"+`sequenceDiagram
175+
Mermaid code the diagram should show the concise logical changes in the codebase between old code and new code.
176+
`+"```\n"+`
177+
178+
## Critical Issues
179+
List high-priority issues requiring immediate attention with clear impact explanations.
180+
181+
## Code Quality Analysis
182+
183+
### Security Concerns
184+
Identify security issues with code examples and explanations.
185+
186+
### Performance Issues
187+
Highlight performance problems with optimization suggestions.
188+
189+
### Best Practices
190+
Note coding standard violations and improvement opportunities.
191+
192+
## Detailed Findings
193+
194+
<details>
195+
<summary>📂 Click to expand issue table</summary>
196+
197+
| Category | Issue Description | Location (File:Line) | Severity | Recommendation |
198+
|----------|-------------------|----------------------|----------|----------------|
199+
| Example | Description here | file.js:42 | High | Specific fix |
200+
201+
</details>
202+
203+
## Code Examples
204+
205+
### Current Implementation
206+
Show problematic code snippets with explanations of why they're issues.
207+
208+
### Suggested Improvements
209+
Present corrected versions with detailed explanations.
210+
211+
## Testing Recommendations
212+
Specific test suggestions for the changes.
213+
214+
215+
---
216+
217+
Here is the diff to review:
218+
` + "```diff\n" + diff + "\n```")
170219
}
171220

172221
func (c *OllamaClient) cleanResponse(response string) string {

internal/utils/token_counter.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)