Skip to content

feat: add SonarQube integration to entity pages - #662

Open
kavix wants to merge 1 commit into
openchoreo:mainfrom
kavix:feat/sonarqube-entity-integration
Open

feat: add SonarQube integration to entity pages#662
kavix wants to merge 1 commit into
openchoreo:mainfrom
kavix:feat/sonarqube-entity-integration

Conversation

@kavix

@kavix kavix commented Jul 1, 2026

Copy link
Copy Markdown

Purpose

Resolves openchoreo/openchoreo#3935

Currently, developers have to leave the developer portal to check their code quality metrics on SonarQube. This PR integrates the @backstage-community/plugin-sonarqube ecosystem to bring those metrics directly into the entity pages.

Goals

Add a dedicated Code Quality tab to the Backstage entity pages that conditionally renders SonarQube metrics when the sonarqube.org/project-key annotation is present.

Approach

  • Backend Integration: Registered the @backstage-community/plugin-sonarqube-backend plugin in packages/backend/src/index.ts to proxy API requests safely to SonarQube.
  • Frontend Integration:
    • Installed @backstage-community/plugin-sonarqube and @backstage-community/plugin-sonarqube-react in packages/app.
    • Added the <EntitySonarQubeContentPage /> to ServiceEntityPage and GenericComponentEntityPage inside packages/app/src/components/catalog/EntityPage.tsx.
    • Conditionally gated the tab rendering using the isSonarQubeAvailable predicate.
  • Configuration: Documented the required sonarqube config block (expecting baseUrl and apiKey) in app-config.yaml.
Screenshot 2026-08-12 at 4 50 41 PM

User stories

As a developer, I want to see my component's SonarQube code quality metrics directly on its Backstage entity page, so that I can easily track technical debt, bugs, and coverage without context-switching.

Release note

Add SonarQube integration to display code quality metrics on Backstage entity pages.

Documentation

N/A - Standard Backstage community plugin integration. The required sonarqube configuration block has been documented in app-config.yaml as part of this PR.

Training

N/A

Certification

N/A - No impact on certification exams.

Marketing

N/A

Automation tests

  • Unit tests

    Validated component rendering using existing standard yarn test passes for the app package.

  • Integration tests

    N/A

Security checks

Samples

N/A

Related PRs

N/A

Migrations (if applicable)

N/A

Test environment

  • Node environment
  • Tested locally on MacOS against a standard Chrome browser.

Learning

Leveraged the Backstage community patterns for conditional entity page rendering using the plugin's built-in isSonarQubeAvailable hook to ensure the Code Quality tab only appears for annotated entities (matching the pattern used by the Jenkins and GitLab integrations).

Summary by CodeRabbit

  • New Features

    • Added SonarQube integration for viewing code quality metrics.
    • Added a “Code Quality” tab to service and component pages when a SonarQube project is configured.
    • Added documented configuration options for connecting to SonarQube.
  • Bug Fixes

    • Improved release browsing stability.
    • Updated observability log tests to provide the required routing context.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kavix, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 63272155-7c5a-425d-be1d-78c8aa328324

📥 Commits

Reviewing files that changed from the base of the PR and between 4d5c528 and b7e3431.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • packages/backend/package.json
  • packages/backend/src/index.ts
  • packages/backend/src/sonarqube.test.ts
  • packages/backend/src/sonarqube.ts
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated changes to LogsTable test routing and ReleaseBrowserDialog effect dependencies outside the SonarQube objectives. Remove the unrelated test and effect-dependency changes, or move them into separate pull requests.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy all coding acceptance criteria for issue #3935, including backend registration, frontend dependencies, conditional rendering, and configuration documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding SonarQube integration to entity pages.
Description check ✅ Passed The description covers the required sections and clearly explains the purpose, implementation, testing, security checks, and release impact.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LakshanSS LakshanSS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kavix Thanks for the PR! Looks like the Prettier formatting check failed.

@kavix
kavix force-pushed the feat/sonarqube-entity-integration branch from 3878d19 to 7d232a3 Compare July 1, 2026 04:33
@kavix

kavix commented Jul 1, 2026

Copy link
Copy Markdown
Author

@kavix Thanks for the PR! Looks like the Prettier formatting check failed.

Thanks! I've run Prettier locally to fix the formatting issues, amended the commit with the required DCO sign-off, and updated the PR. Everything should be passing now!

@kavix
kavix requested a review from LakshanSS July 1, 2026 04:35
@stefinie123

stefinie123 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@kavix Please attach a screenshot of Portal UI how it looks like with the SonarQube plugin

Also take a pull from the main branch, there are conflicts in the yarn.lock file

@LakshanSS LakshanSS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kavix Kind reminder on this

@kavix
kavix force-pushed the feat/sonarqube-entity-integration branch from 7d232a3 to 4d5c528 Compare August 12, 2026 11:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/src/index.ts`:
- Around line 31-32: Update the backend initialization around the SonarQube
plugin registration to avoid calling its setup when the `sonarqube`
configuration is absent; conditionally register `plugin-sonarqube-backend` only
when the configuration exists, or otherwise handle the missing configuration
before initialization. Add a startup test covering configuration without a
`sonarqube` section and verify the backend starts successfully.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fffb90ab-4c44-4b55-8f5a-4041a9bb4ae5

📥 Commits

Reviewing files that changed from the base of the PR and between eb94bf1 and 4d5c528.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • .changeset/sonarqube-entity-integration.md
  • app-config.yaml
  • packages/backend/package.json
  • packages/backend/src/index.ts
  • packages/portal-app/package.json
  • packages/portal-app/src/apis.ts
  • packages/portal-app/src/components/catalog/EntityPage.tsx
  • plugins/openchoreo-observability/src/components/RuntimeLogs/LogsTable.test.tsx
  • plugins/openchoreo/src/components/Environments/components/ReleaseBrowserDialog.tsx

Comment thread packages/backend/src/index.ts Outdated
Comment on lines +31 to +32
// SonarQube: Proxies metrics API. Self-disables when sonarqube config is absent.
backend.add(import('@backstage-community/plugin-sonarqube-backend'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT

metadata="$(curl -fsSL 'https://registry.npmjs.org/@backstage-community%2Fplugin-sonarqube-backend/1.1.1')"
tarball="$(printf '%s' "$metadata" | jq -r '.dist.tarball')"

curl -fsSL "$tarball" -o "$tmp_dir/plugin.tgz"
tar -xzf "$tmp_dir/plugin.tgz" -C "$tmp_dir"

rg -n "getConfig\\(['\"]sonarqube['\"]\\)|getOptionalConfig\\(['\"]sonarqube['\"]\\)|self.?disab" "$tmp_dir/package" || true
rg -n "^[[:space:]]*sonarqube:" --glob 'app-config*.yaml' . || true

Repository: openchoreo/backstage-plugins

Length of output: 18509


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- backend registration ---'
cat -n packages/backend/src/index.ts | sed -n '20,40p'

printf '%s\n' '--- SonarQube configuration references ---'
rg -n -C 2 'sonarqube' --glob 'app-config*.yaml' --glob '!node_modules' . || true

printf '%s\n' '--- package metadata and runtime entrypoints ---'
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
metadata="$(curl -fsSL 'https://registry.npmjs.org/@backstage-community%2Fplugin-sonarqube-backend/1.1.1')"
printf '%s\n' "$metadata" | jq -r '.version, .main, .module, .types, .dist.tarball'
tarball="$(printf '%s' "$metadata" | jq -r '.dist.tarball')"
curl -fsSL "$tarball" -o "$tmp_dir/plugin.tgz"
tar -xzf "$tmp_dir/plugin.tgz" -C "$tmp_dir"

printf '%s\n' '--- configuration access in distributed JavaScript ---'
rg -n -C 8 'getConfig\("sonarqube"\)|getConfig\('\''sonarqube'\' \)' "$tmp_dir/package/dist" || true

printf '%s\n' '--- plugin startup exports ---'
rg -n -C 5 'createRouter|createBackendPlugin|DefaultSonarqubeInfoProvider|fromConfig' "$tmp_dir/package/dist" | head -120 || true

Repository: openchoreo/backstage-plugins

Length of output: 2331


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT

metadata="$(curl -fsSL 'https://registry.npmjs.org/@backstage-community%2Fplugin-sonarqube-backend/1.1.1')"
tarball="$(printf '%s' "$metadata" | jq -r '.dist.tarball')"
curl -fsSL "$tarball" -o "$tmp_dir/plugin.tgz"
tar -xzf "$tmp_dir/plugin.tgz" -C "$tmp_dir"

printf '%s\n' '--- package metadata ---'
cat "$tmp_dir/package/package.json" | jq '{version,main,dependencies,peerDependencies}'

printf '%s\n' '--- configuration access ---'
rg -n -C 10 'getConfig\("sonarqube"\)|getOptionalConfig\("sonarqube"\)' "$tmp_dir/package/dist" || true

printf '%s\n' '--- provider construction and backend registration ---'
rg -n -C 8 'DefaultSonarqubeInfoProvider|fromConfig|createBackendPlugin|createRouter' "$tmp_dir/package/dist/index.cjs.js" "$tmp_dir/package/dist/service" | head -160 || true

Repository: openchoreo/backstage-plugins

Length of output: 38844


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT

metadata="$(curl -fsSL 'https://registry.npmjs.org/@backstage-community%2Fplugin-sonarqube-backend/1.1.1')"
tarball="$(printf '%s' "$metadata" | jq -r '.dist.tarball')"
curl -fsSL "$tarball" -o "$tmp_dir/plugin.tgz"
tar -xzf "$tmp_dir/plugin.tgz" -C "$tmp_dir"

printf '%s\n' '--- distributed files ---'
find "$tmp_dir/package/dist" -maxdepth 2 -type f -printf '%P\n' | sort

printf '%s\n' '--- package entrypoint ---'
wc -l "$tmp_dir/package/dist/index.cjs.js"
cat -n "$tmp_dir/package/dist/index.cjs.js" | sed -n '1,240p'

printf '%s\n' '--- source-map source names ---'
if [ -f "$tmp_dir/package/dist/index.cjs.js.map" ]; then
  jq -r '.sources[]' "$tmp_dir/package/dist/index.cjs.js.map"
  jq -r '.sourcesContent[]' "$tmp_dir/package/dist/index.cjs.js.map' 2>/dev/null || true
fi

Repository: openchoreo/backstage-plugins

Length of output: 833


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT

metadata="$(curl -fsSL 'https://registry.npmjs.org/@backstage-community%2Fplugin-sonarqube-backend/1.1.1')"
tarball="$(printf '%s' "$metadata" | jq -r '.dist.tarball')"
curl -fsSL "$tarball" -o "$tmp_dir/plugin.tgz"
tar -xzf "$tmp_dir/plugin.tgz" -C "$tmp_dir"

printf '%s\n' '--- plugin bundle ---'
wc -l "$tmp_dir/package/dist/plugin.cjs.js"
cat -n "$tmp_dir/package/dist/plugin.cjs.js" | sed -n '1,220p'

printf '%s\n' '--- plugin source map source content ---'
python3 - "$tmp_dir/package/dist/plugin.cjs.js.map" <<'PY'
import json
import sys

with open(sys.argv[1], encoding="utf-8") as stream:
    data = json.load(stream)

for name, content in zip(data.get("sources", []), data.get("sourcesContent", [])):
    print(f"--- {name} ---")
    print(content)
PY

Repository: openchoreo/backstage-plugins

Length of output: 4118


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- resolved Backstage config references ---'
rg -n '`@backstage/config`' --glob 'package.json' --glob '*lock*' . | head -80 || true

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT

metadata="$(curl -fsSL 'https://registry.npmjs.org/@backstage%2Fconfig/1.3.6')"
tarball="$(printf '%s' "$metadata" | jq -r '.dist.tarball')"
curl -fsSL "$tarball" -o "$tmp_dir/config.tgz"
tar -xzf "$tmp_dir/config.tgz" -C "$tmp_dir"

printf '%s\n' '--- ConfigReader.getConfig implementation ---'
rg -n -C 12 'getConfig\(' "$tmp_dir/package/dist" | head -120

Repository: openchoreo/backstage-plugins

Length of output: 50385


Prevent backend startup failure when SonarQube is disabled.

When sonarqube is absent, plugin initialization calls config.getConfig('sonarqube'), which throws before the router is mounted. Handle the absent configuration or register the plugin only when the configuration exists. Add a startup test without a sonarqube section.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/index.ts` around lines 31 - 32, Update the backend
initialization around the SonarQube plugin registration to avoid calling its
setup when the `sonarqube` configuration is absent; conditionally register
`plugin-sonarqube-backend` only when the configuration exists, or otherwise
handle the missing configuration before initialization. Add a startup test
covering configuration without a `sonarqube` section and verify the backend
starts successfully.

Signed-off-by: Kavindu Sachinthe <kavix@yahoo.com>
@kavix
kavix force-pushed the feat/sonarqube-entity-integration branch from 4d5c528 to b7e3431 Compare August 12, 2026 12:09
@kavix

kavix commented Aug 12, 2026

Copy link
Copy Markdown
Author

@kavix Please attach a screenshot of Portal UI how it looks like with the SonarQube plugin

Also take a pull from the main branch, there are conflicts in the yarn.lock file

attached the screenshot showing how the Portal UI looks with the SonarQube plugin.

@kavix
kavix requested a review from LakshanSS August 12, 2026 12:21
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.

Add SonarQube integration to entity pages

3 participants