English | 中文 | Français | Español | العربية | Русский
This document explains how to integrate SonarCloud analysis results with AI to automatically retrieve code quality issues and use AI to assist with fixes.
This integration works through the following steps:
graph TD
A[Code Development] --> B[SonarCloud Analysis]
B --> C{Issues Detected?}
C -->|Yes| D[AI Analysis of Issues]
D --> E[Fix Suggestions]
E --> F[Implement Fixes]
F --> A
C -->|No| G[AI Optimization Analysis]
G --> H[Optimization Suggestions]
H --> A
- GitHub Actions workflow runs SonarCloud analysis during the CI/CD process
- After analysis is complete, the workflow extracts SonarCloud issues and generates reports in two formats:
- JSON format: Contains complete raw data, suitable for in-depth AI analysis
- Markdown format: Formatted human-readable report with issue summaries and details
- These two reports are uploaded as workflow artifacts
- Using the provided Fish function, you can easily download these reports and provide them to AI for analysis and fix suggestions
Add the sonar-ai-fix function to your Fish configuration:
# Add to ~/.config/fish/config.fish
source /path/to/mcp-dbutils/scripts/sonar-ai-fix.fishAlternatively, you can run the script directly to load the function temporarily:
source scripts/sonar-ai-fix.fishIn the project root directory, run:
sonar-ai-fixThis will download the latest SonarCloud analysis reports and save them as two files:
sonar_report.md: Markdown formatted reportsonar_issues.json: Raw data in JSON format
There are two ways to use these reports:
-
Open the
sonar_report.mdfile:bat sonar_report.md
-
Copy the content to an AI (like Claude) and request fix suggestions:
This is the SonarCloud analysis report for my project. Please analyze these issues and provide fix suggestions. [Paste sonar_report.md content]
For situations requiring more in-depth analysis, you can use the JSON data:
-
Open the JSON file:
bat sonar_issues.json
-
Provide the content to AI for more detailed analysis:
This is the raw SonarCloud analysis data for my project. Please perform an in-depth analysis of these issues and provide fix suggestions. [Paste sonar_issues.json content]
In .github/workflows/quality-assurance.yml, we've added two key steps:
-
Extract SonarCloud Issues:
- Uses the SonarCloud API to get unresolved issues
- Formats issues into JSON and Markdown formats
-
Upload Report Artifacts:
- Uploads the generated reports as workflow artifacts
- Makes artifacts downloadable via GitHub CLI
The sonar-ai-fix.fish script provides a convenient function that:
- Checks if the current directory is a project directory
- Gets the latest workflow run ID
- Downloads the SonarCloud issues report artifacts
- Saves the reports to the current directory
- Provides usage instructions
- Ensure you have GitHub CLI (
gh) installed and configured - Ensure you have sufficient permissions to access the GitHub repository and workflows
- Issue links in the reports point to the SonarCloud website, which requires project access permissions
- This feature works best with local AI tools (like Claude Desktop)