Fix high-severity SonarQube issues in pkg/github/notifications.go - #141
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
…rror strings Addresses SonarQube issues on pkg/github/notifications.go: - S1192: extract 'failed to get GitHub client', 'failed to read response body', and 'failed to marshal response' error format strings into package-level constants. - S3776: reduce cognitive complexity of ListNotifications, DismissNotification, MarkAllNotificationsRead, ManageNotificationSubscription, and ManageRepositoryNotificationSubscription by extracting the tool handler closures into named functions and introducing shared helpers for parameter extraction, optional time parsing, error-body reading, and JSON marshalling of tool results. Co-Authored-By: parker.duff@codeium.com <pwjduff@gmail.com>
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:
|
manageRepositoryNotificationSubscriptionHandler was still at 17 per SonarQube (target: 15) because it combined a deferred body close with two separate 'resp != nil' branches for the status check. Extract the close + 2xx check into a shared helper and reuse it in manageNotificationSubscriptionHandler, which also removes a duplicated status-code error-body pattern. Co-Authored-By: parker.duff@codeium.com <pwjduff@gmail.com>
|
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.



Summary
Refactors
pkg/github/notifications.goto resolve the high-severity SonarQube issues reported against the file:S1192 — the duplicated error format strings
"failed to get GitHub client: %w"(6×)"failed to read response body: %w"(4×)"failed to marshal response: %w"(4×)are now defined as package-level constants (
errFailedGitHubClient,errFailedReadResponse,errFailedMarshalResponse) and reused everywhere.S3776 — cognitive complexity of
ListNotifications(37),DismissNotification(19),MarkAllNotificationsRead(26),ManageNotificationSubscription(17), andManageRepositoryNotificationSubscription(22) is reduced by:listNotificationsHandler,dismissNotificationHandler,markAllNotificationsReadHandler,manageNotificationSubscriptionHandler,manageRepositoryNotificationSubscriptionHandler).switchblocks into helpers (markNotificationThread,applyThreadSubscriptionAction,applyRepositorySubscriptionAction).owner/repobranching intofetchNotificationsandmarkAllRead.extractOptionalStringParams/extractRequiredStringParams— batch-read string params and collapse Nif err { return }blocks into one.parseOptionalTime/applyOptionalTime— parse optional RFC3339 time params.readErrorBodyResult— readresp.Bodyand turn it into a"<prefix>: <body>"tool-error result.marshalToolResult— JSON-marshal a value into a text tool result.GetNotificationDetails(not flagged) was left structurally unchanged but opportunistically uses the new constants/helpers for consistency.This is intended to be a pure refactor — no behavior changes, same error messages, same status-code handling (including the existing
nil-respspecial case inManageRepositoryNotificationSubscriptionand the pre-API-error-check early-return on a badthreadIDinDismissNotification).Validation
go build ./...— passesgo vet ./...— cleango test ./...— all packages pass, includingpkg/githubnotification testsReviewer checklist / things worth a close look
switches. Please confirm the three new helpers preserve original semantics, especially:markNotificationThread: an invalidthreadIDint still returns the "invalid threadID format" tool error without hitting the downstreamghErrors.NewGitHubAPIErrorResponsebranch.applyThreadSubscriptionAction/applyRepositorySubscriptionAction: thedefaultcase (invalid action) still returns before theapiErr/resphandling.ManageRepositoryNotificationSubscriptionnil-resphandling is retained (if resp != nil { defer … }andif resp != nil && (…)) — worth a second look since the call-site now receivesrespvia a helper return.notifications.go. If any ofextractOptionalStringParams,extractRequiredStringParams,parseOptionalTime,readErrorBodyResult, ormarshalToolResultwould be better placed inserver.go/ a shared file for reuse by other tools, happy to move them.Closes:
Link to Devin session: https://app.devin.ai/sessions/3b5e549e0be14ef09767ef3d337bd5eb
Requested by: @parkerduff