fix: remediate SonarQube high severity issues (S1192, S3776) - #137
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- S1192: Replace 34 duplicated string literals ('Repository owner' and
'Repository name') in pullrequests.go with existing constants
DescriptionRepositoryOwner and DescriptionRepositoryName from actions.go
- S3776: Reduce cognitive complexity of GetFileContents in repositories.go
by extracting helper functions: inferSHAFromPullRef, buildResourceURI,
getFileFromRawContent, and getDirContents
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.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:
|
|
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 — addresses SonarQube static analysis findings
Summary
Remediates one High severity issue from each of two SonarQube rules:
1. S1192 — String literals should not be duplicated (
pullrequests.go)Replaced 34 occurrences of the raw strings
"Repository owner"and"Repository name"inpullrequests.gowith the existing package-level constantsDescriptionRepositoryOwnerandDescriptionRepositoryName(already defined inactions.go). This is a purely mechanical change with no behavioral impact.2. S3776 — Cognitive Complexity of functions should not be too high (
repositories.go)Refactored
GetFileContentsby extracting four helper functions to flatten the nesting:inferSHAFromPullRefrefs/pull/N/headto the PR's head SHAbuildResourceURIrepo://URI from owner/repo/sha/ref/pathgetFileFromRawContent(nil, nil)on non-200 to signal fallthroughgetDirContentsNo logic was changed — each helper preserves the original behavior exactly.
Tradeoffs
getFileFromRawContentuses a(nil, nil)return to signal "not found, try another method." This is documented in the function's godoc but is an implicit convention worth noting.Human Review Checklist
getFileFromRawContentreturning(nil, nil)on non-200 correctly mirrors the original fallthrough behavior (original: the inner block only executed onStatusOK, otherwise fell through).buildResourceURIparameter order (owner, repo, sha, ref, path) matches all call sites.defer resp.Body.Close()semantics — body is now closed when the helper returns rather than when the outer handler returns. This is safe because the body has already been fully read or the result is being discarded.script/lintandscript/testboth green).Link to Devin session: https://app.devin.ai/sessions/10a70a97f4fa47b4bf49ce67f04e0cc5
Requested by: @VedantKh