Features
- Client — quality gate status, measures and their history, component tree, issue search (severity, type, status, branch, pull request, paging, new code), issue facets, hotspots, rules, duplications, quality profiles, source snippets, branches and project search, on global
fetchwith no runtime dependencies - Layered config — config file < environment < explicit options; undefined never overwrites; project key falls back to
sonar-project.properties - "Why is the gate red" —
explainGateturns a project status into a status word, the new-code period and conditions sorted failing first, with*_ratingmetrics shown as A–E - Safe auth — the token is sent as the basic-auth username with an empty password and never appears in errors;
redactTokenandredactConfigare there for your own logging - Typed errors — a missing host throws
MissingHostError; HTTP failures throwSonarQubeHttpError, and a 401 throwsSonarQubeAuthError, which names the env var the token came from when it is known (orSONARQUBE_TOKEN/SONAR_TOKENotherwise; a rejected legacySONARQUBE_DASH_TOKENpoints atSONARQUBE_TOKEN)
Surface-agnostic by design: no CLI, no prompts, no rendering.
Quick start
npm install @kud/sonarqubeimport { SonarQubeClient, resolveConfig } from "@kud/sonarqube"
const config = resolveConfig()
const client = new SonarQubeClient(config)
const why = await client.explainGate({ project: config.project! })
console.log(why.status, why.newCodePeriod)
for (const c of why.conditions)
console.log(c.failing ? "x" : "ok", c.metric, c.actual, c.comparator, c.threshold)