Skip to content

fix: address SonarQube high-severity issues (S1192, S3776)#74

Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1768242709-sonarqube-fixes
Open

fix: address SonarQube high-severity issues (S1192, S3776)#74
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1768242709-sonarqube-fixes

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Jan 12, 2026

Closes: N/A (SonarQube code quality improvements)

Summary

This PR addresses 4 high-severity SonarQube issues in the codebase:

S1192 - String literals should not be duplicated:

  • pkg/github/discussions.go: Extracted constants for "Repository owner", "Repository name", error messages, and category label format
  • pkg/github/search.go: Extracted constants for error messages used in response handling

S3776 - Cognitive Complexity should not be too high:

  • pkg/github/discussions.go: Reduced ListDiscussions complexity from 27 to under 15 by extracting helper types and functions
  • cmd/mcpcurl/main.go: Reduced main complexity from 18 to under 15 by extracting loadToolsFromServer helper function

Human Review Checklist

  • Verify fetchDiscussionsWithCategory and fetchDiscussionsWithoutCategory return the same data structure as the original inline queries
  • Confirm gqlDiscussionNode struct tags work correctly with the githubv4 library (the graphql:"category" and graphql:"url" tags)
  • Confirm error handling in loadToolsFromServer matches original behavior (silent failure on errors is intentional)
  • Note: SonarCloud shows 3.4% duplication (slightly above 3% threshold) due to GraphQL library limitation requiring different struct tags for with/without category filter

Tradeoffs

The fetchDiscussionsWithCategory and fetchDiscussionsWithoutCategory functions still have similar structure because the GraphQL library requires different struct tags for queries with and without the categoryId parameter. The refactoring extracts a shared gqlDiscussionNode type and mapping functions to minimize duplication while working within this library constraint.


Link to Devin run: https://app.devin.ai/sessions/85d47417ad75420d9de1c7f194f23da2
Requested by: Abhay Aggarwal (@abhay-codeium)

- S1192: Extract duplicated string literals in discussions.go
  - Added constants for 'Repository owner', 'Repository name',
    'failed to get GitHub GQL client', and 'category:%s'
  - Replaced all occurrences with the new constants

- S1192: Extract duplicated string literals in search.go
  - Added constants for 'failed to read response body' and
    'failed to marshal response' error messages
  - Replaced all occurrences with the new constants

- S3776: Reduce cognitive complexity in discussions.go
  - Extracted discussionNode type and mapDiscussionNodeToIssue helper
  - Extracted fetchDiscussionNodes helper function
  - Reduced ListDiscussions function complexity from 27 to under 15

- S3776: Reduce cognitive complexity in mcpcurl/main.go
  - Extracted loadToolsFromServer helper function
  - Reduced main function complexity from 18 to under 15

Co-Authored-By: Abhay Aggarwal <abhay.aggarwal@codeium.com>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Extract gqlDiscussionNode type to share GraphQL node structure
- Add toDiscussionNode method for consistent conversion
- Add mapGQLNodesToDiscussionNodes helper function
- Split fetchDiscussionNodes into fetchDiscussionsWithCategory and
  fetchDiscussionsWithoutCategory for cleaner separation

This addresses SonarCloud's code duplication check (18.4% -> reduced).

Co-Authored-By: Abhay Aggarwal <abhay.aggarwal@codeium.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

0 participants