Fix MBA-471: Resolve High severity string duplication and cognitive complexity issues#70
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Conversation
…omplexity issues - Address SonarQube rule go:S1192 (String literals should not be duplicated): - Create pkg/errors/constants.go with centralized error message constants - Update pkg/errors/error.go to use ErrContextMissingGitHubCtxErrors constant - Replace 4 duplicated instances of 'context does not contain GitHubCtxErrors' - Address SonarQube rule go:S3776 (Cognitive Complexity of functions should not be too high): - Extract buildResourceURI helper function for URI construction logic - Extract createResourceContent helper function for content type handling - Refactor GetFileContents handler to use new helper functions - Reduce nesting levels and improve code readability Co-Authored-By: Jia Wu <jia.wu@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
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.



Closes: MBA-471
Summary
This PR addresses two High severity SonarQube violations identified via SonarQube MCP Server analysis:
Changes
String Duplication Fix
pkg/errors/constants.gowith centralized error message constantspkg/errors/error.goto useErrContextMissingGitHubCtxErrorsconstant (4 occurrences)fmt.Errorf()toerrors.New()since no format arguments are usedCognitive Complexity Fix
buildResourceURI()helper to centralize URI construction logiccreateResourceContent()helper to handle content type detectionGetFileContentshandler to use these helpers, reducing nesting levelsHuman Review Checklist
ErrFailedToGetGitHubClient,ErrMissingRequiredParameter) in constants.go are acceptable or should be removedresourceContent.(mcp.TextResourceContents)correctly distinguishes text vs binary contentTesting
Link to Devin run: https://app.devin.ai/sessions/cfdc7ca39332402681f75483d8a6be2b
Requested by: Jia Wu (jia.wu@cognition.ai) (@jia-cog)