Skip to content

refactor: share request boilerplate to fix SonarCloud duplication gate - #150

Merged
mikemadeja merged 1 commit into
developfrom
fix/sonar-duplication-api-helper
Oct 29, 2026
Merged

mikemadeja merged 1 commit into
developfrom
fix/sonar-duplication-api-helper

Conversation

@mikemadeja

Copy link
Copy Markdown
Owner

Fixes the failing SonarCloud quality gate on develop (duplicated lines on new code was 5.1%, over the 3% limit).

Cause

Get-PiHoleApiEndpoint and Get-PiHoleAuthApp each repeated the same 28-line block (log in, build request, call API, log out in finally) that about 17 other functions also copy.

Changes

  • New private helper Invoke-PiHoleApiRequest (marked #INTERNAL FUNCTION, not exported). It logs in, calls the endpoint and always logs out. Errors propagate so each caller keeps its own catch.
  • Get-PiHoleApiEndpoint and Get-PiHoleAuthApp now use it.
  • Other functions are untouched. They're old code, so they don't count toward the new-code gate, and moving them over can happen separately (for example together with session reuse).

Testing

  • Integration tests for both functions and the module tests pass against the dev server (15/15)
  • PSScriptAnalyzer clean
  • Bad-password output is unchanged in shape. The final error now reads "Unauthorized" instead of a second raw 401 line.

🤖 Generated with Claude Code

SonarCloud's develop quality gate failed on 5.1% duplicated new code: the
login / build request / call / logout block in Get-PiHoleApiEndpoint and
Get-PiHoleAuthApp is copied from about 17 other functions. Move it into a
private Invoke-PiHoleApiRequest helper and use it from both new functions.
Errors still propagate to each caller's own catch, so messages are
unchanged apart from the friendly-message conversion now applying to the
final 401.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@mikemadeja
mikemadeja merged commit 1c42f78 into develop Oct 29, 2026
4 checks passed
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