Fix SonarQube High severity issues: string duplication and cognitive complexity #41
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
This PR addresses two High severity SonarQube issues in
pkg/github/discussions.go:Changes
String Duplication Fix
Added constants for repeated string literals that appeared 3-4 times across the file:
descRepositoryOwner- "Repository owner" (4 occurrences)descRepositoryName- "Repository name" (4 occurrences)errFailedToGetGQLClient- "failed to get GitHub GQL client: %v" (4 occurrences)categoryLabelFormat- "category:%s" (3 occurrences)Cognitive Complexity Reduction
Refactored
ListDiscussionsfunction (complexity 27 → ~10) by extracting shared logic:discussionNodetype for GraphQL response structureconvertDiscussionNodeToIssue()helper to eliminate duplicate mapping codequeryDiscussionsWithCategory()andqueryDiscussionsWithoutCategory()helpers to separate query logicTesting
./script/test)./script/lint)Review Checklist
Critical items to verify:
discussionNodestruct correctly matches both query responses (with/without category filter)convertDiscussionNodeToIssuepreserves all original field mappings and formattingTradeoffs
discussionNode) couples the two query paths, but this is acceptable since they query the same data structureLink to Devin run: https://app.devin.ai/sessions/d642e178617b4b5897327bf05d009d45
Requested by: Shawn Azman (@ShawnAzman)