/xwiki:xwiki-fix-sonarqube-issuefrom xwiki
Finds open SonarCloud issues in an XWiki repo via the REST API, applies rule-specific fixes from a knowledge base, and opens a PR. Requires SONARQUBE_TOKEN and SONARQUBE_PROJECT_KEY.
Ships in xwiki. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Finds open issues via the SonarCloud REST API, fixes them and opens a PR. A failing quality gate
the daily CI sweep (xwiki-ci-check) hands over is fixed here; the sweep attributes it and opens its
PR its own way (its quality-gate reference).
Works in whatever XWiki / xwiki-contrib repo the session runs in. Requires the
SONARQUBE_TOKEN and per-repo SONARQUBE_PROJECT_KEY env vars (see the plugin README). The
SonarCloud organization is xwiki. The repo you are working in is the local clone — read files from
the working copy, never fetch them over a remote API.
The quality of the fix is decided by knowing which sites to DROP, and that knowledge is
rule-specific. It lives in the KB at kb/sonarqube/ (resolve from this skill's directory as
../../kb/sonarqube/; in Claude Code ${CLAUDE_PLUGIN_ROOT}/kb/sonarqube/, in Kimi Code
${KIMI_SKILL_DIR}/../../kb/sonarqube/, in opencode $XWIKI_LLM_HOME/xwiki/kb/sonarqube/).
kb/sonarqube/index.md first — the rule → family-file map, the rules never worth
fixing, and the drop conditions that apply to every rule.kb/sonarqube/verification.md before building.kb/conventions/, not in kb/sonarqube/ — and the index entry will say so. Logging rules
(S2629, S2589 on log guards, anything about what to pass a logger) are owned by
kb/conventions/logging.md; follow the pointer before deciding the fix.A fix applied without its family file is how a batch ships an infinite recursion (S3878), a dead
reflective callback (S1185), or an NPE on a null enum key (S1640) — all of which compile cleanly.
A fix applied without the convention file is how a batch "removes a redundant toString()" from a
log call and silently changes what gets written into the job log.
The cost here is almost entirely file reads while evaluating candidates. Rules:
issueStatuses=OPEN filter is load-bearing — it is what hides the issues an open PR has
already claimed):
curl -s -u "$SONARQUBE_TOKEN:" "https://sonarcloud.io/api/issues/search?organization=xwiki&componentKeys=$SONARQUBE_PROJECT_KEY&issueStatuses=OPEN&severities=BLOCKER,CRITICAL&facets=rules&ps=1"
For an exact per-rule count read the response total from a &rules=java:SXXXX&ps=1 query, not a
facet value.kb/sonarqube/index.md, safest family first, and query it explicitly with
&rules=java:SXXXX. Start with BLOCKER, then CRITICAL, then lower — but this is guidance, not a
gate: a clean MAJOR fix beats forcing a risky higher-severity one, and the mechanical
BLOCKER/CRITICAL pool is frequently exhausted.Explore subagent when you must read and reject several candidates. It
lists candidates, reads local snippets, rejects unsuitable ones, and returns ONLY the chosen issue
key + the ~15-line snippet + its file path. Rejected candidates' file content stays in the subagent
and never reaches the main thread — this is the single biggest token lever. For a single mechanical
candidate, an inline Read with offset/limit is cheaper than spawning one.Read on the working copy with offset/limit for ~15 lines
around the flagged line (the issue gives line and textRange). Never read a whole file to
evaluate a candidate; never fetch file contents over a GitHub/remote API.groupId:artifactId:path, which has TWO colons. The file path is
component.split(':')[-1] — splitting on the first colon is wrong and every file open then fails.
Collect issue keys by a substring of the full component path
(.../xwiki-platform-chart-macro/...), not a guessed short module name, which silently returns 0.flows/locations arrays. Pipe every
issues/search response through jq/python3 and keep only key,rule,component,line,message,effort.
Never dump a raw response into context.gh pr list --search "is:pr is:open in:title SonarQube OR SonarCloud" (the title convention
below). Scope the off-limits check by (rule + module), not rule alone — a per-module PR only
claims the files it touched. But a same-file open PR is off-limits even for a different rule,
because a concurrent edit risks a merge conflict."…/issues/search?componentKeys=<the issue's full component>&resolved=false&ps=100" — then compare
with the lines your edit touches. A rewrite SonarCloud cannot match re-dates those findings into the
new-code period and can turn the master quality gate red although you introduced nothing (see
kb/sonarqube/verification.md). Fix them in the same PR, or pick another site.ps=5), read only the top candidate's
snippet, and accept it unless the snippet disqualifies it. Do not pre-read multiple candidates.The failure mode to design against is a silent mis-edit: a wrong mechanical fix usually still compiles, so the build will not catch it.
Edit calls. For each
(file, old, new) triple, assert content.count(old) == 1 first — that catches a stale,
drifted or ambiguous target — and write nothing if any assertion fails. Validate every edit
(occurrence count + resulting line lengths) before writing anything: if an assertion fires mid-loop,
some files are already written.old a verbatim
multi-line block asserted to occur exactly once. That beats delegating, because the assertions are
the verification. Dump the snippets once (±6 lines around every flagged line, grouped per module),
write the script, dry-run it printing - old / + new per site, then re-run with a write flag.Edit's replace_all matches only the exact indentation you typed and silently leaves the same
pattern at other depths — prefer the script, and grep for the residual pattern after any batch
replace.api/project_analyses/search?project=…&ps=1 → analyses[0].date against git log -1 --format=%ci.
If the checkout is ahead, line numbers have drifted and a line-keyed old will silently not match
— locate each site by the code pattern or by the Sonar message (which names the method, field or
constant) instead.total. This is the most robust anti-drift
technique and needs no snippet reads.if, an instanceof line with several casts, a class-level test-visibility flag), so assert the
sum against the Sonar total and build the accept list by key, not by edit count.old goes stale once the first applies.old is not found there, grep the file for
the actual token.src/main because Checkstyle excludes those files.Logger inside LoggerFactory.Explore, which cannot edit — over disjoint files. Never trust a subagent's
self-reported "converted": it routinely reports, with a plausible rationale, editing a file it
never touched, and a missed site still compiles. Afterwards, cross-check the exact expected file set
against git diff --name-only, apply the missed sites yourself, and re-grep the pre-fix pattern
across changed files — only intentional keeps should remain.@SuppressWarnings, False positive,
Accepted) is the last resort and is the developer's call — see Before retiring an issue below.-DskipTests, always
-Plegacy,quality. See kb/sonarqube/verification.md and the xwiki-build skill.gh. For commit/PR conventions use the xwiki-pull-request skill; SonarQube
fixes normally have no JIRA issue, so use [Misc] <description> with the word "SonarQube" in it:
[Misc] <short description of the problem; mention SonarQube>
* <optional detail bullets>
llm-agent label when running as the scheduled routine (rule in xwiki-pull-request).kb/sonarqube/verification.md.A reviewer saying "this feels wrong" about a mechanical rule usually means the rule is a bad fit for that kind of code, not that the transformation is broken. Verify the mechanism so the record is accurate, then judge whether the objection is about intent clarity — if it is, it stands even when the change is provably behaviour-preserving. Withdraw rather than argue: reply with the clarification and close the PR.
Then do not stop at closing it. Ship the @SuppressWarnings + rationale version as its own PR,
and narrow the rule's entry in kb/sonarqube/ to the code shape that provoked the objection — do
not blanket-denylist a rule that is fine elsewhere.
Calling a finding a false positive — or "real but not worth fixing" — is the cheapest thing you can do and the one that hides it forever. So before proposing it, work out what would make the rule stop firing because the code no longer has the shape it objects to, and put those options to the developer:
try, a boolean flag parameter, a field that only exists for a serialization contract). Changing
it clears this finding and every future one on the same shape.-legacy — the xwiki-legacy skill owns that move, xwiki-knowledge the @since /
@Deprecated(since = …) strings.[Misc].Propose, do not decide. Present the viable options with, for each, what it changes, roughly what it costs, and what it risks (backward compatibility, blast radius) — then let the developer choose, suppression included. Never apply a suppression or a SonarCloud transition on your own judgment.
Retiring in the code is right when the developer picks it, and when the analyser is simply wrong
about the code — it cannot see reflective dispatch, XStream serialization or a cross-module contract.
Then the // comment says why the analyser is wrong, per kb/conventions/code-style.md, and the
suppression goes in the code, not only in SonarCloud.
Accept the issues the PR fixes, as a claim on them. Discovery filters on issueStatuses=OPEN,
so an issue left open while a PR already handles it is picked up and fixed a second time by the next
sweep. Accepting is what reserves it. SonarCloud still closes it as FIXED on its own at the next
branch analysis after the merge — a @SuppressWarnings fix included, since the rule then stops
raising it. Turning a red quality gate green before the merge is a separate question and is the
developer's call — ask.
A claim is provisional: whatever the PR stops covering goes back to OPEN. Reopen every issue it claimed when the PR is closed or abandoned, and exactly the dropped sites' issues when review or a quality-gate condition narrows it. A stale Accepted is worse than never having claimed: neither a later sweep nor a developer browsing open issues will ever see that finding again.
Transition a finding the code keeps as it is with the same call — falsepositive for one that is
wrong, accept for one that is real but deliberately not worth fixing — once the developer has
chosen that over the prevention options above, and with a comment saying why:
curl -s -u "$SONARQUBE_TOKEN:" -X POST "https://sonarcloud.io/api/issues/add_comment" \
--data-urlencode "issue=$ISSUE_KEY" --data-urlencode "text=$MESSAGE"
curl -s -u "$SONARQUBE_TOKEN:" -X POST "https://sonarcloud.io/api/issues/do_transition" \
--data-urlencode "issue=$ISSUE_KEY" --data-urlencode "transition=accept"
Releasing a claim is the same call with transition=reopen. (The sonarqube MCP server's
change_sonar_issue_status is an alternative to the transition call, with status accept,
falsepositive or reopen.)
For many issues: each one costs ~2 requests, so a 20+ issue loop will blow a short command timeout —
run it in the background and make it idempotent by re-querying which keys are still OPEN.
do_transition's response does not reliably contain an issues key (indexing into it raises,
even though the transition applied) — confirm separately with issues/search?issues=<keys> and
re-POST for any straggler.
A durable, generic fact about when a rule's fix is wrong in XWiki belongs in kb/sonarqube/ —
offer to add it via the xwiki-knowledge EXTEND flow (a reviewed PR, never a silent write). Volatile
facts — how many issues a rule has, which module they cluster in, which pools are drained — do not
belong there; they are stale within days.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub xwiki/xwiki-dev-llm --plugin xwiki38 skills in this plugin
/xwiki-backportBackport any change (bug fix, feature, refactor, or test) to an older branch of an XWiki repo (xwiki-platform / xwiki-commons / xwiki-rendering / xwiki-contrib). Cherry-pick `-x` the source commit(s) into a worktree, ADAPT the result to the older branch (module pom versions, Java level, `@since` tags, data migration versions and skip ranges, style/API divergence), verify it compiles against that branch, and push / open a PR. Use whenever a commit that exists on one branch needs to be applied to an older/maintenance branch. For the `testneeded`-labelled test sweep use xwiki-backport-testneeded (which builds on this skill); for Maven commands use xwiki-build; for PR/commit conventions use xwiki-pull-request; for the versioning/`@since` conventions (the format and what carries `@since`) use xwiki-knowledge./xwiki-backport-testneededBackport the automated test of one JIRA issue labelled `testneeded` to the currently-supported stable branches, adjust its `@since` tags across all branches, and open the PRs. Use when asked to backport the test of a given testneeded issue, or to catch a stable branch up with a recently-added test. (For several issues at once, the user will say so — then apply this per issue.) This is the test-specific layer on top of xwiki-backport (which owns the generic cherry-pick / adapt-to-branch / verify mechanics — including the mandatory pom-version, Java-version and `@since` checks). For Maven use xwiki-build; for PR/commit conventions use xwiki-pull-request; for the `@since` rules use xwiki-knowledge; for querying JIRA (the testneeded sweep) use xwiki-jira.