Fix SonarQube issues: string literal duplication and cognitive complexity#73
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
Fix SonarQube issues: string literal duplication and cognitive complexity#73devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
…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>
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:
|
- 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>
|
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 code quality improvements)
Summary
This PR addresses SonarQube issues for two Go rules:
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
repoto avoid naming conflicts (repoDescRepoOwner,repoDescRepoName,repoErrFailedGetClient, etc.)Cognitive Complexity Reduction
pullrequests.go -
UpdatePullRequest: Extracted the optional parameter building logic into a newbuildPullRequestUpdate()helper function.repositories.go -
DeleteFile: Added three helper functions:checkResponseStatus()- validates HTTP response status codescreateDeleteFileTree()- creates tree entries for file deletioncreateDeleteFileCommit()- creates commits for file deletionHuman Review Checklist
buildPullRequestUpdate()maintains identical behavior to the original inline codecheckResponseStatus()error message format matches original behaviorcreateDeleteFileCommit()correctly handles parent SHA (usesgithub.Ptr(parentSHA)instead of direct pointer)Tradeoffs
Link to Devin run: https://app.devin.ai/sessions/660a44105f1d4277a003f0ca7ca1173c
Requested by: Eashan Sinha (@eashansinha-cog)