Skip to content

Conversation

@devin-ai-integration
Copy link

Summary

Resolves code duplication by extracting repeated string literals into constants, addressing the 29% code duplication identified in SonarQube analysis.

Changes

  • Created pkg/github/constants.go with centralized error messages and parameter descriptions
  • Replaced duplicate string literals across 11 files with constants:
    • "failed to get GitHub client: %w"ErrFailedToGetGitHubClient
    • "failed to marshal response: %w"ErrFailedToMarshalResponse
    • "failed to read response body: %w"ErrFailedToReadResponseBody
    • "Repository owner"ParamRepositoryOwner
    • "Repository name"ParamRepositoryName
    • "Pull request number"ParamPullRequestNumber
    • "The unique identifier of the workflow run"ParamWorkflowRunID
    • "The number of results per page (max 100)"ParamResultsPerPage
    • "The page number of the results to fetch"ParamPageNumber
  • Removed duplicate constants from actions.go and consolidated with main constants file

Testing

  • ✅ All tests pass (go test ./...)
  • ✅ Code compiles successfully (go build ./...)
  • ✅ No breaking changes to functionality

Review Focus

Please pay special attention to:

  1. Import statements - Verify all modified files properly import the constants
  2. String replacement accuracy - Spot check that hardcoded strings were correctly replaced with appropriate constants
  3. Missed duplications - Check if any duplicate strings remain in the codebase
  4. Constants file structure - Ensure the new constants follow Go naming conventions

Tradeoffs

  • Maintainability vs. Brevity: Slightly increases verbosity in individual files but significantly improves maintainability by centralizing common strings
  • Search and Replace Risk: Large-scale automated replacements carry inherent risk of errors, mitigated by comprehensive testing

Link to Devin run: https://app.devin.ai/sessions/f89f0b3ffdfe44b28208818907af7126
Requested by: @eashansinha

This addresses the SonarQube code quality analysis findings and should significantly reduce the reported 29% code duplication in the repository.

devin-ai-integration bot and others added 2 commits September 22, 2025 17:21
- Created pkg/github/constants.go with common error messages and parameter descriptions
- Replaced 'failed to get GitHub client: %w' with ErrFailedToGetGitHubClient constant
- Replaced 'failed to marshal response: %w' with ErrFailedToMarshalResponse constant
- Replaced 'failed to read response body: %w' with ErrFailedToReadResponseBody constant
- Replaced 'Repository owner' with ParamRepositoryOwner constant
- Replaced 'Repository name' with ParamRepositoryName constant
- Replaced 'Pull request number' with ParamPullRequestNumber constant
- Replaced 'The unique identifier of the workflow run' with ParamWorkflowRunID constant
- Removed duplicate constants from actions.go and consolidated with main constants.go

This addresses the 29% code duplication identified in SonarQube analysis and improves code maintainability.

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
- Replace remaining instances of 'The number of results per page (max 100)' with ParamResultsPerPage constant
- Replace 'The page number of the results to fetch' with ParamPageNumber constant

This completes the code duplication resolution identified in SonarQube analysis.

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.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

devin-ai-integration bot and others added 5 commits September 22, 2025 17:23
- Replace last hardcoded 'Repository name' string with ParamRepositoryName constant
- This completes the code duplication resolution task

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
- Replace remaining instances of 'Sort order' with ParamSortOrder constant in issues.go and search.go
- This addresses additional string literal duplication identified in SonarQube analysis

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
- Create WithPaginationPerPage() helper for functions expecting per_page parameters
- Replace remaining custom parameter definitions with helper functions
- Update toolsnaps to match new pagination schemas
- Ensure actions.go and GetIssueComments use per_page parameters
- Ensure all other functions use standard perPage parameters with constraints
- All tests now pass with consistent pagination schemas

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
- Replace remaining hardcoded parameter descriptions with constants
- Ensure consistent use of ParamRepositoryOwner, ParamRepositoryName, etc.
- Address duplication in code_scanning.go, notifications.go, pullrequests.go, repositories.go, secret_scanning.go

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
…duplication

- Replace repetitive MCP tool creation patterns with CreateBasicTool, CreateWorkflowTool, CreateWorkflowIDTool helpers
- Standardize error handling with HandleStandardToolError and ValidateWorkflowParams/ValidateWorkflowIDParams
- Remove duplicate ToBoolPtr function from tools.go (already exists in constants.go)
- Significantly reduce structural duplication in parameter definitions and validation patterns
- Target SonarCloud duplication reduction from 53.9% to ≤3% on new code

Co-Authored-By: Eashan Sinha <eashan.sinha@codeium.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
30.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

1 participant