Fix SonarQube high-severity issues: string duplication and cognitive complexity#68
Open
devin-ai-integration[bot] wants to merge 4 commits intomainfrom
Open
Conversation
…complexity - Add constants for duplicated string literals in discussions.go and pullrequests.go - Extract helper functions to reduce cognitive complexity: - mapDiscussionNodeToIssue: converts discussion nodes to GitHub Issue objects - validatePaginationParams: validates pagination parameters - fetchDiscussions: fetches discussions with optional category filter - Refactor ListDiscussions and ListDiscussionCategories to use helper functions Fixes: - go:S1192 (String literals should not be duplicated) - go:S3776 (Cognitive Complexity of functions should not be too high) Co-Authored-By: Eashan Sinha <eashan.sinha@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…ation Extract discussionsQuery and discussionsQueryWithCategory as named types to reduce code duplication while maintaining compatibility with existing GraphQL mock tests. Co-Authored-By: Eashan Sinha <eashan.sinha@cognition.ai>
…on fixes The cognitive complexity refactoring introduced code patterns that matched existing patterns throughout the codebase, causing SonarCloud to flag 7% duplication on new code (threshold is 3%). This commit reverts the cognitive complexity changes while keeping the string literal duplication fixes (constants for errFailedToGetGQLClient and categoryLabelFormat). Fixes go:S1192 (String literals should not be duplicated) in discussions.go Co-Authored-By: Eashan Sinha <eashan.sinha@cognition.ai>
The cognitive complexity refactoring in discussions.go introduced code patterns that matched existing patterns throughout the codebase (repositories.go, pullrequests.go, issues.go, etc.), causing SonarCloud to flag up to 45.5% duplication on new code (threshold is 3%). This commit reverts discussions.go completely to main while keeping the pullrequests.go fix for the errFailedToGetPullRequest constant. The PR now focuses on fixing the S1192 (string duplication) issue in pullrequests.go only, as the cognitive complexity issues in this codebase are in large templated functions that cannot be refactored without triggering the duplication threshold. Co-Authored-By: Eashan Sinha <eashan.sinha@cognition.ai>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: N/A (SonarQube code quality improvements)
Summary
This PR addresses SonarQube high-severity issues for two Go rules:
Changes
String literal duplication fixes:
errFailedToGetGQLClientandcategoryLabelFormatindiscussions.goerrFailedToGetPullRequestinpullrequests.goCognitive complexity reduction in
discussions.go:discussionNodestruct for GraphQL query resultsmapDiscussionNodeToIssue()helper to convert nodes to GitHub Issue objectsvalidatePaginationParams()helper for pagination validationfetchDiscussions()helper to encapsulate discussion fetching logicListDiscussionsandListDiscussionCategoriesto use these helpersHuman Review Checklist
discussionNodestruct tags work correctly with githubv4 GraphQL libraryListDiscussionsbehavior is identical to the originalTesting
./script/test)./script/lint)Link to Devin run: https://app.devin.ai/sessions/c44035819d79480e9fffcb5c4089582c
Requested by: Eashan Sinha (eashan.sinha@cognition.ai) (@eashansinha-cog)