A CLI tool to analyze SonarCloud issues and attempt LLM-powered fixes
Project description
DevDox AI SonarCloud
A powerful CLI tool and Python library that analyzes SonarCloud issues and generates AI-powered fix suggestions using Large Language Models (LLMs).
Features
- ๐ Fetch SonarCloud Issues: Retrieve issues from SonarCloud projects with filtering capabilities
- ๐ Project Analytics: Get comprehensive project metrics and quality insights
- ๐ค AI-Powered Fixes: Generate intelligent fix suggestions using OpenAI, Anthropic, or Google Gemini LLMs
- ๐ ๏ธ Automated Application: Apply fixes directly to your codebase with backup support
- ๐ Project Inspection: Analyze local project structure and configuration
- ๐ฏ Interactive CLI: Claude Code-style interactive interface with rich output formatting
- ๐ Command Switching: Switch between commands mid-workflow by typing
/ - ๐ Security Focus: Specialized security vulnerability fixing mode
- ๐ฆ Library Support: Use as a Python library in your own projects
- โ๏ธ Flexible Configuration: Interactive configuration management for providers and SonarCloud
- ๐ซ Rule Exclusions: Exclude specific SonarQube rules from analysis
Installation
pip install devdox_ai_sonar
Development Installation
git clone https://github.com/montymobile1/devdox-ai-sonar.git
cd devdox-ai-sonar
pip install -e ".[dev]"
Requirements
- Python 3.9+
- SonarCloud authentication token
- LLM API key (OpenAI, Anthropic, or Google Gemini)
Quick Start
1. Interactive Configuration
The easiest way to get started is through the interactive configuration:
devdox_sonar
This will guide you through:
- SonarCloud configuration (token, organization, project)
- LLM provider setup (OpenAI, Anthropic, or Gemini)
- Analysis parameters (issue types, severities, max fixes)
2. Direct Command Execution
Run specific commands directly:
# Fix issues
devdox_sonar -c fix_issues
# Fix security issues specifically
devdox_sonar -c fix_security_issues
# Analyze project
devdox_sonar -c analyze
# Inspect local project
devdox_sonar -c inspect
3. Command Line with Options
devdox_sonar -c fix_issues \
--types BUG,CODE_SMELL \
--severity CRITICAL,BLOCKER \
--max-fixes 10 \
--apply 1
Interactive Mode
The interactive mode provides a Claude Code-style experience:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
DevDox AI Sonar - Interactive Mode
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
? What would you like to do?
โ Add Provider - Add provider or sonar configuration
โ๏ธ Update Provider - Update provider or sonar configuration
๐ง Fix Issues - Generate and apply LLM-powered fixes
๐ Fix Security Issues - Specialized security vulnerability fixes
๐ Analyze Project - Display SonarCloud analysis
๐ Inspect Project - Analyze local directory structure
โ๏ธ Change Parameters Configuration
โ Exit
Command Switching
At any prompt, type / to return to the main menu and switch to a different command.
CLI Commands
Main Entry Point
devdox_sonar [OPTIONS]
Options:
-v, --verbose Enable verbose output
-c, --command TEXT Run specific command directly
--types TEXT Comma-separated issue types
--severity TEXT Comma-separated severities
--max-fixes INTEGER Maximum number of fixes (0-100)
--apply INTEGER Apply fixes (1=apply, 0=preview)
--dry-run Show changes without applying
--version Show version
--help Show help message
Configuration Commands
add_provider
Add a new LLM provider configuration:
devdox_sonar -c add_provider
Supported Providers:
- OpenAI (GPT-4, GPT-4 Turbo, GPT-3.5)
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus)
- Google Gemini (Gemini Pro, Gemini Ultra)
update_provider
Update an existing provider configuration:
devdox_sonar -c update_provider
change_parameters
Modify analysis parameters:
devdox_sonar -c change_parameters
Configurable Parameters:
- Branch or Pull Request selection
- Maximum number of fixes
- Issue types (BUG, VULNERABILITY, CODE_SMELL, SECURITY_HOTSPOT)
- Severities (BLOCKER, CRITICAL, MAJOR, MINOR, INFO)
- Apply fixes automatically
- Create backups before applying
- Exclude specific rules
Analysis Commands
fix_issues
Generate and apply LLM-powered fixes for regular issues:
devdox_sonar -c fix_issues [OPTIONS]
Options:
--types TEXT Filter by issue types
--severity TEXT Filter by severities
--max-fixes INTEGER Maximum fixes to generate
--apply INTEGER Apply fixes (1=yes, 0=no)
--dry-run Preview changes only
Example:
devdox_sonar -c fix_issues \
--types "BUG,CODE_SMELL" \
--severity "CRITICAL,MAJOR" \
--max-fixes 5 \
--apply 1
fix_security_issues
Specialized command for fixing security vulnerabilities:
devdox_sonar -c fix_security_issues [OPTIONS]
Features:
- Focuses exclusively on security issues
- Groups issues by file for comprehensive fixes
- Enhanced validation for security-sensitive changes
- Detailed markdown documentation of changes
analyze
Display SonarCloud analysis results:
devdox_sonar -c analyze
Shows:
- Project metrics (lines of code, coverage, bugs, vulnerabilities)
- Issue breakdown by severity and type
- Detailed issue list with file locations
inspect
Analyze local project directory structure:
devdox_sonar -c inspect
Analyzes:
- File counts by language
- Source directory detection
- SonarCloud configuration presence
- Git repository status
Configuration
Configuration Files
DevDox AI Sonar uses two configuration files:
- Auth Configuration (
~/.devdox_sonar_auth.json):
{
"token": "your_sonarcloud_token",
"organization": "your_org",
"project": "your_project",
"project_path": "/path/to/project"
}
- LLM Configuration (
~/.devdox_sonar_config.yaml):
llm:
default_provider: "openai",
default_model: "gpt-4o"
providers:
openai:
api_key: "your_openai_key",
name: "openai"
default_model: "gpt-4o",
model: "gpt-4o",
models:
- "gpt-4o"
- "mini-gpt-4o"
configuration:
max_fixes: 10
types: "BUG,CODE_SMELL"
severities: "CRITICAL,MAJOR"
apply: 0
create_backup: 1
exclude_rules: "python:S3776,python:S7493"
Environment Variables
Alternatively, use environment variables:
export SONAR_TOKEN="your_sonarcloud_token"
export OPENAI_API_KEY="your_openai_api_key"
export ANTHROPIC_API_KEY="your_anthropic_api_key"
export GEMINI_API_KEY="your_gemini_api_key"
SonarCloud Setup
- Get your token: https://sonarcloud.io/account/security
- Find organization/project keys in SonarCloud dashboard
- Ensure your project has recent analysis results
LLM Provider Setup
OpenAI
- Sign up: https://platform.openai.com
- Recommended models:
gpt-4o,gpt-4-turbo
Anthropic
- Sign up: https://console.anthropic.com
- Recommended models:
claude-3-5-sonnet-20241022,claude-3-opus-20240229
Google Gemini
- Sign up: https://makersuite.google.com
- Recommended models:
gemini-pro,gemini-ultra
Rule Exclusions
Exclude specific SonarQube rules from analysis:
Via Interactive Configuration
devdox_sonar -c change_parameters
# Select "Rules to be excluded"
# Enter: python:S7503,python:S7493,python:S107
Via Configuration File
Add to ~/.devdox_sonar_config.yaml:
configura[config.toml](../../../devdox/config.toml)tion:
exclude_rules: "python:S7503,python:S7493,python:S107"
Common Rules to Exclude
| Rule ID | Description | Reason to Exclude |
|---|---|---|
python:S7503 |
Async functions should use async features | |
python:S7493 |
Async functions should not contain synchronous file operations | |
python:S107 |
Too Many Parameters | FastAPI dependency injection |
python:S5852 |
ReDoS | Safe patterns flagged incorrectly |
Issue Types and Processing
Regular Issues (By Rule)
Regular issues are grouped by rule and processed individually:
- BUG: Logic errors, null pointer issues
- CODE_SMELL: Style issues, maintainability problems
- SECURITY_HOTSPOT: Potential security concerns
Security Issues (By File)
Security issues are grouped by file for comprehensive fixes:
- VULNERABILITY: SQL injection, XSS, authentication issues
- Processed once per file with all security issues
- Enhanced validation and documentation
Supported Languages
- Python (.py)
- JavaScript/TypeScript (.js, .jsx, .ts, .tsx)
- Java (.java)
- Kotlin (.kt)
- Scala (.scala)
- Go (.go)
- Rust (.rs)
- C/C++ (.c, .cpp)
- C# (.cs)
- PHP (.php)
- Ruby (.rb)
- Swift (.swift)
Best Practices
Before Using Fixes
- Backup Your Code: Automatic backup creation is enabled by default
- Review Generated Fixes: Always review before applying to production code
- Test Thoroughly: Run your test suite after applying fixes
- Version Control: Commit changes incrementally
- Use Dry Run: Preview changes with
--dry-runflag
Fix Confidence Levels
- High (>0.8): Generally safe to apply
- Medium (0.6-0.8): Review recommended
- Low (<0.6): Manual review required
Security Fixes
- Always manually review security-related fixes
- Test security fixes thoroughly
- Consider security implications of automated changes
- Review generated markdown documentation
Performance Tips
- Use
--max-fixesto limit processing for large projects - Filter by severity to prioritize critical issues
- Exclude false-positive rules to reduce noise
- Use branch/PR filtering to focus on specific changes
Change Documentation
All fixes generate markdown documentation:
- Regular issues:
CHANGES_REGULAR_YYYYMMDDHHMMSS.md - Security issues:
CHANGES_SECURITY_YYYYMMDDHHMMSS.md
Documentation includes:
- Original code
- Fixed code
- Explanation of changes
- Rule information
- Confidence scores
Troubleshooting
Common Issues
Authentication Error
Error: 401 Unauthorized
Solution: Verify SonarCloud token and permissions
LLM API Errors
Error: Invalid API key
Solution: Check API key validity and billing status
File Not Found
File not found: /path/to/file.py
Solution: Verify project path matches SonarCloud structure
Configuration Not Found
โ Configuration not found
Solution: Run devdox_sonar without options to initialize configuration
Debug Mode
Enable verbose output:
devdox_sonar --verbose -c fix_issues
Reset Configuration
Delete configuration files and reconfigure:
rm ~/.devdox_sonar_auth.json
rm ~/.devdox_sonar_config.yaml
devdox_sonar
Development
Setup
git clone https://github.com/montymobile1/devdox-ai-sonar.git
cd devdox-ai-sonar
pip install -e ".[dev]"
Command Reference
Quick Command List
# Interactive mode
devdox_sonar
# Configuration
devdox_sonar -c add_provider
devdox_sonar -c update_provider
devdox_sonar -c change_parameters
# Analysis and fixing
devdox_sonar -c fix_issues
devdox_sonar -c fix_security_issues
devdox_sonar -c analyze
devdox_sonar -c inspect
# With options
devdox_sonar -c fix_issues --apply 1 --max-fixes 10
devdox_sonar -c fix_issues --dry-run
devdox_sonar --verbose -c analyze
Workflow Examples
First-Time Setup
# Step 1: Initialize configuration
devdox_sonar
# Step 2: Configure SonarCloud
# Follow interactive prompts for token, org, project
# Step 3: Add LLM provider
# Select and configure your preferred provider
# Step 4: Set parameters
# Configure issue types, severities, etc.
# Step 5: Run analysis
# Select "Fix Issues" from menu
Regular Workflow
# Preview fixes without applying
devdox_sonar -c fix_issues --dry-run
# Apply fixes with backup
devdox_sonar -c fix_issues --apply 1
# Focus on critical bugs only
devdox_sonar -c fix_issues \
--types BUG \
--severity CRITICAL,BLOCKER \
--max-fixes 5 \
--apply 1
Security Audit Workflow
# Analyze security issues
devdox_sonar -c analyze
# Fix security vulnerabilities
devdox_sonar -c fix_security_issues --dry-run
# Review generated CHANGES_SECURITY_*.md
# Apply after review
devdox_sonar -c fix_security_issues --apply 1
License
MIT License - see LICENSE file for details.
Support
Acknowledgments
- Built with Rich for beautiful terminal output
- Uses Questionary for interactive prompts
- Powered by OpenAI, Anthropic, and Google Gemini LLMs
- Integrates with SonarCloud for code quality analysis
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 devdox_sonar-0.0.1b0.tar.gz.
File metadata
- Download URL: devdox_sonar-0.0.1b0.tar.gz
- Upload date:
- Size: 215.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e31f63af1ee1aface6de4504ac66d346c158ac7f1084b436d51e5d349edbba2e
|
|
| MD5 |
59a8ba9ede275c9daf3a9911ab5d901a
|
|
| BLAKE2b-256 |
b436d833d8270f768036de6cc91bc9067c049ae0bacf616bcd459e6330a784b6
|
File details
Details for the file devdox_sonar-0.0.1b0-py3-none-any.whl.
File metadata
- Download URL: devdox_sonar-0.0.1b0-py3-none-any.whl
- Upload date:
- Size: 133.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5270d9478ac69b9caf04ceee7414f0ecc8d58a7e4c0947802b2f996bdf098bbe
|
|
| MD5 |
ba62a431a7565ea233366933fd597b06
|
|
| BLAKE2b-256 |
a847ac893eb8ea5d2d9897bcffa9d589a270fe7be04cc4ac65f13839baa6f7d3
|