Skip to content

SonarQube: Fix High severity Go issues (S1192, S3776) in discussions.go#86

Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1770393952-sonarqube-fixes
Open

SonarQube: Fix High severity Go issues (S1192, S3776) in discussions.go#86
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1770393952-sonarqube-fixes

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Feb 6, 2026

Closes:

Summary

  • Addresses two High-severity SonarQube rules in pkg/github/discussions.go:
    • S1192 (Go): String literals should not be duplicated
      • Introduced shared constants and replaced repeated literals:
        • descRepoOwner = "Repository owner"
        • descRepoName = "Repository name"
        • errGQLClientFmt = "failed to get GitHub GQL client: %v"
        • categoryLabelFmt = "category:%s"
      • Applied in ListDiscussions, GetDiscussion, GetDiscussionComments, and ListDiscussionCategories.
    • S3776 (Go): Cognitive Complexity of functions should not be too high
      • Reduced complexity in ListDiscussionCategories by extracting pagination validation into a helper:
        • validatePaginationParams(first, last, after, before string) error

Updates since initial revision

  • Introduced discussionNode struct type to eliminate duplicated inline struct definitions in ListDiscussions
  • Added newIssueFromNode helper to centralize node-to-Issue mapping
  • Unified ListDiscussions to use a single mapping loop after both query branches
  • These changes reduced Sonar "new code duplication" from 10% → 2.9% (passing threshold)

Intent and impact

  • Pure refactor/no-op behavior changes:
    • Descriptions and error messages remain identical; only centralized as constants.
    • Extracted validation logic preserves existing checks and messages.
    • GraphQL queries unchanged; only struct definitions consolidated.
  • Unit tests and lint pass:
    • ./script/lint → 0 issues
    • ./script/test → all packages ok

Tradeoffs

  • Added package-level constants, one shared struct type, and two helper functions to reduce duplication and complexity.
  • Kept changes scoped to discussions.go to minimize review surface.

Alternatives considered

  • Refactoring other functions (GetDiscussion, GetDiscussionComments) to use shared node types; deferred to keep PR focused.

Human review checklist

  • Verify discussionNode struct GraphQL tags match original inline definitions
  • Confirm newIssueFromNode output is identical to previous inline mapping code
  • Check that validatePaginationParams error messages match original inline checks
  • Ensure no exported API/schema changes in tool definitions (param names/types unchanged)

Manual test ideas

  • Smoke test the affected tools with typical inputs:
    • list_discussions (with/without category)
    • get_discussion
    • get_discussion_comments
    • list_discussion_categories (including pagination arg edge cases: first+last, after+before)
  • Confirm returned JSON structures and error messages are unchanged.

Links

Small PR

  • Single-file change (pkg/github/discussions.go), net ~20 lines added after consolidation.

Open with Devin

…ty in ListDiscussionCategories

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

ShawnAzman and others added 2 commits February 6, 2026 16:29
…e duplication)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…o cut new-code duplication

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 6, 2026

Copy link
Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant