fix: resolve SonarQube S1192 and S3776 High severity issues in discussions.go - #147
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
S1192 - Extract duplicated string literals to package-level constants: - descRepoOwner, descRepoName, errGQLClientFmt, categoryLabelFmt S3776 - Reduce cognitive complexity of ListDiscussions from 27 to <=15: - Extract discussionNode struct and mapDiscussionNodesToIssues helper - Extract listDiscussionsWithCategory and listDiscussionsAll helpers - Flatten branching in the main handler Co-Authored-By: Vedant Khanna <vedantkhanna@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:
|
Use var declaration instead of make() so json.Marshal produces null (not []) when there are no discussions, matching original behavior. Co-Authored-By: Vedant Khanna <vedantkhanna@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.



Closes: N/A (SonarQube-driven code quality improvements)
Summary
Addresses two HIGH severity SonarQube findings in
pkg/github/discussions.go:S1192 — String literals should not be duplicated
Extracted four duplicated string literals into package-level constants:
descRepoOwner("Repository owner") — was duplicated 4×descRepoName("Repository name") — was duplicated 4×errGQLClientFmt("failed to get GitHub GQL client: %v") — was duplicated 4×categoryLabelFmt("category:%s") — was duplicated 3×S3776 — Cognitive Complexity of functions should not be too high
Reduced the cognitive complexity of
ListDiscussionsfrom 27 → ~8 (allowed max: 15):discussionNodestruct to eliminate inline struct duplicationmapDiscussionNodesToIssues()helper to consolidate the node→Issue mapping logic that was copy-pasted in both brancheslistDiscussionsWithCategory()andlistDiscussionsAll()helpers to move the two GraphQL query branches out of the main handlerTradeoffs
discussions.goand not exported, keeping the change scoped.Alternatives
categoryIdvariable, which isn't valid for the no-filter case due to howgithubv4constructs queries.Verification
go build ./...passesgo vet ./...passesTest_ListDiscussions,Test_GetDiscussion,Test_GetDiscussionComments,Test_ListDiscussionCategories)Link to Devin session: https://app.devin.ai/sessions/975cc3c24a394a1397adb7d1362fe6ae
Requested by: @VedantKh
Devin Review