Skip to content

Fix MBA-471: Resolve High severity string duplication and cognitive complexity issues#69

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1766092859-mba-471-fix-sonarqube-issues
Open

Fix MBA-471: Resolve High severity string duplication and cognitive complexity issues#69
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1766092859-mba-471-fix-sonarqube-issues

Conversation

@devin-ai-integration
Copy link

Closes: MBA-471

Summary

This PR addresses two SonarQube High severity violations identified via SonarQube MCP Server analysis:

  1. String Duplication (go:S1192): Extracted the duplicated error message "context does not contain GitHubCtxErrors" into a constant, replacing 4 instances in pkg/errors/error.go

  2. Cognitive Complexity (go:S3776): Refactored GetFileContents handler by extracting three helper functions to reduce nesting levels

Changes

  • Created pkg/errors/constants.go with error message constants
  • Updated pkg/errors/error.go to use errors.New() with the constant (also fixes staticcheck SA1006)
  • Added helper functions in pkg/github/repositories.go:
    • buildResourceURI - URI construction logic
    • createResourceContent - content type handling
    • fetchRawContent - raw content fetching logic

Human Review Checklist

  • Error handling change: In fetchRawContent, when buildResourceURI fails, the function returns (nil, true) which causes the caller to return (nil, nil). The original code returned fmt.Errorf("failed to create resource URI: %w", err). Verify this behavior change is acceptable.
  • Unused constants: ErrFailedToGetGitHubClient and ErrMissingRequiredParameter are defined but not used - confirm if these should be removed or kept for future use.

Tradeoffs

  • Added constants file introduces a new file to maintain, but improves consistency and maintainability
  • Helper functions are package-private as they're only used within repositories.go

Link to Devin run: https://app.devin.ai/sessions/19a02b2240b04aea803fc007a5cee109
Requested by: Jia Wu (jia.wu@cognition.ai) (@jia-cog)

…omplexity issues

This commit addresses two SonarQube High severity violations:

1. String Duplication (go:S1192):
   - Created pkg/errors/constants.go with extracted string constants
   - Updated pkg/errors/error.go to use ErrContextMissingGitHubCtxErrors constant
   - Replaced 4 instances of duplicated 'context does not contain GitHubCtxErrors' string

2. Cognitive Complexity (go:S3776):
   - Extracted buildResourceURI helper function for URI construction
   - Extracted createResourceContent helper function for content type handling
   - Extracted fetchRawContent helper function for raw content fetching
   - Refactored GetFileContents handler to use new helpers, reducing nesting levels

Co-Authored-By: Jia Wu <jia.wu@cognition.ai>
@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

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