Skip to content

Commit e6292ec

Browse files
committed
finishing test
Signed-off-by: euclidstellar <euclidstellar@gmail.com>
1 parent ac3c7db commit e6292ec

7 files changed

Lines changed: 205 additions & 106 deletions

File tree

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# filepath: .gitignore
2+
# Binaries
3+
main
4+
code-review-agent
5+
6+
# Log files
7+
*.log
8+
ollama_serve.log
9+
10+
# IDE settings
11+
.vscode/

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
MIT License
3+
4+
Copyright (c) 2025 EuclidStellar
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,100 @@
11
# Smart AI Code Review Action
22

3-
AI-powered code review with **intelligent fallback system**:
4-
1. **GitHub Models** (primary, fastest)
5-
2. **Ollama** (fallback for rate limits)
6-
3. **Static review** (final fallback)
3+
[![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)
74

8-
## Features
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.
96

10-
**Smart Diff Prioritization** - Focuses on critical files
11-
**Multi-Model Support** - GitHub Models + Ollama fallback
12-
**Rate Limit Resilience** - Never fails due to API limits
13-
**Comprehensive Reviews** - Security, performance, best practices
14-
**Zero Configuration** - Works out of the box
7+
## Key Features
8+
9+
- 🧠 **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+
- 🤖 **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.
14+
- 🚀 **Zero-Setup Ready**: Works out of the box with the standard `GITHUB_TOKEN`.
15+
16+
## How It Works
17+
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.
1521

1622
## Usage
1723

24+
Create a workflow file (e.g., `.github/workflows/code-review.yml`) in your repository.
25+
26+
### Basic Example
27+
28+
This configuration uses the default settings and is the quickest way to get started.
29+
1830
```yaml
19-
- uses: euclidstellar/code-review-agent@v1
20-
with:
21-
github-token: ${{ secrets.GITHUB_TOKEN }}
22-
model: 'gpt-4o-mini'
23-
ollama-model: 'qwen2.5:7b' # Fallback model
31+
name: AI Code Review
32+
33+
on:
34+
pull_request:
35+
types: [opened, synchronize, reopened]
36+
37+
permissions:
38+
contents: read
39+
pull-requests: write
40+
41+
jobs:
42+
ai-review:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout Repository
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0 # Required to get the full git history for diffing
49+
50+
- name: Run Smart AI Code Review
51+
uses: euclidstellar/code-review-agent@v1 # Replace with your repo name
52+
with:
53+
github-token: ${{ secrets.GITHUB_TOKEN }}
2454
```
2555
26-
## Advanced Configuration
56+
### Advanced Example
57+
58+
This configuration customizes the models, temperature, and file patterns.
2759
2860
```yaml
29-
- uses: euclidstellar/code-review-agent@v1
30-
with:
31-
github-token: ${{ secrets.GITHUB_TOKEN }}
32-
model: 'gpt-4o-mini'
33-
max-tokens: 6700
34-
temperature: 0.1
35-
enable-ollama: true
36-
ollama-model: 'qwen2.5:7b'
37-
use-ollama-fallback: true
38-
ignore-patterns: '*.md,node_modules/**'
61+
name: Advanced AI Code Review
62+
63+
on:
64+
pull_request:
65+
types: [opened, synchronize, reopened]
66+
67+
permissions:
68+
contents: read
69+
pull-requests: write
70+
71+
jobs:
72+
ai-review:
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Checkout Repository
76+
uses: actions/checkout@v4
77+
with:
78+
fetch-depth: 0
79+
80+
- name: Run Smart AI Code Review
81+
uses: euclidstellar/code-review-agent@v1 # Replace with your repo name
82+
with:
83+
github-token: ${{ secrets.GITHUB_TOKEN }}
84+
model: 'gpt-4o'
85+
ollama-model: 'llama3:8b'
86+
temperature: 0.5
87+
ignore-patterns: '*.md,*.lock,dist/**'
3988
```
89+
90+
## Inputs
91+
92+
See the [`action.yml`](action.yml) file for a full list of inputs and their descriptions.
93+
94+
## Contributing
95+
96+
Contributions are welcome! Please open an issue or submit a pull request.
97+
98+
## License
99+
100+
This project is licensed under the [MIT License](LICENSE).

action.yml

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
11
name: 'Smart AI Code Review'
2-
description: 'AI-powered code review with intelligent diff prioritization and GitHub Models integration'
2+
description: 'Provides automated, AI-powered code reviews on pull requests with a resilient fallback system using GitHub Models and Ollama.'
33
author: 'EuclidStellar'
44

5+
branding:
6+
icon: 'git-pull-request'
7+
color: 'blue'
8+
59
inputs:
610
github-token:
7-
description: 'GitHub token with pull-requests:write and models:read permissions'
11+
description: 'Required. The GITHUB_TOKEN secret.'
812
required: true
913
model:
10-
description: 'AI model to use'
14+
description: 'The primary AI model to use (e.g., from GitHub Models).'
1115
required: false
1216
default: 'gpt-4o-mini'
17+
ollama-model:
18+
description: 'The Ollama model to use as a fallback if the primary model fails.'
19+
required: false
20+
default: 'qwen2:7b'
21+
use-ollama-fallback:
22+
description: 'Enable the Ollama fallback system.'
23+
required: false
24+
default: 'true'
1325
max-tokens:
14-
description: 'Maximum tokens for diff analysis'
26+
description: 'The token limit for smart diff prioritization. Diffs larger than this will be summarized.'
1527
required: false
16-
default: '6700'
28+
default: '8000'
1729
temperature:
18-
description: 'AI model temperature'
30+
description: 'The creativity/randomness of the AI model (0.0 to 2.0).'
1931
required: false
20-
default: '0.1'
32+
default: '0.2'
2133
ignore-patterns:
22-
description: 'Comma-separated patterns to ignore'
34+
description: 'Comma-separated list of file patterns to ignore (e.g., "*.md,dist/**").'
2335
required: false
24-
default: '*.md,node_modules/**'
36+
default: ''
2537
include-patterns:
26-
description: 'Comma-separated patterns to include'
27-
required: false
28-
# New Ollama inputs
29-
enable-ollama:
30-
description: 'Enable Ollama as fallback'
38+
description: 'Comma-separated list of file patterns to force-include (overrides ignore).'
3139
required: false
32-
default: 'true'
33-
ollama-model:
34-
description: 'Ollama model to use for fallback'
35-
required: false
36-
default: 'qwen2.5:7b'
37-
use-ollama-fallback:
38-
description: 'Use Ollama when GitHub Models fails'
39-
required: false
40-
default: 'true'
40+
default: ''
4141

4242
outputs:
4343
review-posted:
44-
description: 'Whether review was successfully posted'
44+
description: '"true" if a review comment was successfully posted, otherwise "false".'
4545
review-provider:
46-
description: 'Which provider was used (github-models, ollama, fallback)'
46+
description: 'The provider that generated the review (github-models, ollama, or static-fallback).'
4747

4848
runs:
4949
using: 'docker'
50-
image: 'Dockerfile'
51-
52-
branding:
53-
icon: 'git-pull-request'
54-
color: 'blue'
50+
image: 'Dockerfile'

examples/workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
with:
1818
github-token: ${{ secrets.GH_FINE_GRAINED_PAT }}
1919
model: 'gpt-4.1-nano'
20+
ollama-model: 'qwen2:7b'
2021
max-tokens: 6700
2122
temperature: 0.1
2223
ignore-patterns: '*.md,node_modules/**,dist/**'

internal/utils/logger.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
//"strings"
87
)
98

109
type Logger struct {
@@ -25,10 +24,17 @@ func (l *Logger) Error(format string, v ...interface{}) {
2524
l.Printf("ERROR: "+format, v...)
2625
}
2726

28-
func (l *Logger) Debug(format string, v ...interface{}) {
29-
l.Printf("DEBUG: "+format, v...)
30-
}
31-
3227
func (l *Logger) GitHubOutput(name, value string) {
28+
// Use the modern, recommended way to set outputs
29+
if githubOutput := os.Getenv("GITHUB_OUTPUT"); githubOutput != "" {
30+
f, err := os.OpenFile(githubOutput, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
31+
if err == nil {
32+
defer f.Close()
33+
if _, err := f.WriteString(fmt.Sprintf("%s=%s\n", name, value)); err == nil {
34+
return
35+
}
36+
}
37+
}
38+
// Fallback for local testing or older environments
3339
fmt.Printf("::set-output name=%s::%s\n", name, value)
3440
}

0 commit comments

Comments
 (0)