Fix SonarQube critical issues: string duplication and cognitive complexity #40
  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.
  
    
  
    
Summary
Fixes two critical SonarQube code quality issues identified in the codebase:
GetCodeScanningAlertfunction (complexity 17, threshold 15)Changes Made
1. String Duplication Fix (go:S1192)
pkg/github/constants.gowithErrFailedToReadResponseBodyconstantcode_scanning.go(2 occurrences)issues.go(6 occurrences)notifications.go(4 occurrences)pullrequests.go(15 occurrences)repositories.go(12 occurrences)repository_resource.go(1 occurrence)search.go(3 occurrences)search_utils.go(1 occurrence, special handling)secret_scanning.go(2 occurrences)2. Cognitive Complexity Fix (go:S3776)
validateResponseAndReadBodyhelper function incode_scanning.goGetCodeScanningAlertto use the helper, reducing complexity from 17 to below 15ListCodeScanningAlertsfor consistencyTesting
./script/lint- 0 issues./script/test- All tests passingReview Checklist
Critical areas to review:
code_scanning.go): Verify the dual return value handling is correct"%s: "+ErrFailedToReadResponseBodypattern - confirm this is acceptablefmt.Errorf(ErrFailedToReadResponseBody, err)correctly formats the error with%wNice to have:
Tradeoffs
"%s: "+ErrFailedToReadResponseBodyinstead of extracting a separate constant. This was chosen to maintain the error prefix pattern while still using the constant.code_scanning.gorather than a shared utilities file. Could be moved to a common location if other files would benefit from it.Link to Devin run
https://app.devin.ai/sessions/edb413c51d3f4c0ab35658c626c0c9b1
Requested by: Zoheb Munshi (@zohebmunshi)