Skip to content

Conversation

@devin-ai-integration
Copy link

Summary

This PR addresses two High severity SonarQube code quality issues in pkg/github/discussions.go:

  1. String literal duplication (go:S1192) - Defined constants for frequently duplicated strings
  2. Cognitive complexity (go:S3776) - Refactored ListDiscussions function to reduce complexity from 27 to below 15

Changes

String Literal Constants

Added package-level constants for duplicated strings:

  • errFailedToGetGQLClient - "failed to get GitHub GQL client: %v" (used 4x)
  • descRepositoryOwner - "Repository owner" (used 4x)
  • descRepositoryName - "Repository name" (used 4x)
  • formatCategoryLabel - "category:%s" (used 3x)

Cognitive Complexity Reduction

Refactored ListDiscussions by extracting helper functions:

  • discussionNode type: Represents GraphQL discussion node structure
  • convertDiscussionNodeToIssue(): Converts GraphQL node to GitHub Issue object
  • queryDiscussions(): Handles GraphQL queries with/without category filter

The main handler now coordinates these helpers instead of containing all the logic inline.

Testing

  • ✅ All existing tests pass (./script/test)
  • ✅ Linter passes with 0 issues (./script/lint)

Review Focus Areas

Critical: Verify the refactored ListDiscussions maintains identical behavior:

  1. Check queryDiscussions() correctly handles both categoryID paths
  2. Verify convertDiscussionNodeToIssue() maps all fields correctly
  3. Ensure GraphQL query structures are unchanged in both branches

Low risk: Constants replacement is straightforward - all usages were mechanically replaced.


Link to Devin run: https://app.devin.ai/sessions/2ac756d3cb7d43679481075e347ee576
Requested by: Shawn Azman (@ShawnAzman)

- Define constants for duplicated string literals (go:S1192):
  - errFailedToGetGQLClient
  - descRepositoryOwner
  - descRepositoryName
  - formatCategoryLabel

- Reduce cognitive complexity of ListDiscussions function (go:S3776):
  - Extract discussionNode type for GraphQL structure
  - Extract convertDiscussionNodeToIssue helper function
  - Extract queryDiscussions helper function
  - Simplified main handler to coordinate helpers
  - Reduced complexity from 27 to below 15
@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

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
14.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

2 participants