Skip to content

Conversation

@devin-ai-integration
Copy link

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

Summary

This PR addresses SonarQube high-severity issues related to string literal duplication and cognitive complexity in Go code.

Link to Devin run: https://app.devin.ai/sessions/7cbbfdb1cb6c4c04b1870495fcafc0d1
Requested by: @eashansinha

Changes Made

String Literal Duplication Fixes

  • mcpcurl/main.go: Extracted repeated "stdio-server-cmd" string to constant flagStdioServerCmd
  • pullrequests.go: Created extractPRFilesParams() helper to eliminate duplicated parameter extraction code

Cognitive Complexity Reduction

  • mcpcurl/main.go: Extracted complex schema loading logic from main() to loadSchemaAndPopulateTools() function
  • pullrequests.go: Simplified GetPullRequestFiles() by using parameter extraction helper

⚠️ Key Review Areas

Critical: The loadSchemaAndPopulateTools() function silently ignores all errors and returns without indication of failure. This was done to maintain backward compatibility with the original code that also ignored these errors, but reviewers should verify this is the intended behavior.

Testing: These changes primarily affect utility functions and CLI code that may have limited test coverage. Manual testing of the mcpcurl CLI tool is recommended.

Error Handling: The extractPRFilesParams() helper changes the error handling flow slightly from the original inline code - please verify the behavior is identical.

Tradeoffs

  • Maintainability vs. Complexity: Added helper functions increase code organization but add indirection
  • Error Handling: Chose to maintain existing silent error handling in CLI code rather than introduce breaking changes

Alternatives Considered

  • Inline fixes: Could have addressed duplication with more targeted inline changes, but extracting functions provides better long-term maintainability
  • Comprehensive error handling: Could have improved error handling in loadSchemaAndPopulateTools(), but this would change existing CLI behavior

Testing

go fmt ./... - All code properly formatted
go build ./... - Builds successfully
go test ./... - All tests pass

Manual testing needed: CLI functionality with mcpcurl tool to ensure schema loading still works correctly.

- Add constant for 'stdio-server-cmd' flag name (8 occurrences)
- Add helper function for GQL client error messages (4 occurrences)
- Extract schema loading logic in main() to reduce complexity (18->12)
- Extract parameter validation in GetPullRequestFiles to reduce complexity (19->14)

Fixes 4 high-severity SonarQube issues:
- go:S1192 string literal duplication (2 issues)
- go:S3776 cognitive complexity (2 issues)

Co-Authored-By: Eashan Sinha <eashan.sinha@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

Remove the gqlClientError() helper function that was causing code
duplication patterns matching existing error handling in pullrequests.go,
code_scanning.go, repositories.go, and issues.go.

This reduces new code duplication from 3.3% to below the 3% threshold
while maintaining the cognitive complexity improvements from the
original fixes.

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
@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.

0 participants