Fix SonarQube issues: string duplication and cognitive complexity #33
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
Fixes two High severity SonarQube issues in the github-mcp-server codebase:
ErrFailedToGetGitHubClientconstant to eliminate 40+ duplicate occurrences of"failed to get GitHub client: %w"ManageNotificationSubscriptionby extractingexecuteNotificationSubscriptionActionhelper function to reduce complexity from 17 to ≤15Changes
String Duplication Fix
ErrFailedToGetGitHubClientconstant inpkg/github/server.gopkg/github/actions.go(14 instances)pkg/github/repositories.go(12 instances)pkg/github/issues.go(7 instances)pkg/github/notifications.go(6 instances)pkg/github/pullrequests.go(multiple instances)pkg/github/search.go(3 instances)pkg/github/code_scanning.go(2 instances)pkg/github/secret_scanning.go(2 instances)pkg/github/repository_resource.go(1 instance)Note:
pkg/github/search_utils.gowas intentionally excluded as it uses a dynamic prefix pattern:fmt.Errorf("%s: failed to get GitHub client: %w", errorPrefix, err)Cognitive Complexity Fix
executeNotificationSubscriptionActionhelper function that encapsulates the switch statement for different notification actions (ignore/watch/delete)ManageNotificationSubscriptionhandler by delegating action execution to the helperTesting
✅ All lint checks passed (
./script/lint- 0 issues)✅ All tests passed (
./script/test)Review Checklist
Please pay special attention to:
fmt.Errorf(ErrFailedToGetGitHubClient, err)still produces the expected error messages with proper wrappingif apiErr.Error() == fmt.Sprintf("invalid action: %s", action)to distinguish invalid action errors from API errors - confirm this pattern is reliabledefer func() { _ = resp.Body.Close() }()is still called correctly after the refactoringLink to Devin run: https://app.devin.ai/sessions/d7851a5770a441d9a7e342cc1c5d63cd
Requested by: Shawn Azman (@ShawnAzman)