Skip to content

Repository files navigation

SonarQube Bug Export Workaround

The Community Edition of SonarQube does not provide an official way to export unresolved issues or generate bug reports. This project offers a workaround by programmatically retrieving and correlating SonarQube issues with their rule metadata, producing a useful .csv export.

Features

  • Export unresolved issues from any project analyzed by SonarQube.
  • Enrich issues with rule metadata (bug descriptions, language, etc.).
  • Generate a clean, de-duplicated bug_fixes.csv file.
  • Fully automated with Python and SonarQube REST APIs.

How It Works

This tool leverages SonarQube's REST API to extract project-specific issues and metadata. Here's the flow:

  1. Rule Metadata Collection (all_rules_scraping.py):

    • Authenticates using your API token.
    • Calls the /api/rules/search endpoint.
    • Iterates through all pages and extracts rule key, language, and description.
    • Saves to all_sonarqube_rules.csv.
  2. Unresolved Issue Extraction (repo_rules_scraping.py):

    • Prompts the user to input a SonarQube project key.
    • Calls the /api/issues/search endpoint with filters for unresolved issues.
    • Extracts rule key and filename from each issue.
    • Saves raw output to unresolved_issues.csv.
  3. Merging & Enrichment:

    • Loads both CSV files using pandas.
    • Merges them on the rule key (keyrule) to enrich issues with rule info.
    • Selects and renames columns: code_language, file_name, and bug_description.
    • Removes duplicates and saves final bug_fixes.csv.

Final Output: A clean list of file-level issues enriched with descriptions for bug tracking, analysis, or automation.

Pre-requisites

  • Python 3.7+
  • SonarQube Community Edition (running at http://localhost:9000)
  • A valid SonarQube API Token
  • Installed Python packages:
    • requests
    • pandas

You can install dependencies via:

pip install -r requirements.txt

If requirements.txt is missing:

pip install requests pandas

Installation

  1. Clone this repository or download the scripts:
git clone https://github.com/your-username/sonarqube-export-workaround.git
cd sonarqube-export-workaround
  1. Ensure SonarQube server is running:
docker ps
# Look for container with name like 'sonarqube' and port 9000 exposed
  1. Replace the TOKEN in both Python files with your SonarQube API token:
TOKEN = "your_actual_sonar_token_here"

Usage

There are two main steps:

Step 1: Download All SonarQube Rules

This script pulls metadata for all rules:

python3 all_rules_scraping.py

Output:

  • all_sonarqube_rules.csv

Step 2: Export Unresolved Issues for a Project

python3 repo_rules_scraping.py

It will prompt:

enter the repo for which u want to pull the bugs :

Provide your project key (e.g., my_project_key)

Output:

  • unresolved_issues.csv
  • bug_fixes.csv (final enriched file)

Example Session

$ python3 all_rules_scraping.py
 Fetching page 1...
 Fetching page 2...
...
 Saved 4023 rules to 'all_sonarqube_rules.csv'

$ python3 repo_rules_scraping.py
enter the repo for which u want to pull the bugs : my_project_key
df1: Index(['key', 'repo', 'name'], dtype='object')
df2: Index(['rule', 'file_name'], dtype='object')
Merge completed. Saved to bug_fixes.csv

Final bug_fixes.csv will look like:

code_language file_name bug_description
java MyClass.java “Equals() should not be used...”
py script.py “Use ‘is’ for comparison to None...”

This workaround gives SonarQube Community users better visibility into issues and supports external analysis or automation.

Demo Video

bugs_export_demo.webm

About

A Python-based workaround for exporting unresolved issues from SonarQube Community Edition . Generates a clean CSV report enriched with rule descriptions.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages