Fix MBA-471: Resolve High severity string duplication and cognitive complexity issues #42
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 for the github-mcp-server repository:
pkg/errors/error.go) into a constantget_file_contentshandler inpkg/github/repositories.goby extracting helper functions to reduce nesting levels from 5+ to 2-3SonarQube Rules Addressed:
Changes
1. String Duplication Fix (
pkg/errors/)Created
constants.gowith three error message constants:Updated
error.goto use the constant in 4 locations (lines 75, 83, 99, 107):fmt.Errorf("context does not contain GitHubCtxErrors")tostderrors.New(ErrContextMissingGitHubCtxErrors)errorspackage with alias to avoid naming conflict with package name2. Cognitive Complexity Fix (
pkg/github/)Extracted three helper functions in
repositories.go:tryRawContentFetch(): Handles raw content API call and error checkingbuildResourceURI(): Builds resource URI based on sha/ref parameters using switch statementcreateResourceContent(): Creates appropriate resource content (Text/Blob) based on content typeRefactored
GetFileContentshandler (lines 556-586):Testing
./script/test)./script/lint)error_test.gocontinue to pass (they check for the error message string which is preserved via constant)Review Focus
Critical areas for review:
fmt.Errorf(string)tostderrors.New(string)preserves error handling behaviorGetFileContentsmaintains exact same behavior as beforeErrFailedToGetGitHubClient,ErrMissingRequiredParameter) are defined but not used in this PR per scope limitation to "one issue from each category"Tradeoffs
Notes
Link to Devin run: https://app.devin.ai/sessions/71aa3c9de3904275a1e6b836c17db8f8
Requested by: @jia-cog (Jia Wu)