Quick Start¶
Configura AI Code Reviewer in 5 minuti su GitHub o GitLab.
Passo 1: Scegli il Provider LLM e Ottieni una Chiave API¶
AI Reviewer supporta diversi provider LLM. Scegline uno (o usa entrambi per il fallback):
- Vai su Google AI Studio
- Accedi con il tuo account Google
- Clicca "Get API key" โ "Create API key"
- Copia la chiave (inizia con
AIza...)
Tier gratuito
L'API Gemini ha un tier gratuito: 15 richieste al minuto, sufficiente per la maggior parte dei team di 4-8 sviluppatori.
- Vai su Mistral Console
- Registrati o accedi
- Vai su API Keys โ Create new key
- Copia la chiave (inizia con
sk-...)
Tier gratuito
Mistral offre un tier gratuito per la sperimentazione. Dopo la registrazione, ricevi crediti API gratuiti per provare tutti i modelli. Controlla Mistral Pricing per i limiti attuali.
Codestral gratuito
Codestral (un modello specializzato per il codice) ha un proprio livello gratuito con endpoint e chiave separati:
- Vai su codestral.mistral.ai
- Genera una chiave API Codestral
- Imposta
AI_REVIEWER_MISTRAL_API_URL=https://codestral.mistral.ai - Imposta
AI_REVIEWER_MISTRAL_MODEL=codestral-latest
Questa chiave funziona solo con codestral-latest sull'endpoint Codestral.
Ottieni entrambe le chiavi seguendo le istruzioni qui sopra. Questo ti offre:
- Mistral come modello primario (es.
mistral-large-latest) - Google Gemini come fallback automatico se Mistral non e disponibile
Questa e la configurazione piu affidabile per l'uso in produzione.
Salva la chiave
Le chiavi API vengono mostrate una sola volta. Salvale in un posto sicuro.
Passo 2: Aggiungi i Secret nel Repository¶
Percorso: Repository โ Settings โ Secrets and variables โ Actions โ New repository secret
| Name | Value |
|---|---|
AI_REVIEWER_GOOGLE_API_KEY |
La tua chiave Gemini (AIza...) |
| Name | Value |
|---|---|
AI_REVIEWER_MISTRAL_API_KEY |
La tua chiave Mistral (sk-...) |
| Name | Value |
|---|---|
AI_REVIEWER_MISTRAL_API_KEY |
La tua chiave Mistral (sk-...) |
AI_REVIEWER_GOOGLE_API_KEY |
La tua chiave Gemini (AIza...) |
Clicca "Add secret" per ciascuno.
Istruzioni dettagliate con screenshot
- Apri il tuo repository su GitHub
- Clicca Settings (ingranaggio nel menu superiore)
- Nel menu a sinistra trova Secrets and variables โ Actions
- Clicca il pulsante verde New repository secret
- Inserisci il nome e incolla la chiave
- Clicca Add secret
- Ripeti per ogni secret
Per GitLab devi creare un token GitLab per pubblicare commenti.
Passo 2a: Crea un token GitLab¶
Percorso: Avatar utente โ Edit profile โ Access Tokens
| Campo | Valore |
|---|---|
| Token name | ai-reviewer |
| Expiration date | Scegli una data (max 1 anno) |
| Scopes | api |
Clicca "Create personal access token" โ Copia il token (viene mostrato una sola volta!)
I commenti appariranno sotto il tuo nome utente
Un Personal Access Token e legato al tuo account. Tutti i commenti della revisione saranno pubblicati a tuo nome.
Servono i permessi Maintainer
Per creare un Project Access Token serve il ruolo Maintainer o Owner nel progetto.
Percorso: Project โ Settings โ Access Tokens
| Campo | Valore |
|---|---|
| Token name | ai-reviewer |
| Expiration date | Scegli una data (max 1 anno) |
| Role | Developer |
| Scopes | api |
Clicca "Create project access token" โ Copia il token (viene mostrato una sola volta!)
Passo 2b: Aggiungi le Variabili in CI/CD¶
Percorso: Project โ Settings โ CI/CD โ Variables
| Key | Value | Flags |
|---|---|---|
AI_REVIEWER_GOOGLE_API_KEY |
La tua chiave Gemini | |
AI_REVIEWER_GITLAB_TOKEN |
Token dal passo 2a |
| Key | Value | Flags |
|---|---|---|
AI_REVIEWER_MISTRAL_API_KEY |
La tua chiave Mistral | |
AI_REVIEWER_GITLAB_TOKEN |
Token dal passo 2a |
| Key | Value | Flags |
|---|---|---|
AI_REVIEWER_MISTRAL_API_KEY |
La tua chiave Mistral | |
AI_REVIEWER_GOOGLE_API_KEY |
La tua chiave Gemini | |
AI_REVIEWER_GITLAB_TOKEN |
Token dal passo 2a |
Deseleziona ยซProtectedยป!
Per impostazione predefinita, GitLab contrassegna le nuove variabili come Protected. Le variabili Protected sono disponibili solo nei branch protetti (es. main), ma le pipeline MR vengono eseguite su branch sorgente non protetti โ la variabile sara vuota e otterrai 401 Unauthorized.
CI_JOB_TOKEN non funziona
Il CI_JOB_TOKEN automatico di GitLab non puo pubblicare commenti sulle Merge Request.
Devi creare un Personal Access Token (o un Project Access Token su Premium+).
Passo 3: Aggiungi AI Review nel CI¶
Crea il file .github/workflows/ai-review.yml:
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ai-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
steps:
- uses: KonstZiv/ai-code-reviewer@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
google_api_key: ${{ secrets.AI_REVIEWER_GOOGLE_API_KEY }}
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ai-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
steps:
- uses: KonstZiv/ai-code-reviewer@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
mistral_api_key: ${{ secrets.AI_REVIEWER_MISTRAL_API_KEY }}
llm_provider: mistral
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ai-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
steps:
- uses: KonstZiv/ai-code-reviewer@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
mistral_api_key: ${{ secrets.AI_REVIEWER_MISTRAL_API_KEY }}
google_api_key: ${{ secrets.AI_REVIEWER_GOOGLE_API_KEY }}
llm_provider: mistral
llm_fallback_provider: google
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ai-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
steps:
- uses: KonstZiv/ai-code-reviewer@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
mistral_api_key: ${{ secrets.AI_REVIEWER_MISTRAL_API_KEY }}
llm_provider: mistral
mistral_model: codestral-latest
mistral_api_url: https://codestral.mistral.ai
Chiave Codestral
Usa la chiave da codestral.mistral.ai, non la chiave API Mistral normale.
Info su GITHUB_TOKEN
secrets.GITHUB_TOKEN e un token automatico che GitHub crea per ogni workflow run. Non serve aggiungerlo manualmente ai secret โ e gia disponibile.
Crea o aggiorna .gitlab-ci.yml:
stages:
- review
ai-review:
image: ghcr.io/konstziv/ai-code-reviewer:1
stage: review
script:
- ai-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
Le variabili CI/CD AI_REVIEWER_GOOGLE_API_KEY e AI_REVIEWER_GITLAB_TOKEN dal Passo 2b vengono ereditate automaticamente.
stages:
- review
ai-review:
image: ghcr.io/konstziv/ai-code-reviewer:1
stage: review
variables:
AI_REVIEWER_LLM_PROVIDER: mistral
script:
- ai-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
Le variabili CI/CD AI_REVIEWER_MISTRAL_API_KEY e AI_REVIEWER_GITLAB_TOKEN dal Passo 2b vengono ereditate automaticamente.
stages:
- review
ai-review:
image: ghcr.io/konstziv/ai-code-reviewer:1
stage: review
variables:
AI_REVIEWER_LLM_PROVIDER: mistral
AI_REVIEWER_LLM_FALLBACK_PROVIDER: google
script:
- ai-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
Tutte e tre le variabili CI/CD (AI_REVIEWER_MISTRAL_API_KEY, AI_REVIEWER_GOOGLE_API_KEY, AI_REVIEWER_GITLAB_TOKEN) dal Passo 2b vengono ereditate automaticamente.
stages:
- review
ai-review:
image: ghcr.io/konstziv/ai-code-reviewer:1
stage: review
variables:
AI_REVIEWER_LLM_PROVIDER: mistral
AI_REVIEWER_MISTRAL_MODEL: codestral-latest
AI_REVIEWER_MISTRAL_API_URL: https://codestral.mistral.ai
script:
- ai-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
Le variabili CI/CD AI_REVIEWER_MISTRAL_API_KEY (usa la chiave Codestral) e AI_REVIEWER_GITLAB_TOKEN dal Passo 2b sono disponibili automaticamente.
Passo 4: Verifica il Risultato¶
Ora AI Review partira automaticamente quando:
| Piattaforma | Evento |
|---|---|
| GitHub | Creazione PR, nuovi commit in PR, riapertura PR |
| GitLab | Creazione MR, nuovi commit in MR |
Cosa Vedrai¶
Dopo il completamento del job CI, appariranno nel PR/MR:
- Commenti inline โ collegati a righe specifiche di codice
- Pulsante "Apply suggestion" โ per applicare rapidamente le correzioni (GitHub)
- Commento summary โ panoramica generale con metriche
Ogni commento contiene:
/
/
Badge di gravita
- Descrizione del problema
- Suggerimento di correzione
- Sezione espandibile "Perche e importante?"
Il footer mostra quale modello e provider e stato utilizzato:
Model: Google / gemini-2.5-flash | Tokens: 1,234 | Latency: 2.3s | Est. cost: $0.0012
Troubleshooting¶
La revisione non appare?¶
Controlla questa checklist:
- La chiave API e stata aggiunta come secret? (
AI_REVIEWER_GOOGLE_API_KEYoAI_REVIEWER_MISTRAL_API_KEY) -
llm_providere impostato correttamente se usi Mistral? (il predefinito egoogle) -
github_tokenpassato esplicitamente? (per GitHub) - Per GitLab:
AI_REVIEWER_GITLAB_TOKENe impostato su un Personal Access Token? - Il job CI e terminato con successo? (controlla i log)
- Per GitHub: hai
permissions: pull-requests: write? - Per PR da fork: i secret non sono disponibili โ comportamento previsto
Rate limit?¶
- Gemini tier gratuito: 15 richieste al minuto
- Mistral tier gratuito: controlla Mistral Pricing per i limiti attuali
Aspetta un minuto e riprova, oppure configura un provider di fallback.
Tutti i problemi e soluzioni โ
Cosa Fare Dopo?¶
| Compito | Documento |
|---|---|
| Configurare la lingua delle risposte | Configurazione |
| Impostazioni avanzate provider LLM | Configurazione โ LLM |
| Cambiare modelli senza modificare il codice | GitHub โ Configurazione tramite Variables |
| Impostazioni avanzate GitHub | Guida GitHub |
| Impostazioni avanzate GitLab | Guida GitLab |
| Esempi di workflow | Esempi |