Skip to content

chore: add SonarQube golden path (MCP + pre-commit hook) - #10

Open
caroolcanelas2 wants to merge 3 commits into
mainfrom
feat/sonarqube-mcp-precommit
Open

chore: add SonarQube golden path (MCP + pre-commit hook)#10
caroolcanelas2 wants to merge 3 commits into
mainfrom
feat/sonarqube-mcp-precommit

Conversation

@caroolcanelas2

Copy link
Copy Markdown
Collaborator

What is the purpose of this pull request?

Adopts the VTEX SonarQube golden path in this repository, in two parts:

1. SonarQube MCP (on-demand access from Claude Code / Cursor)

  • .mcp.json at the repo root with the sonarqube server (http://sonarqube.vtex.systems/mcp), read natively by Claude Code.
  • .cursor/mcp.json as a symlink../.mcp.json, keeping a single source of truth for both editors.

2. Secrets-only pre-commit hook (via Husky)

  • scripts/sonar-verify-staged.sh / .ps1 — wrapper that resolves the Sonar CLI and runs sonar hook git-pre-commit (secrets-only scan of staged files).
  • package.json — this repo runs legacy Husky v4 (hook defined inline via the husky.hooks field, no .husky/ directory). Rather than bundling an unrelated Husky major-version migration into this change, the sonar wrapper call was appended to the existing pre-commit string alongside lint-staged.
  • No AGENTS.md/CLAUDE.md exists at the repo root yet, so no doc section was added.

Based on the reference implementations: vtex/data-vault#99 (.NET wiring), vtex/admin-mercadolivre-monorepo#432 (MCP unification), vtex/seller-register-api#521 (secrets-only fix), and vtex/vbase#176 (this exact flow, first .NET repo it landed on).

What problem is this solving?

Standardizes local static analysis (pre-commit gate) and on-demand SonarQube access via MCP, per the VTEX golden path.

Note

About Vortex Agentic Analysis (403) — already worked around. The golden-path command sonar analyze --staged also triggers server-side Vortex Agentic Analysis, which returns 403 Forbidden because most VTEX orgs don't yet have that entitlement (Sonar Agent Essentials). Since the CLI treats that as a failure (exit 1), it would block every commit. This PR wires the hook to sonar hook git-pre-commit (secrets-only) instead — no 403. Code quality stays enforced by the full Sonar scan in CI. The golden-path command is kept commented out in the wrapper scripts, ready to re-enable once the org has the entitlement.

How should this be manually tested?

yarn install

# run the pre-commit hook manually (secrets-only, no 403)
bash scripts/sonar-verify-staged.sh

# direct scan
sonar hook git-pre-commit

# MCP (requires VPN/Netscope): in a new session, mcp__sonarqube__* tools should appear
cat .mcp.json && ls -la .cursor/mcp.json   # .cursor/mcp.json -> ../.mcp.json

Validated locally: clean staged file → commit passes (no 403).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires change to documentation, which has been updated accordingly.

🤖 Generated with Claude Code

Wire a secrets-only Sonar gate into the existing Husky (v4, package.json
config) pre-commit hook via scripts/sonar-verify-staged.sh / .ps1. The
wrapper calls `sonar hook git-pre-commit` rather than the golden-path
`sonar analyze --staged`, since the latter also triggers Vortex Agentic
Analysis which returns 403 for orgs without that entitlement (VTEX
included) and would block every commit. Code quality stays enforced by
the full Sonar scan in CI.
Add a root .mcp.json for the sonarqube MCP server, with .cursor/mcp.json
symlinked to it so Claude Code and Cursor share one config.
No Windows-specific caller wires this hook manager to PowerShell (only
Husky.Net's task-runner.json windows block does that) — the .ps1 was
dead code, never invoked.
@sonar-workflows

Copy link
Copy Markdown

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.

1 participant