Skip to content

CLI-356 Fetch analysis properties for SCA analysis#244

Open
georgii-borovinskikh-sonarsource wants to merge 2 commits intomasterfrom
gb/sca-get-properties
Open

CLI-356 Fetch analysis properties for SCA analysis#244
georgii-borovinskikh-sonarsource wants to merge 2 commits intomasterfrom
gb/sca-get-properties

Conversation

@georgii-borovinskikh-sonarsource
Copy link
Copy Markdown
Contributor

No description provided.

@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod Bot commented May 4, 2026

CLI-356

@sonar-review-alpha
Copy link
Copy Markdown
Contributor

sonar-review-alpha Bot commented May 5, 2026

Summary

This PR implements CLI-356: fetching SCA analysis properties from SonarQube project settings.

What changed:

  • New parseAnalysisProperties() function routes settings into three categories: SCA-prefixed properties, exclusion patterns, and a Git-ignore flag
  • New getProjectSettings() API method fetches settings via /api/settings/values scoped to a project
  • analyzeDependencyRisks() now fetches and parses these properties, logging them for debugging (actual forwarding to SCA scanner is deferred to CLI-352)
  • Refactored SonarQubeClient.get() to use a new non-throwing getSafe() variant, needed because settings endpoints return 404 for missing projects

Why it matters:
The SCA dependency risk analysis needs project-specific configuration (exclusions, SCA properties, SCM settings). This PR lays the foundation by fetching and parsing them from the API. The properties aren't yet forwarded to the scanner—that's planned in CLI-352—but this PR ensures they're available and validated (project existence is checked via 404 handling).

What reviewers should know

Where to focus:

  • parseAnalysisProperties.ts — the core parsing logic; handles both comma-separated and array-based settings, merges multiple exclusion keys
  • client.ts — the API layer changes; getSafe() is the new non-throwing variant, getProjectSettings() wraps it with project-not-found error handling
  • Integration test changes — verify that settings are fetched, that missing projects are detected (404), and that the API calls happen in the right order

Key decisions:

  • getSafe() returns { response, value } instead of throwing, allowing callers to differentiate 404 (project not found) from other errors
  • Settings are parsed separately in parseAnalysisProperties, not mixed into the API layer—clean separation of concerns
  • The parsing handles missing or mixed value formats (arrays, comma-separated strings) gracefully

What to watch:

  • The refactoring of get() to use getSafe() is subtle; verify that error handling still works correctly (check the raiseForStatus logic)
  • getValueAsList() trims and filters empty strings—confirm this is the intended behavior for all setting types
  • The properties are currently logged but not used; this is expected (awaiting CLI-352 to forward them to the scanner)

  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

sonar-review-alpha[bot]

This comment was marked as resolved.

sonar-review-alpha[bot]

This comment was marked as resolved.

sonar-review-alpha[bot]

This comment was marked as outdated.

Base automatically changed from gb/sca-check-sqas-enabled to master May 6, 2026 08:47
sonar-review-alpha[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@damien-urruty-sonarsource damien-urruty-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM, one suggestion to improve performance

Comment on lines +47 to +50
const componentExists = await client.checkComponent(options.project);
if (!componentExists) {
throw new CommandFailedError(`No project: ${options.project}`);
}
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.

Could we avoid this extra round-trip? Do we receive a 404 when we try to get settings for a non-existing project in the call below, and could we rely on that?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

@sonar-review-alpha sonar-review-alpha Bot left a comment

Choose a reason for hiding this comment

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

LGTM! ✅

Clean commit that removes the explicit checkComponent round-trip and instead surfaces a missing project via the 404 from getProjectSettings. The refactoring is correct and the tests were properly updated to match the new behavior.

🗣️ Give feedback

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