Skip to content

fix(security): remediate SonarQube vulnerabilities (S1192, S3776)#81

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1770237080-sonarqube-remediation
Open

fix(security): remediate SonarQube vulnerabilities (S1192, S3776)#81
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1770237080-sonarqube-remediation

Conversation

@devin-ai-integration
Copy link

Closes: N/A (SonarQube remediation task)

Summary

This PR addresses 3 high-severity SonarQube issues by refactoring code to reduce cognitive complexity and eliminate duplicated string literals.

Changes

S1192 - Duplicated string literal (search.go)

  • Extracted the "Sort order" string (used 3 times) to a package-level constant sortOrderDescription

S3776 - Cognitive complexity (search.go:171)

  • Refactored userOrOrgHandler by extracting helper functions:
    • extractUserSearchParams - parameter extraction and validation
    • convertToMinimalUser - GitHub User to MinimalUser conversion
    • buildMinimalSearchResult - result building from search results

S3776 - Cognitive complexity (repository_resource.go:68)

  • Refactored RepositoryResourceContentsHandler by extracting helper functions:
    • extractRequiredStringArg / extractOptionalStringArg - argument extraction
    • extractResourceParams - owner/repo/path extraction
    • setRefOptions - ref option configuration
    • handlePRRef - PR reference handling
    • determineMimeType - MIME type detection
    • buildResourceContents - resource content building
    • handleRawContentResponse - response processing

Human Review Checklist

  • Verify buildMinimalSearchResult is behaviorally equivalent (removed redundant nil checks that were already handled by getter methods)
  • Verify the error check order change in RepositoryResourceContentsHandler (directory check moved earlier) is acceptable
  • Verify the defer resp.Body.Close() placement after error check is correct (prevents potential nil pointer if GetRawContent fails)

Testing

  • All existing tests pass
  • Lint checks pass

Link to Devin run: https://app.devin.ai/sessions/a538bd03d56241b5af15d0c04d9c0a24
Requested by: @parkerduff

- S1192: Extract duplicated 'Sort order' string to sortOrderDescription constant
- S3776 search.go: Reduce cognitive complexity of userOrOrgHandler by extracting:
  - userSearchParams struct for parameter grouping
  - extractUserSearchParams for parameter extraction
  - convertToMinimalUser for user conversion
  - buildMinimalSearchResult for result building
- S3776 repository_resource.go: Reduce cognitive complexity of
  RepositoryResourceContentsHandler by extracting:
  - resourceRequestParams struct for parameter grouping
  - extractRequiredStringArg/extractOptionalStringArg for argument extraction
  - extractResourceParams for parameter extraction
  - setRefOptions for ref option setting
  - handlePRRef for PR reference handling
  - determineMimeType for MIME type detection
  - buildResourceContents for content building
  - handleRawContentResponse for response handling

Co-Authored-By: parker.duff@codeium.com <pwjduff@gmail.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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

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