Fix SonarQube High severity issues for string duplication and cognitive complexity #35
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 SonarQube High/Critical severity issues identified in the github-mcp-server repository by fixing code quality issues in two categories:
go:S1192) inpkg/github/discussions.gogo:S3776) inpkg/github/repositories.goChanges
1. Fix String Literal Duplication in discussions.go
Added constants at the package level to eliminate repeated string literals:
descRepositoryOwner = "Repository owner"(4 occurrences)descRepositoryName = "Repository name"(4 occurrences)errGitHubGQLClient = "failed to get GitHub GQL client: %v"(4 occurrences)discussionCategoryLabelFmt = "category:%s"(3 occurrences)These constants are now used consistently across 4 functions:
ListDiscussions,GetDiscussion,GetDiscussionComments, andListDiscussionCategories.2. Reduce Cognitive Complexity in repositories.go
Refactored the
ListCommitsfunction to reduce cognitive complexity from 23 to well below the threshold of 15:listCommitsParamsstruct to encapsulate function parametersparseListCommitsParamshelper functionReview Checklist
Critical items to verify:
PaginationParamstype name is correctly capitalized (was initially lowercase, fixed during development)What to look for:
parseListCommitsParamsmatches the original inline logic exactlyparams.owner,params.repo, etc.) are correctTesting
./script/lintpasses with 0 issues./script/testpasses all test suitesTradeoffs
Link to Devin run: https://app.devin.ai/sessions/20c43147c2b74e5f9a077535303e2d5b
Requested by: Shawn Azman (shawn@cognition.ai) (@ShawnAzman)