refactor(utils): extract shared pagination validation helper#895
refactor(utils): extract shared pagination validation helper#895PrasunaEnumarthy wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #895 +/- ##
=========================================
- Coverage 10.99% 9.21% -1.78%
=========================================
Files 173 321 +148
Lines 8671 16073 +7402
=========================================
+ Hits 953 1481 +528
- Misses 7612 14459 +6847
- Partials 106 133 +27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
NucleoFusion
left a comment
There was a problem hiding this comment.
lgtm!
Thanks for the contribution!
There was a problem hiding this comment.
Pull request overview
This PR centralizes pagination (page, pageSize) validation into a shared utility to eliminate duplicated logic across CLI list commands and standardize related error messages.
Changes:
- Added
utils.ValidatePagination(page, pageSize int64) errorinpkg/utils/helper.go. - Added table-driven unit tests for pagination validation in
pkg/utils/helper_test.go. - Refactored user/project/registry/artifact list commands to call the shared helper.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/utils/helper.go | Introduces shared pagination validation logic (with consistent constraints/messages). |
| pkg/utils/helper_test.go | Adds unit tests for the new pagination helper. |
| cmd/harbor/root/user/list.go | Replaces inline pagination checks with utils.ValidatePagination. |
| cmd/harbor/root/project/list.go | Replaces inline pagination checks with utils.ValidatePagination. |
| cmd/harbor/root/registry/list.go | Replaces inline pagination checks with utils.ValidatePagination. |
| cmd/harbor/root/artifact/list.go | Replaces inline pagination checks with utils.ValidatePagination. |
Comments suppressed due to low confidence (1)
cmd/harbor/root/registry/list.go:43
- The error message references "projects list" even though this command lists registries, which is confusing and inconsistent with other list commands.
registry, err := api.ListRegistries(opts)
if err != nil {
return fmt.Errorf("failed to get projects list: %v", err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ce6dbb3 to
8483e48
Compare
Signed-off-by: PrasunaEnumarthy <eswari.prasuna@gmail.com>
Signed-off-by: PrasunaEnumarthy <eswari.prasuna@gmail.com>
8483e48 to
d04ccc0
Compare
|
@bupd please ptal when you have time, i have resolved all review comments |
Description
This PR centralizes and standardizes the pagination validation logic across multiple CLI commands. Currently, logic to validate
pageandpageSizeis duplicated in severallist.gofiles, leading to inconsistent error messages and maintenance overhead.By moving this logic to a shared utility helper, we ensure a "Single Source of Truth" for pagination constraints, improve code reusability, and simplify the implementation of future commands.
Type of Change
Changes