Skip to content

Fix SonarQube issues: string literal duplication and cognitive complexity#73

Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1767888673-sonarqube-go-fixes
Open

Fix SonarQube issues: string literal duplication and cognitive complexity#73
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1767888673-sonarqube-go-fixes

Conversation

@devin-ai-integration
Copy link

Closes: N/A (SonarQube code quality improvements)

Summary

This PR addresses SonarQube issues for two Go rules:

  • go:S1192: String literals should not be duplicated
  • go:S3776: Cognitive Complexity of functions should not be too high

Changes

String Literal Deduplication

Extracted repeated string literals into package-level constants in both files:

pullrequests.go: Added constants for descRepoOwner, descRepoName, descPullRequestNumber, and error message templates (errFailedGetClient, errFailedReadBody, errFailedMarshal, etc.)

repositories.go: Added similar constants prefixed with repo to avoid naming conflicts (repoDescRepoOwner, repoDescRepoName, repoErrFailedGetClient, etc.)

Cognitive Complexity Reduction

pullrequests.go - UpdatePullRequest: Extracted the optional parameter building logic into a new buildPullRequestUpdate() helper function.

repositories.go - DeleteFile: Added three helper functions:

  • checkResponseStatus() - validates HTTP response status codes
  • createDeleteFileTree() - creates tree entries for file deletion
  • createDeleteFileCommit() - creates commits for file deletion

Human Review Checklist

  • Verify buildPullRequestUpdate() maintains identical behavior to the original inline code
  • Verify checkResponseStatus() error message format matches original behavior
  • Verify createDeleteFileCommit() correctly handles parent SHA (uses github.Ptr(parentSHA) instead of direct pointer)

Tradeoffs

  • Added helper functions increase the number of functions in the package but significantly improve readability and reduce cognitive complexity
  • Used separate constant blocks in each file (with prefixes in repositories.go) to avoid cross-file dependencies

Link to Devin run: https://app.devin.ai/sessions/660a44105f1d4277a003f0ca7ca1173c
Requested by: Eashan Sinha (@eashansinha-cog)

…xity

- Extract duplicated string literals into constants in pullrequests.go and repositories.go
- Add buildPullRequestUpdate helper function to reduce cognitive complexity in UpdatePullRequest
- Add checkResponseStatus, createDeleteFileTree, and createDeleteFileCommit helper functions to reduce cognitive complexity in DeleteFile

Addresses SonarQube rules:
- go:S1192 (String literals should not be duplicated)
- go:S3776 (Cognitive Complexity of functions should not be too high)

Co-Authored-By: Eashan Sinha <eashan.sinha@cognition.ai>
@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

- Remove duplicate descRepoOwner and descRepoName constants from pullrequests.go
- Remove duplicate repoDescRepoOwner and repoDescRepoName constants from repositories.go
- Use existing DescriptionRepositoryOwner and DescriptionRepositoryName from actions.go
- This reduces cross-file string literal duplication flagged by SonarCloud

Co-Authored-By: Eashan Sinha <eashan.sinha@cognition.ai>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 8, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
29.2% 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.

0 participants