GitLab: Esempio Avanzato¶
Configurazione pronta per produzione con tutte le best practice.
Passo 1: Crea un PAT¶
User Settings โ Access Tokens โ Add new token
| Campo | Valore |
|---|---|
| Nome | ai-code-reviewer |
| Scope | api |
| Scadenza | Secondo necessita |
Passo 2: Aggiungi Variabili¶
Settings โ CI/CD โ Variables
| Nome | Valore | Opzioni |
|---|---|---|
AI_REVIEWER_GOOGLE_API_KEY |
Chiave API Gemini | Masked |
AI_REVIEWER_GITLAB_TOKEN |
PAT dal Passo 1 | Masked |
Passo 3: Aggiungi un Job¶
.gitlab-ci.yml:
stages:
- test
- review
# ... altri job ...
ai-review:
stage: review
image: ghcr.io/konstziv/ai-code-reviewer:1
script:
- ai-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Non bloccare MR se la revisione fallisce
allow_failure: true
# Protezione timeout
timeout: 10m
# Puo essere cancellato con nuovo commit
interruptible: true
# Non aspettare altri stage
needs: []
variables:
AI_REVIEWER_LANGUAGE: uk
AI_REVIEWER_LANGUAGE_MODE: adaptive
Cosa Include¶
| Funzionalita | Stato | Descrizione |
|---|---|---|
| Discussioni inline | Con token PAT | |
| Non bloccante | allow_failure: true |
|
| Timeout | 10 minuti | |
| Interrompibile | Cancellato con nuovo commit | |
| Esecuzione parallela | needs: [] |
|
| Lingua personalizzata | LANGUAGE: uk |
Variazioni¶
GitLab Self-hosted¶
Con Docker Registry Personalizzato¶
ai-review:
# Se ghcr.io non e accessibile
image: registry.mycompany.com/devops/ai-code-reviewer:latest
Con Log DEBUG¶
Solo per Branch Specifici¶
ai-review:
# ...
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
when: always
Troubleshooting¶
La Review Non Pubblica Commenti¶
- Controlla i log del job
- Controlla che
AI_REVIEWER_GITLAB_TOKENabbia scopeapi - Controlla che la pipeline sia in esecuzione per una MR
"401 Unauthorized"¶
Token non valido o scaduto. Crea un nuovo PAT.
"403 Forbidden"¶
Il token non ha accesso al progetto. Controlla i permessi.
Esempio Completo .gitlab-ci.yml¶
stages:
- lint
- test
- review
- deploy
lint:
stage: lint
image: python:3.13
script:
- pip install ruff
- ruff check .
test:
stage: test
image: python:3.13
script:
- pip install pytest
- pytest
ai-review:
stage: review
image: ghcr.io/konstziv/ai-code-reviewer:1
script:
- ai-review
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
timeout: 10m
interruptible: true
needs: []
variables:
AI_REVIEWER_LANGUAGE: uk
deploy:
stage: deploy
script:
- echo "Deploying..."
rules:
- if: $CI_COMMIT_BRANCH == "main"