Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Identified and eliminated ~30 lines of duplicated code across resolver String() implementations and API client initialization.

Changes

Resolver String() Methods

  • Extracted common upstream formatting logic into formatUpstreamResolvers() helper in resolver/resolver.go
  • Refactored StrictResolver and ParallelBestResolver to use shared implementation

Before:

func (r *StrictResolver) String() string {
    resolvers := *r.resolvers.Load()
    upstreams := make([]string, len(resolvers))
    for i, s := range resolvers {
        upstreams[i] = s.resolver.String()
    }
    return fmt.Sprintf("%s upstreams '%s (%s)'", strictResolverType, r.cfg.Name, strings.Join(upstreams, ","))
}

After:

func (r *StrictResolver) String() string {
    return formatUpstreamResolvers(strictResolverType, r.cfg.Name, *r.resolvers.Load())
}

API Client Creation

  • Added newAPIClient() helper in cmd/root.go for consistent client initialization and error handling
  • Updated 6 command functions across blocking.go, cache.go, lists.go, and query.go

Before:

client, err := api.NewClientWithResponses(apiURL())
if err != nil {
    return fmt.Errorf("can't create client: %w", err)
}

After:

client, err := newAPIClient()
if err != nil {
    return err
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 127.0.0.2
    • Triggering command: /home/REDACTED/work/blocky/blocky/resolver/resolver.test --test.timeout=0 --ginkgo.seed=1763102286 --ginkgo.timeout=59m43.553297085s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/resolver/coverage.txt (packet block)
    • Triggering command: /home/REDACTED/work/blocky/blocky/resolver/resolver.test --test.timeout=0 --ginkgo.seed=1763102854 --ginkgo.timeout=59m45.066627341s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/resolver/coverage.txt (packet block)
  • example.com
    • Triggering command: /home/REDACTED/work/blocky/blocky/cmd/cmd.test --test.timeout=0 --ginkgo.seed=1763102286 --ginkgo.timeout=59m49.735667649s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/cmd/coverage.txt (dns block)
    • Triggering command: /home/REDACTED/work/blocky/blocky/server/server.test --test.timeout=0 --ginkgo.seed=1763102286 --ginkgo.timeout=59m31.762891604s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/server/coverage.txt (dns block)
    • Triggering command: /home/REDACTED/work/blocky/blocky/cmd/cmd.test --test.timeout=0 --ginkgo.seed=1763102854 --ginkgo.timeout=59m51.268400917s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/cmd/coverage.txt (dns block)
  • xyz.example.com
    • Triggering command: /home/REDACTED/work/blocky/blocky/lists/lists.test --test.timeout=0 --ginkgo.seed=1763102286 --ginkgo.timeout=59m47.410342067s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/lists/coverage.txt (dns block)
    • Triggering command: /home/REDACTED/work/blocky/blocky/lists/lists.test --test.timeout=0 --ginkgo.seed=1763102854 --ginkgo.timeout=59m48.940083249s --ginkgo.grace-period=30s --ginkgo.label-filter=!e2e --ginkgo.parallel.process=1 --ginkgo.parallel.total=1 --ginkgo.succinct --test.coverprofile=/home/REDACTED/work/blocky/blocky/lists/coverage.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 14, 2025
Copilot AI changed the title [WIP] Refactor duplicated code for better maintainability Refactor duplicated code patterns in resolver and cmd packages Nov 14, 2025
Copilot AI requested a review from 0xERR0R November 14, 2025 06:52
@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.80%. Comparing base (5657ce8) to head (15e6367).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/blocking.go 50.00% 3 Missing ⚠️
cmd/root.go 60.00% 1 Missing and 1 partial ⚠️
cmd/cache.go 50.00% 1 Missing ⚠️
cmd/lists.go 50.00% 1 Missing ⚠️
cmd/query.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1932      +/-   ##
==========================================
- Coverage   91.83%   91.80%   -0.03%     
==========================================
  Files          90       90              
  Lines        6257     6259       +2     
==========================================
  Hits         5746     5746              
- Misses        381      382       +1     
- Partials      130      131       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@0xERR0R 0xERR0R changed the title Refactor duplicated code patterns in resolver and cmd packages refactor: remove duplicated code patterns in resolver and cmd packages Nov 14, 2025
@0xERR0R 0xERR0R marked this pull request as ready for review November 14, 2025 15:51
@0xERR0R 0xERR0R merged commit b776ae5 into main Nov 14, 2025
28 of 34 checks passed
@0xERR0R 0xERR0R deleted the copilot/refactor-duplicated-code branch November 14, 2025 15:52
alexlebens pushed a commit to alexlebens/infrastructure that referenced this pull request Nov 24, 2025
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/0xerr0r/blocky](https://github.com/0xERR0R/blocky) | minor | `v0.27.0` -> `v0.28.2` |

---

### Release Notes

<details>
<summary>0xERR0R/blocky (ghcr.io/0xerr0r/blocky)</summary>

### [`v0.28.2`](https://github.com/0xERR0R/blocky/releases/tag/v0.28.2)

[Compare Source](0xERR0R/blocky@v0.28.1...v0.28.2)

##### Changelog

##### Features

- [`26ac90c`](0xERR0R/blocky@26ac90c): feat: add MIPS architecture builds ([#&#8203;1929](0xERR0R/blocky#1929)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))

##### Bug fixes

- [`605a361`](0xERR0R/blocky@605a361): fix: handle DNSSEC validation for large RSA exponents and improve DNSKEY matching ([#&#8203;1935](0xERR0R/blocky#1935)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))

##### Misc

- [`b776ae5`](0xERR0R/blocky@b776ae5): refactor: remove duplicated code patterns in resolver and cmd packages ([#&#8203;1932](0xERR0R/blocky#1932)) ([@&#8203;Copilot](https://github.com/Copilot))

### [`v0.28.1`](https://github.com/0xERR0R/blocky/releases/tag/v0.28.1)

[Compare Source](0xERR0R/blocky@v0.28.0...v0.28.1)

##### Changelog

##### Bug fixes

- [`5657ce8`](0xERR0R/blocky@5657ce8): fix: resolve DNSSEC validation issue for CNAMEs in unsigned zones ([#&#8203;1930](0xERR0R/blocky#1930)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))

##### Build and dependencies

- [`f4b6b75`](0xERR0R/blocky@f4b6b75): build: Update regex for bug fixes in goreleaser config ([@&#8203;0xERR0R](https://github.com/0xERR0R))

##### Misc

- [`0a3c724`](0xERR0R/blocky@0a3c724): refactor: remove unused code ([#&#8203;1928](0xERR0R/blocky#1928)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))

### [`v0.28.0`](https://github.com/0xERR0R/blocky/releases/tag/v0.28.0)

[Compare Source](0xERR0R/blocky@v0.27.0...v0.28.0)

##### Changelog

##### Features

- [`77578da`](0xERR0R/blocky@77578da): feat: add DNSSEC validation ([#&#8203;1914](0xERR0R/blocky#1914)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`b29eab4`](0xERR0R/blocky@b29eab4): feat: add SOA records to NXDOMAIN responses for RFC 2308 compliance ([#&#8203;1895](0xERR0R/blocky#1895)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`d0681ae`](0xERR0R/blocky@d0681ae): feat: enhance error messages with more context ([#&#8203;1894](0xERR0R/blocky#1894)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`ac8ca7d`](0xERR0R/blocky@ac8ca7d): feat: respect NO\_COLOR environment variable ([#&#8203;1911](0xERR0R/blocky#1911)) ([@&#8203;aanderse](https://github.com/aanderse))
- [`629b4f0`](0xERR0R/blocky@629b4f0): feat: support DNS Stamp upstream format ([#&#8203;1922](0xERR0R/blocky#1922)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))

##### Bugfixes

- [`8aad53e`](0xERR0R/blocky@8aad53e): fix: TCP response truncation ([#&#8203;1904](0xERR0R/blocky#1904)) ([@&#8203;TimQuelch](https://github.com/TimQuelch))
- [`9d4a58c`](0xERR0R/blocky@9d4a58c): fix: allow list group initialization with partial source failures ([#&#8203;1889](0xERR0R/blocky#1889)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`0993a17`](0xERR0R/blocky@0993a17): fix: ensure HTTP response bodies are drained before closing for connection reuse ([#&#8203;1924](0xERR0R/blocky#1924)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`1a98cda`](0xERR0R/blocky@1a98cda): fix: ensure conditional upstreams initialize independently of default upstreams ([#&#8203;1890](0xERR0R/blocky#1890)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`0804760`](0xERR0R/blocky@0804760): fix: resolve panic when CNAME points to external domain ([#&#8203;1867](0xERR0R/blocky#1867)) ([#&#8203;1884](0xERR0R/blocky#1884)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))

##### Build and dependencies

- [`0cd5be8`](0xERR0R/blocky@0cd5be8): build(deps): bump actions/download-artifact from 5 to 6 ([#&#8203;1907](0xERR0R/blocky#1907)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`5db30c4`](0xERR0R/blocky@5db30c4): build(deps): bump actions/upload-artifact from 4 to 5 ([#&#8203;1908](0xERR0R/blocky#1908)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`fc7ebe3`](0xERR0R/blocky@fc7ebe3): build(deps): bump amannn/action-semantic-pull-request from 5 to 6 ([#&#8203;1897](0xERR0R/blocky#1897)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`6a4d411`](0xERR0R/blocky@6a4d411): build(deps): bump github.com/avast/retry-go/v4 from 4.6.1 to 4.7.0 ([#&#8203;1888](0xERR0R/blocky#1888)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`9e293c0`](0xERR0R/blocky@9e293c0): build(deps): bump github.com/breml/rootcerts from 0.3.1 to 0.3.2 ([#&#8203;1886](0xERR0R/blocky#1886)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`e81bf41`](0xERR0R/blocky@e81bf41): build(deps): bump github.com/breml/rootcerts from 0.3.2 to 0.3.3 ([#&#8203;1912](0xERR0R/blocky#1912)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`073c8bf`](0xERR0R/blocky@073c8bf): build(deps): bump github.com/docker/docker from 28.5.1+incompatible to 28.5.2+incompatible ([#&#8203;1915](0xERR0R/blocky#1915)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`2dac748`](0xERR0R/blocky@2dac748): build(deps): bump github.com/onsi/ginkgo/v2 from 2.26.0 to 2.27.1 ([#&#8203;1906](0xERR0R/blocky#1906)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`8f534e6`](0xERR0R/blocky@8f534e6): build(deps): bump github.com/onsi/ginkgo/v2 from 2.27.1 to 2.27.2 ([#&#8203;1909](0xERR0R/blocky#1909)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`7fa1c78`](0xERR0R/blocky@7fa1c78): build(deps): bump github.com/testcontainers/testcontainers-go from 0.39.0 to 0.40.0 ([#&#8203;1916](0xERR0R/blocky#1916)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`5b147cc`](0xERR0R/blocky@5b147cc): build(deps): bump github.com/testcontainers/testcontainers-go/modules/mariadb from 0.39.0 to 0.40.0 ([#&#8203;1918](0xERR0R/blocky#1918)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`80aeaa9`](0xERR0R/blocky@80aeaa9): build(deps): bump github.com/testcontainers/testcontainers-go/modules/postgres from 0.39.0 to 0.40.0 ([#&#8203;1917](0xERR0R/blocky#1917)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`1cdaf72`](0xERR0R/blocky@1cdaf72): build(deps): bump github.com/testcontainers/testcontainers-go/modules/redis from 0.39.0 to 0.40.0 ([#&#8203;1919](0xERR0R/blocky#1919)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`7663b7d`](0xERR0R/blocky@7663b7d): build(deps): bump golang.org/x/net from 0.46.0 to 0.47.0 ([#&#8203;1925](0xERR0R/blocky#1925)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`8a212de`](0xERR0R/blocky@8a212de): build(deps): bump gorm.io/gorm from 1.31.0 to 1.31.1 ([#&#8203;1913](0xERR0R/blocky#1913)) ([@&#8203;dependabot](https://github.com/dependabot)\[bot])
- [`157f91f`](0xERR0R/blocky@157f91f): build(release): Add changelog groups for features and fixes ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`d3e8b3b`](0xERR0R/blocky@d3e8b3b): build: add pr title validation workflow ([#&#8203;1893](0xERR0R/blocky#1893)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`44074e4`](0xERR0R/blocky@44074e4): build: cache Go dependencies in Docker builds ([#&#8203;1899](0xERR0R/blocky#1899)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`21a65de`](0xERR0R/blocky@21a65de): build: enable dependabot automerge ([#&#8203;1891](0xERR0R/blocky#1891)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`8bf91c4`](0xERR0R/blocky@8bf91c4): build: remove unused tools ([#&#8203;1900](0xERR0R/blocky#1900)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`4656429`](0xERR0R/blocky@4656429): build: simplify build ([#&#8203;1892](0xERR0R/blocky#1892)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`ab77fd5`](0xERR0R/blocky@ab77fd5): build: update tool dependencies ([#&#8203;1898](0xERR0R/blocky#1898)) ([@&#8203;0xERR0R](https://github.com/0xERR0R))
- [`824ca3e`](0xERR0R/blocky@824ca3e): build: use Docker for mkdocs-material documentation server ([@&#8203;0xERR0R](https://github.com/0xERR0R))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41LjAiLCJ1cGRhdGVkSW5WZXIiOiI0Mi41LjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImltYWdlIl19-->

Reviewed-on: https://gitea.alexlebens.dev/alexlebens/infrastructure/pulls/2100
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
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