Skip to content

CLI-115 Generic API tool for any sonarqube cloud api#80

Draft
subdavis wants to merge 2 commits intomasterfrom
bd/feature/generic-api-tool
Draft

CLI-115 Generic API tool for any sonarqube cloud api#80
subdavis wants to merge 2 commits intomasterfrom
bd/feature/generic-api-tool

Conversation

@subdavis
Copy link
Member

@subdavis subdavis commented Mar 6, 2026

General API client using built-in templates

This is a vibe-coded proof of concept based on gh api and a similar tool I built before.

Give power users the ability to build reusable automations and agent skills to do anything through the SonarQube Cloud API.

Slack thread: https://sonarsource.slack.com/archives/C0ADT7VMGHW/p1772447653087179

Template variables

  • {organization}
  • {project}

Examples

  • sonar api get '/api/issues/search?projects={project}&organization={organization}
  • sonar api post '/api/user_tokens/generate' --data '{"name":"test-cli-token"}'
  • sonar api get '/api/system/status'
  • sonar api get '/api/organizations/search?member=true'
  • sonar api get '/sca/releases?projectKey={project}'

V1 vs V2 Behavior

  • v1 endpoints take url params or form data
  • v2 endpoints take JSON body
  • endpoints that do NOT begin with /api use SONARCLOUD_API_URL
  • This tool figures out which to use so the user doesn't have to know.

Draft status. I'll clean up the code later if we want to pursue this.

If this feature could be considered in-scope, we can refine the interface and make sure we're covering all the edge cases.

please don't do a code review yet :)

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Generic API tool for any sonarqube cloud api CLI-115 Generic API tool for any sonarqube cloud api Mar 6, 2026
@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Mar 6, 2026

CLI-115

@sonarqube-agent
Copy link

sonarqube-agent bot commented Mar 6, 2026

Remediation Agent Summary 📊

🤖 To review: The 1 issues found require manual fixes.
Issues requiring manual fix (1)

QualityIssue
Maintainability
🟡 Low
Prefer `String#replaceAll()` over `String#replace()`.

Why is this an issue?


Note

Help us improve the Agent!
Have a suggestion or found an issue? Share your feedback here.

@subdavis subdavis requested a review from a team March 9, 2026 14:37
@damien-urruty-sonarsource
Copy link
Contributor

Hi @subdavis! Thanks for the contribution 🙏

We are reconsidering our command tree and discussing with the team what the top-level commands should be. We will definitely consider this PR and use case in the reflection. Give me a couple of days and I will come back to you

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2026

SonarQube reviewer guide

Review in SonarQube

Summary: Add a new api command enabling authenticated HTTP requests to SonarQube/SonarCloud endpoints with support for GET, POST, PATCH, DELETE methods, template variable substitution, and intelligent content-type handling.

Review Focus:

  • Input validation in api.ts (method whitelist, endpoint format, data constraints) — ensure all validation paths are covered
  • SonarCloud URL routing logic in resolveBaseUrl() — verify correct host selection for /api vs non-/api endpoints
  • Content-Type detection (form vs JSON encoding) and form-encoding implementation in api-request.ts — this is critical for v1 API compatibility
  • Template variable substitution with URI encoding in url-template.ts — ensure special characters are properly escaped
  • Build script change: removing the validate step may skip linting/checks — confirm this is intentional

Start review at: src/cli/commands/api.ts. This is the command entry point that orchestrates auth resolution, template substitution, API requests, and error handling. Understanding the control flow here will clarify how the supporting modules (api-request.ts, url-template.ts) are used.

💬 Please send your feedback

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
99.2% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@damien-urruty-sonarsource
Copy link
Contributor

@subdavis small update, we have this epic planned at the beginning of Q2: https://sonarsource.atlassian.net/browse/CLI-100. We likely won't touch this PR until then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants