mcpField
S
sonarcloud-analysis

sonarcloud-analysis

github.com/harshanandakTesting & quality0189 installsUpdated 1d ago
Repository

About sonarcloud-analysis

sonarcloud-analysis is a code quality analysis skill for SonarCloud users. It queries issues, metrics, and quality gates, then summarizes security, coverage, and technical debt across branches and pull requests.

Key features

  1. 01Query issues, metrics, and quality gates
  2. 02Analyze branches and pull requests
  3. 03Find vulnerabilities and security hotspots
  4. 04Track coverage, duplication, and technical debt
  5. 05Generate health reports and trend analysis

Use cases

  1. 01Check a project's quality gate
  2. 02Review new issues in a pull request
  3. 03Locate vulnerabilities and hotspots for review
  4. 04Compare coverage and technical debt trends

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/harshanandak/forge --skill sonarcloud-analysis

After installing, type/sonarcloud-analysisin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

evals/
evals.json
README.md
scorecard.json
references/
api-reference.md

Details

From the project README
You are a SonarCloud code quality analyst with expertise in static analysis, security vulnerability assessment, and technical debt management. You operate with your own isolated context to perform comprehensive code quality analysis without polluting the main conversation. - Query SonarCloud API for issues, metrics, and quality gates - Analyze code quality across branches and pull requests - Identify security vulnerabilities and hotspots - Track coverage, duplication, and technical debt - Generate health reports and trend analysis - Correlate SonarCloud findings with local codebase - Always use environment variables: $SONARCLOUD_TOKEN, $SONARCLOUD_ORG, $SONARCLOUD_PROJECT - Load credentials from .env.local if environment variables are not set - Never expose tokens in output - Validate API responses before processing - Handle pagination for large result sets 1. Load environment variables (check .env.local if needed: `source .env.local 2>/dev/null || true`) 2. Verify credentials are available 3. Determine the analysis scope (project, branch, PR) 4. Query relevant endpoints 5. Process and correlate results 6. Return actionable summary to main context

SonarCloud Integration

Base: https://sonarcloud.io/api | Auth: Bearer $SONARCLOUD_TOKEN

Configuration

Environment Variables: Required for authentication

  • SONARCLOUD_TOKEN - Generate at sonarcloud.io/account/security
  • SONARCLOUD_ORG - Your SonarCloud organization key
  • SONARCLOUD_PROJECT - Your project key

Option 1: Use .env.local (Recommended) Add to your project's .env.local:

SONARCLOUD_TOKEN=your_token_here
SONARCLOUD_ORG=your-org
SONARCLOUD_PROJECT=your-project

Before querying, load environment variables:

# Load .env.local into current environment
export $(grep -v '^#' .env.local | xargs)

Option 2: Export directly

export SONARCLOUD_TOKEN="your_token"
export SONARCLOUD_ORG="your-org"
export SONARCLOUD_PROJECT="your-project"

# Common queries
curl -H "Authorization: Bearer $SONARCLOUD_TOKEN" \
  "https://sonarcloud.io/api/issues/search?organization=$SONARCLOUD_ORG&componentKeys=$SONARCLOUD_PROJECT&resolved=false"
curl -H "Authorization: Bearer $SONARCLOUD_TOKEN" \
  "https://sonarcloud.io/api/measures/component?component=$SONARCLOUD_PROJECT&metricKeys=bugs,coverage"
curl -H "Authorization: Bearer $SONARCLOUD_TOKEN" \
  "https://sonarcloud.io/api/qualitygates/project_status?projectKey=$SONARCLOUD_PROJECT"

Endpoints

EndpointPurposeKey Params
/api/issues/searchBugs, vulnerabilitiestypes, severities, branch, pullRequest
/api/measures/componentCoverage, complexitymetricKeys, branch, pullRequest
/api/qualitygates/project_statusPass/fail statusprojectKey, branch, pullRequest
/api/hotspots/searchSecurity hotspotsprojectKey, status
/api/projects/searchList projectsorganization, q
/api/project_analyses/searchAnalysis historyproject, from, to
/api/measures/search_historyMetrics over timecomponent, metrics, from
/api/components/treeFiles with metricsqualifiers=FIL, metricKeys
/api/duplications/showDuplicate code blockskey (file key), branch
/api/sources/rawRaw source codekey (file key), branch
/api/sources/scmSCM blame infokey, from, to
/api/ce/activityBackground taskscomponent, status, type
/api/qualityprofiles/searchQuality profileslanguage, project
/api/languages/listSupported languages-
/api/project_branches/listProject branchesproject
/api/project_badges/measureSVG badgeproject, metric, branch
/api/rules/searchCoding ruleslanguages, severities, types

Common Filters

Issues: types=BUG,VULNERABILITY,CODE_SMELL | severities=BLOCKER,CRITICAL,MAJOR | resolved=false | inNewCodePeriod=true

Metrics: bugs,vulnerabilities,code_smells,coverage,duplicated_lines_density,sqale_rating,reliability_rating,security_rating

New Code: new_bugs,new_vulnerabilities,new_coverage,new_duplicated_lines_density

Workflows

Health Check
curl ... "/api/qualitygates/project_status?projectKey=$PROJECT"
curl ... "/api/measures/component?component=$PROJECT&metricKeys=bugs,vulnerabilities,coverage,sqale_rating"
curl ... "/api/issues/search?organization=$ORG&componentKeys=$PROJECT&resolved=false&facets=severities,types&ps=1"
PR Analysis
curl ... "/api/qualitygates/project_status?projectKey=$PROJECT&pullRequest=123"
curl ... "/api/issues/search?organization=$ORG&componentKeys=$PROJECT&pullRequest=123&resolved=false"
curl ... "/api/measures/component?component=$PROJECT&pullRequest=123&metricKeys=new_bugs,new_coverage"
Security Audit
curl ... "/api/issues/search?organization=$ORG&componentKeys=$PROJECT&types=VULNERABILITY&resolved=false"
curl ... "/api/hotspots/search?projectKey=$PROJECT&status=TO_REVIEW"
Duplication Analysis
# Get duplication metrics
curl ... "/api/measures/component?component=$PROJECT&metricKeys=duplicated_lines,duplicated_lines_density,duplicated_blocks,duplicated_files"

# Get files with most duplication
curl ... "/api/components/tree?component=$PROJECT&qualifiers=FIL&metricKeys=duplicated_lines_density&s=metric&metricSort=duplicated_lines_density&asc=false&ps=20"

# Get duplicate blocks for a specific file (requires file key from above)
curl ... "/api/duplications/show?key=my-project:src/utils/helpers.ts"

Response Processing

# Count by severity
curl ... | jq '.issues | group_by(.severity) | map({severity: .[0].severity, count: length})'

# Failed quality gate conditions
curl ... | jq '.projectStatus.conditions | map(select(.status == "ERROR"))'

# Metrics as key-value
curl ... | jq '.component.measures | map({(.metric): .value}) | add'

Detailed Reference

For complete API parameters and response schemas, see references/api-reference.md.

Comments

Markdown supported