Skip to content

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Oct 3, 2025

Summary

This PR addresses 4 high-severity SonarQube issues in the github-mcp-server repository:

  • 2 string literal duplication issues
  • 2 cognitive complexity issues

Changes

String Duplication Fixes (pkg/github/search.go)

Issue: String literals "failed to read response body: %w" and "failed to marshal response: %w" were duplicated 3-4 times each.

Solution:

  • Added package-level constants errReadResponseBody and errMarshalResponse
  • Replaced all duplicate occurrences with constant references
  • Reduces maintenance burden and ensures consistency

Cognitive Complexity Reductions

1. cmd/mcpcurl/main.go (Complexity: 18 → <15)

Issue: The main() function had cognitive complexity of 18, exceeding the threshold of 15.

Solution:

  • Extracted schema loading logic into loadSchemaAndGenerateCommands() function
  • Improved error handling with proper error wrapping
  • Made the main function flow more linear and easier to understand

2. pkg/github/search.go (Complexity: 40 → <15)

Issue: The userOrOrgHandler function had cognitive complexity of 40, far exceeding the threshold of 15.

Solution:

  • Extracted parameter extraction into extractSearchParams() function
  • Extracted API call logic into performUserSearch() function
  • Extracted error handling into handleNon200Response() function
  • Extracted result building into buildMinimalSearchResult() function
  • Extracted marshaling into marshalSearchResult() function
  • Each function now has a single, focused responsibility

Testing

  • ✅ All existing tests pass (go test -v ./...)
  • ✅ Linting passes with 0 issues (./script/lint)
  • ✅ SonarCloud analysis passes with 0 new issues and 2.9% duplication (below 3% threshold)
  • ✅ No functional changes - refactoring only

SonarQube Issues Addressed

  1. go:S1192 - String literal "failed to read response body: %w" duplicated 3 times in pkg/github/search.go
  2. go:S1192 - String literal "failed to marshal response: %w" duplicated 3 times in pkg/github/search.go
  3. go:S3776 - Cognitive Complexity of 18 in cmd/mcpcurl/main.go:155
  4. go:S3776 - Cognitive Complexity of 40 in pkg/github/search.go:176

Link to Devin run: https://app.devin.ai/sessions/ceeb3d7d08fd442287dac90a0405cd58

Requested by: Eashan Sinha (eashan.sinha@cognition.ai) (@eashansinha)

@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

…complexity

- Fixed string literal duplication in pkg/github/search.go
  * Added constants for 'failed to read response body: %w' and 'failed to marshal response: %w'
  * Replaced 4 duplicate occurrences with constant references

- Reduced cognitive complexity in cmd/mcpcurl/main.go
  * Refactored main() function from complexity 18 to under 15
  * Extracted schema loading logic into loadSchemaAndGenerateCommands() function

- Reduced cognitive complexity in pkg/github/search.go
  * Refactored userOrOrgHandler from complexity 40 to under 15
  * Extracted parameter extraction into extractSearchParams() function
  * Extracted API call logic into performUserSearch() function
  * Extracted error handling into handleNon200Response() function
  * Extracted result building into buildMinimalSearchResult() function
  * Extracted marshaling into marshalSearchResult() function

All tests pass and linting is clean.

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
@devin-ai-integration devin-ai-integration bot force-pushed the devin/1759474902-fix-sonarqube-issues branch from ac162ee to e5cd66d Compare October 3, 2025 07:06
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 3, 2025

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.

1 participant