Skip to content

CLI-963 file level drill down for QG - #830

Merged
Krosovok merged 10 commits into
masterfrom
task/vt/CLI-963-file-level-drill-down
Sep 14, 2026
Merged

Krosovok merged 10 commits into
masterfrom
task/vt/CLI-963-file-level-drill-down

Conversation

@Krosovok

@Krosovok Krosovok commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Quality Gate Status Command:
    • Added optional [file] argument to quality-gate status for file- or directory-level drill down
    • Implemented file-scoped condition evaluation and formatting for coverage and duplication metrics
  • Measures Client:
    • Added getComponentMeasures method and measure value extraction helpers in MeasuresClient

This will update automatically on new commits.

@netlify

netlify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for sonarqube-cli canceled.

Name Link
🔨 Latest commit c1d0658
🔍 Latest deploy log https://app.netlify.com/projects/sonarqube-cli/deploys/6aa7c33cd72d1f00082d1364

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

CLI-963

Comment thread src/commands/quality-gate/status/file-scope-conditions.ts
Comment thread src/commands/quality-gate/status/index.ts Outdated
Comment thread src/commands/command-tree.ts
Comment thread tests/integration/harness/fake-sonarqube-server.ts
Comment thread src/commands/quality-gate/status/format-json.ts Outdated
Comment thread src/commands/quality-gate/status/breakdown.ts Outdated
Comment thread src/commands/quality-gate/status/file-scope-conditions.ts
Comment thread src/commands/quality-gate/status/index.ts Outdated
Comment thread src/commands/quality-gate/status/index.ts
Comment thread src/commands/quality-gate/status/format-json.ts Outdated
@Krosovok
Krosovok force-pushed the task/vt/CLI-963-file-level-drill-down branch from 4ffd29b to 88054c6 Compare September 14, 2026 08:57
@Krosovok
Krosovok marked this pull request as ready for review September 14, 2026 08:59

@kirill-knize-sonarsource kirill-knize-sonarsource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some duplication found.

Comment thread src/commands/quality-gate/status/index.ts Outdated
Comment thread src/commands/quality-gate/status/format-json.ts Outdated
@Krosovok
Krosovok force-pushed the task/vt/CLI-963-file-level-drill-down branch from 19a7684 to c1d0658 Compare September 14, 2026 09:49
@gitar-bot

gitar-bot Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 11 resolved / 11 findings

Adds file- or directory-level drill down to the quality-gate status command with component-level measure fetching and scoped condition evaluation. Multiple issues were resolved including file-scoped verdict handling, measure availability checks, test coverage for reliability/maintainability paths, JSON scope preservation, and export cleanup.

✅ 11 resolved
✅ Bug: File-scoped verdict exits 0 when only unsupported conditions fail

📄 src/commands/quality-gate/status/file-scope-conditions.ts:54-60 📄 src/commands/quality-gate/status/index.ts:229-243 📄 src/commands/quality-gate/status/format-table.ts:99-107
fetchFileScopedConditions keeps only conditions whose metric maps to coverage/duplications (file-scope-conditions.ts:54-57) and buildFileScopedResult derives the verdict solely from that filtered list, ignoring both the dropped conditions and a null/NONE project status. Concretely: a project whose gate only has new_violations/new_security_rating conditions, run as sonar quality-gate status src/foo.ts, prints No conditions apply to this file. with "status": "OK" and exits 0 — a false pass for CI; the same happens when getProjectStatus returns no status at all, where the project path would report NOT_COMPUTED (exit 1). Distinguish "nothing could be evaluated at file level" from "evaluated and clean" (e.g. NOT_COMPUTED plus a warning naming the skipped metrics) instead of silently reporting OK. Note the message also says "file" for a directory argument.

✅ Bug: --category is validated then ignored in the file-scoped path

📄 src/commands/quality-gate/status/index.ts:79-87 📄 src/commands/quality-gate/status/index.ts:106-110 📄 src/commands/quality-gate/status/index.ts:121-130 📄 src/commands/quality-gate/status/index.ts:188-194
FileScopedResultParams has no category field and buildFileScopedResult never receives options.category, so sonar quality-gate status src/foo.ts --category duplications still prints the coverage conditions, and --category issues prints coverage/duplications conditions with no warning — while the project path both filters and warns (No failing conditions match category '…'). Either thread category into fetchFileScopedConditions (filtering applicable by it and warning when nothing matches) or reject --category together with the file argument via InvalidOptionError.

✅ Quality: Generated docs and CLAUDE/AGENTS not updated for the new [file] arg

📄 src/commands/command-tree.ts:310-313
The new positional [file] on quality-gate status is absent from the generated docs: docs/data/commands.json still has "arguments": [] for sonar-quality-gate-status and docs/llms.txt still shows Usage: sonar quality-gate status [-p <value>] [--format <value>] …. CLAUDE.md/AGENTS.md also still describe the command as showing only "the project-level quality gate verdict" and document the shared file resolver as belonging to "any command taking --file", which no longer matches a positional-argument command. Run bun run gen:docs and update the two agent docs with the file/directory scope (including that only coverage/duplications conditions are evaluated).

✅ Quality: Fake component_tree ignores the directory scope, weakening the new test

📄 tests/integration/harness/fake-sonarqube-server.ts:1103-1117 📄 tests/integration/specs/quality-gate/status-file-scope-coverage.test.ts:179-193
The /api/measures/component_tree handler now resolves the project key out of a <project>:<path> component key but still returns componentTreeFilesByMetric for the whole project, ignoring subPath. The directory drill-down test therefore gets the same two entries whether the CLI sends my-project:src/checkout or my-project as component, so the central behaviour this PR adds (params.componentKey ?? params.projectKey in worst-file-entries.ts) is not actually asserted. Filter the configured files by the requested sub-path (or assert the recorded request's component query param) so a regression to project scope fails the test.

✅ Quality: File-scoped JSON drops the branch/pull-request scope

📄 src/commands/quality-gate/status/format-json.ts:40-46 📄 src/commands/quality-gate/status/index.ts:248-251
formatFileQualityGateJson emits only {status, file, conditions}, while the project JSON includes the resolved branch or pull request. Since quality-gate status <file> still accepts --branch/--pull-request (and auto-detects a PR), a consumer parsing the file-scoped JSON cannot tell which branch/PR the measures came from — including the auto-detected case, where the user never named it. Include the scope in the file view model as the project formatter does.

...and 6 more resolved from earlier reviews

Implementation Status ✅ 10 of 10 objectives covered
✅ CLI-963 - 10 of 10 objectives covered

This PR implements file-level drill-down for quality-gate status, covering positional file arguments, metric value reporting, issue listing, --all option handling, error states, and rendering conventions.

✅ 10 covered here
  • ✅ Add a positional file argument to sonar quality-gate status
  • ✅ Show every quality-gate condition applying to the specified file or directory path using its own metric value
  • ✅ List every condition currently failing on the file showing the metric, file value, and threshold
  • ✅ Display coverage and duplications conditions with the file's metric value
  • ✅ List passing conditions on the file when --all is provided
  • ✅ Report clearly when a file has no applicable or failing conditions
  • ✅ Report clearly when a file argument does not exist in the project's file tree
  • ✅ Follow project-level rendering conventions for table and JSON output
  • ✅ Follow standard exit codes for clean, unresolvable file, and failing conditions
  • ✅ Display actual issues on the file including file, line, key, rule, and message
Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

@kirill-knize-sonarsource kirill-knize-sonarsource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@Krosovok
Krosovok merged commit 5dabd07 into master Sep 14, 2026
22 checks passed
@Krosovok
Krosovok deleted the task/vt/CLI-963-file-level-drill-down branch September 14, 2026 10:01
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