Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests
Project description
AI Code Review
Automated code review tool with Pull Request integration for Azure DevOps/TFS and support for multiple LLM providers.
The main entry point is in src/ai_review.py. The project also includes dedicated modules for configuration, output formatting, Git diff capture, TFS/Azure DevOps integration, and communication with the LLM provider.
Features
- AI Pull Request review (
pr-review) - Structured PR comments (inline + general summary)
dry-runmode to validate without posting- PR listing with filters (
list-prs) - Configuration exclusively via
config.yaml - Providers LLM: OpenAI, Azure OpenAI, Gemini, Claude, Ollama, GitHub Copilot, AWS Bedrock
Installation
Install from PyPI:
pip install code-review-ai-cli
Or install with optional LLM SDK extras:
pip install "code-review-ai-cli[bedrock]" # AWS Bedrock
pip install "code-review-ai-cli[openai]" # OpenAI SDK
pip install "code-review-ai-cli[gemini]" # Google Gemini SDK
pip install "code-review-ai-cli[claude]" # Anthropic Claude SDK
pip install "code-review-ai-cli[all]" # All optional SDKs
All providers also work without their optional SDK — the tool communicates via HTTP directly.
If you plan to run the test suite locally, also install development dependencies:
pip install "code-review-ai-cli[dev]"
Configuration
After installing the package, generate a ready-to-edit config.yaml in your working directory:
ai-review init
This copies the bundled template with all available options and inline documentation:
✅ config.yaml created at: /home/user/my-project/config.yaml
Edit it to add your credentials and preferences.
If a config.yaml already exists you will be prompted before it is overwritten:
config.yaml already exists in the current directory.
Overwrite? [y/N]
The tool looks for config.yaml in the current working directory at runtime. You can also pass a different path with --config:
ai-review pr-review --config ~/configs/ai-review.yaml
Minimal Example
llm:
provider: openai
model: gpt-4o
openai:
api_key: sk-xxxx
tfs:
base_url: https://dev.azure.com/your-organization
project: ProjectName
pat: xxxxxxxxx
verify_ssl: true
# ca_bundle: C:/certs/corporate-root-ca.pem
review:
language: pt
verbosity: detailed
scope: diff_only
custom_prompt_file: review_prompt.md
# file limit sent to the LLM
max_diff_files: 50
# per-file limit
max_diff_lines: 2000
# extension allowlist (empty list = all files)
file_extensions_filter: [".cs", ".ts", ".py"]
pr:
auto_post_comments: false
dry_run: false
comment_mode: structured
output:
format: terminal
file: ""
color: true
Filter by File Extension
file_extensions_filter works as an allowlist: only files with listed extensions are sent to the LLM for review. Remaining files are excluded from the diff before any processing.
review:
# Review only C#, TypeScript, and Python code
file_extensions_filter: [".cs", ".ts", ".py"]
To review all PR files, leave the list empty:
review:
file_extensions_filter: []
Note: If no eligible files remain after filtering, the review ends with a warning without calling the LLM.
Markdown-Customizable Prompt
You can adjust review rules, context, and examples in review_prompt.md.
This file is loaded automatically and injected into LLM instructions on each run.
Example in config.yaml:
review:
custom_prompt_file: review_prompt.md
Suggested usage for this file:
- Define comment tone and format
- Add mandatory validation rules
- Include business/architecture context
- Add examples of good/bad comments
Bedrock Example
llm:
provider: bedrock
model: anthropic.claude-3-5-sonnet-20240620-v1:0
bedrock:
region: us-east-1
# profile: default
# access_key_id: AKIA...
# secret_access_key: ...
# session_token: ...
tfs:
base_url: https://dev.azure.com/your-organization
project: ProjectName
pat: xxxxxxxxx
Bedrock notes:
- You can use
profileor explicit credentials in YAML. - If explicit credentials are not defined, the AWS SDK uses the default credentials chain.
Review Flow
The main pr-review workflow is:
- load and validate configuration
- fetch Pull Request metadata from Azure DevOps/TFS
- fetch the PR diff
- filter and truncate the diff according to configuration
- request textual analysis and structured comments from the LLM provider
- display a preview in the terminal
- post inline or general PR comments when applicable
Tests
The project's functional coverage is reflected in the tests/ folder, including:
tests/test_ai_review.pyfor the CLI and main workflowtests/test_config.pyfor configuration and validationtests/test_formatter.pyfor terminal/markdown/json renderingtests/test_git_utils.pyfor diffs and Git utilitiestests/test_llm_client.pyfor prompts, parsing, and LLM providerstests/test_tfs_client.pyfor TFS/Azure DevOps integration
Run the suite:
python -m pytest --cov=src --cov-report=term
CLI Usage
Help
python src/ai_review.py --help
Bootstrap configuration
Generate a config.yaml template in the current directory:
ai-review init
Interactive Mode
python ai_review.py
Pull Request Review
List PRs and select interactively:
python ai_review.py pr-review
Review a specific PR:
python ai_review.py pr-review 42
Dry-run:
python ai_review.py pr-review 42 --dry-run
Full review of changed files (in addition to diff-focused review):
python ai_review.py pr-review 42 --review-scope full_code
Automatic posting (without confirmation):
python ai_review.py pr-review 42 --auto-post
Filter PRs in interactive selection:
python ai_review.py pr-review --author "John Smith" --target-branch main
Choose provider/model via CLI:
python ai_review.py pr-review 42 --provider bedrock --model anthropic.claude-3-5-sonnet-20240620-v1:0
List Pull Requests
python ai_review.py list-prs
python ai_review.py list-prs --status completed
python ai_review.py list-prs --repo-name backend --author "John"
Execution Flow
The diagram below summarizes how the review application moves from CLI entry to PR analysis and comment posting.
flowchart TD
A[Start: python ai_review.py] --> B{Arguments provided?}
B -->|No| C[Interactive mode]
B -->|Yes| D[Parse CLI command]
C --> E{Choose action}
E -->|PR review| F[Start PR review workflow]
E -->|List PRs| G[List pull requests]
E -->|Show config| H[Display current configuration]
D --> I{Command}
I -->|pr-review| F
I -->|list-prs| G
F --> J[Load and validate config]
J --> K[Initialize TFS client]
K --> L{PR ID provided?}
L -->|No| M[Fetch active PRs and select one]
L -->|Yes| N[Use provided PR ID]
M --> O[Get PR details]
N --> O
O --> P[Get PR diff or full changed-file context]
P --> Q[Filter by allowed file extensions]
Q --> R[Keep additions only]
R --> S[Limit files with max_diff_files]
S --> T[Build changed-files summary]
T --> U[Truncate each file with max_diff_lines]
U --> V[Run AI general review]
V --> W[Run AI structured comment generation]
W --> X[Preview review and suggested comments]
X --> Y{Dry-run enabled?}
Y -->|Yes| Z[Stop after preview]
Y -->|No| AA{Auto-post enabled?}
AA -->|Yes| AB[Post all review comments]
AA -->|No| AC[Select comments to post]
AC --> AB
AB --> AD[Post general PR summary]
AD --> AE{Output file configured?}
AE -->|Yes| AF[Save formatted review output]
AE -->|No| AG[Finish]
AF --> AG
G --> AH[Fetch PR list with filters]
AH --> AI[Display PR list]
Supported Commands and Options
pr-review
python ai_review.py pr-review [pr_id]
Options:
--repo-name,-r--dry-run--auto-post--author--target-branch--quick/--detailed/--security--review-scope {diff_only,full_code}(default:diff_only)--max-diff-files N— overridesreview.max_diff_filesfrom config.yaml--context,-c--format {terminal,markdown,json}--output,-o--no-color--model,-m--provider,-p--config
list-prs
python ai_review.py list-prs
Options:
--repo-name,-r--status {active,completed,abandoned,all}--author
Available VS Code Tasks
🌟 AI Review: Pull Request (Interactive)🌟 AI Review: PR (Dry-Run)📋 AI Review: List Active PRs🤖 AI Review: Interactive Mode
Troubleshooting
TLS/SSL Error in On-Prem TFS
Prefer using a CA bundle:
tfs:
verify_ssl: true
ca_bundle: C:/certs/corporate-root-ca.pem
Avoid verify_ssl: false except for temporary troubleshooting.
Bedrock Authentication Error
- Confirm
bedrock.region. - Confirm
llm.modelwith a valid Bedrock model ID in the chosen region. - Validate AWS credentials (
profileor explicit keys).
Architecture
ai_code_review_script/
├── src/
│ ├── config.py # YAML-only configuration
│ ├── ai_review.py # Main PR CLI and workflow
│ ├── llm_client.py # LLM provider integration (includes Bedrock)
│ ├── tfs_client.py # Azure DevOps/TFS (PRs and comments)
│ ├── formatter.py # Output formatting
│ └── git_utils.py # Utilities for diff parsing/truncation
├── config.yaml # Single configuration file
├── requirements.txt # Python dependencies
└── .vscode/tasks.json # PR review tasks
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file code_review_ai_cli-1.0.0.tar.gz.
File metadata
- Download URL: code_review_ai_cli-1.0.0.tar.gz
- Upload date:
- Size: 58.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0246234ae6873d2f0a827d70caadb3ef504fed142737729a7bc8c18ce3221f0f
|
|
| MD5 |
34d5e20b3f18b3d62016c1d75b0cb3d4
|
|
| BLAKE2b-256 |
1176172a1b6c8d0f42758d9917088bb3d3d36f27ec98e6d48fb5c819e1200278
|
File details
Details for the file code_review_ai_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: code_review_ai_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 44.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13f52fe918233e3cf7a44ca0097041c207321b690f52bfc2b72c5dfaeb0228f1
|
|
| MD5 |
dcf60508a450c6025f7db9f0adf88b89
|
|
| BLAKE2b-256 |
42c862eea30fab0dec6a583d995b250bac0dcd1d205309a5083c6edc65645f70
|