Fix MBA-471: Resolve High severity string duplication and cognitive complexity issues #34
  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 resolves two High severity SonarQube violations in the codebase:
Changes
1. String Duplication Fix (go:S1192)
Created
pkg/errors/constants.gowith three error message constants:ErrContextMissingGitHubCtxErrors- eliminates 4 duplicate instances inerror.goErrMissingRequiredParameter- eliminates 2 duplicate instances inserver.goErrFailedToGetGitHubClient- added for future consistencyUpdated
pkg/errors/error.go:fmt.Errorf()toerrors.New()to fix staticcheck SA1006 warning (no format verbs in the string)Updated
pkg/github/server.go:pkg/errors(aliased aspkgerrorsto avoid conflict with stdlib)2. Cognitive Complexity Reduction (go:S3776)
Refactored
get_file_contentshandler inpkg/github/repositories.go:Extracted three helper functions to reduce nesting from 5+ levels to 2-3:
tryRawContentFetch()- handles raw content API call and client initializationbuildResourceURI()- constructs resource URI based on sha/ref parameterscreateResourceContent()- creates appropriate resource content type (text vs binary)The refactoring improves code readability and maintainability while preserving all existing functionality.
Testing
./script/test)./script/lint)assert.Contains()work correctly with constant-based errorsReview Checklist
Key areas to review:
get_file_contentslogic behaves identically to the original, especially:Tradeoffs
pkg/githubnow importspkg/errorsfor constants. This is a reasonable design choice that centralizes error messages and improves maintainability.createResourceContent()returns(*mcp.CallToolResult, error)but always returnsnilfor error. This maintains consistency with Go patterns and handler expectations, though the error return is currently unused.Session Details