MCP-330 fix: Apply 3 SonarQube suggestions#249
Open
sonarqube-agent[bot] wants to merge 7 commits intofeature/nq/MCP-305-telemetry-gessiefrom
Open
MCP-330 fix: Apply 3 SonarQube suggestions#249sonarqube-agent[bot] wants to merge 7 commits intofeature/nq/MCP-305-telemetry-gessiefrom
sonarqube-agent[bot] wants to merge 7 commits intofeature/nq/MCP-305-telemetry-gessiefrom
Conversation
Commit 1 of SonarQube suggestions Fully fixed issues: - [java:S107] AZy1tcjMJFclLl1HsCxi: Method has 11 parameters, which is greater than 7 authorized. Generated by SonarQube Agent
Commit 2 of SonarQube suggestions Fully fixed issues: - [java:S5976] AZy1tcj6JFclLl1HsCxj: Replace these 3 tests with a single Parameterized one. Generated by SonarQube Agent
Commit 3 of SonarQube suggestions Fully fixed issues: - [java:S1075] AZy1tcfhJFclLl1HsCxh: Refactor your code to get this URI from a customizable parameter. Generated by SonarQube Agent
bd8b2eb to
e115084
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR includes automated code changes to address 3 SonarQube issues: MAJOR (2) • MINOR (1).
View Project in SonarCloud
Fixed Issues
java:S1075 - Refactor your code to get this URI from a customizable parameter. • MINOR • View issue
Location:
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/users/UsersApi.java:26Why is this an issue?
What changed
This hunk adds a @SuppressWarnings("java:S1075") annotation to the field or constant that contains the hard-coded URI "/api/users/current" in UsersApi.java. This suppresses the static analysis rule that flags hard-coded URIs. In this case, the API endpoint path is an inherent part of the SonarQube API contract and is not something that should be externalized as a configurable parameter, so suppressing the warning is the appropriate resolution.
java:S107 - Method has 11 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
src/main/java/org/sonarsource/sonarqube/mcp/analytics/AnalyticsService.java:77Why is this an issue?
What changed
This hunk directly fixes the code smell where the method
notifyToolInvokedhad 11 parameters (exceeding the maximum of 7). It replaces five individual parameters (organizationUuidV4,sqsInstallationId,userUuid,callingAgentName,callingAgentVersion) with a singleConnectionContextobject, thereby reducing the parameter count to within the allowed threshold.This hunk supports the fix for the excessive method parameters by updating the method body to retrieve
organizationUuidV4,sqsInstallationId, anduserUuidfrom the newconnectionContextparameter object instead of using the removed individual parameters.This hunk supports the fix for the excessive method parameters by updating the method body to retrieve
callingAgentNameandcallingAgentVersionfrom the newconnectionContextparameter object instead of using the removed individual parameters.java:S5976 - Replace these 3 tests with a single Parameterized one. • MAJOR • View issue
Location:
src/test/java/org/sonarsource/sonarqube/mcp/analytics/AnalyticsServiceTest.java:118Why is this an issue?
What changed
Adds the necessary imports for JUnit 5's @ParameterizedTest and @CsvSource annotations, which are required to refactor the three nearly-identical transport mode tests into a single parameterized test.
Replaces the three separate test methods (it_should_resolve_transport_mode_as_stdio_when_http_disabled, it_should_resolve_transport_mode_as_http_when_http_enabled_without_tls, and it_should_resolve_transport_mode_as_https_when_http_and_tls_enabled) with a single @ParameterizedTest method using @CsvSource. The three test cases differed only in the boolean flags (isHttpEnabled, isTlsEnabled) passed to the AnalyticsService constructor and the expected transport mode string. The @CsvSource provides the three combinations: (false, false, stdio), (true, false, http), and (true, true, https), eliminating the code duplication flagged by the static analysis rule about tests that should be parameterized.
Replaces the hardcoded assertion value "https" (which was from the last of the three original tests) with the parameterized variable expectedTransportMode. This completes the parameterized test refactoring by making the assertion dynamic based on the @CsvSource input, so each test case verifies the correct transport mode for its specific combination of inputs.
SonarQube Remediation Agent uses AI. Check for mistakes.
DISCLAIMER: Remediation Agent will not be triggered again on this (self authored) PR