10 Commits

Author SHA1 Message Date
Unbound Release e18b226356 chore(release): prepare for v0.0.4 2025-06-16 10:09:08 +00:00
argoyle a8a1c613a4 fix(pagination): handle empty page return case
Adds a check for empty pages in the pagination logic to return a 
nil slice and empty PageInfo when there are no items to display. 
Updates tests to verify the behavior when no more items are 
available, ensuring robustness in pagination functionality.
2025-06-16 12:04:52 +02:00
Unbound Release e60459ddd4 chore(release): prepare for v0.0.3 2025-06-16 07:13:07 +00:00
argoyle 8e8bdac22c fix: update GetPage to check for empty items slice
Refactor the GetPage function to check for an empty slice of items 
instead of a nil pointer. Update tests to cover cases for nil and 
empty slices, ensuring consistent behavior and improved clarity.
2025-06-16 09:09:04 +02:00
Unbound Release 704b755c4c chore(release): prepare for v0.0.2 2025-06-15 20:27:11 +02:00
argoyle bb3f7327cd fix(pagination): handle out-of-bounds slicing in pagination
Ensure the pagination function correctly handles out-of-bounds indices  
when slicing items. Update the slice logic to prevent slice bounds  
errors and add a test case for better coverage of edge cases.
2025-06-15 19:56:47 +02:00
Renovate 0e8ba09d62 chore(deps): update golang:1.24.4 docker digest to 3494bbe 2025-06-11 02:51:22 +00:00
argoyle 9978b6f900 fix: update Codecov badge URL in README
Updates the Codecov badge URL in the README to ensure it 
correctly points to the project repository. This enhances 
documentation clarity and reflects the correct integration 
status.
2025-06-10 19:55:02 +02:00
Renovate bd468af1d2 chore(deps): update pre-commit hook gitleaks/gitleaks to v8.27.2 2025-06-09 00:51:17 +00:00
Renovate ec1003a094 chore(deps): update pre-commit hook gitleaks/gitleaks to v8.27.1 2025-06-08 02:51:14 +00:00
6 changed files with 51 additions and 7 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ include:
- project: unboundsoftware/ci-templates
file: Pre-Commit-Go.gitlab-ci.yml
image: amd64/golang:1.24.4@sha256:40891f7b63de861049787c5262bff91906d30cbe221753840e276b3e785a66ab
image: amd64/golang:1.24.4@sha256:3494bbe140127d12656113203ec91b8e3ff34e8a2b06a0a22bb0d8a41cc69e53
stages:
- deps
@@ -32,7 +32,7 @@ test:
vulnerabilities:
stage: test
image: amd64/golang:1.24.4@sha256:40891f7b63de861049787c5262bff91906d30cbe221753840e276b3e785a66ab
image: amd64/golang:1.24.4@sha256:3494bbe140127d12656113203ec91b8e3ff34e8a2b06a0a22bb0d8a41cc69e53
script:
- go install golang.org/x/vuln/cmd/govulncheck@latest
- govulncheck ./...
+1 -1
View File
@@ -41,6 +41,6 @@ repos:
hooks:
- id: golangci-lint-full
- repo: https://github.com/gitleaks/gitleaks
rev: v8.27.0
rev: v8.27.2
hooks:
- id: gitleaks
+19
View File
@@ -2,6 +2,25 @@
All notable changes to this project will be documented in this file.
## [0.0.4] - 2025-06-16
### 🐛 Bug Fixes
- *(pagination)* Handle empty page return case
## [0.0.3] - 2025-06-16
### 🐛 Bug Fixes
- Update GetPage to check for empty items slice
## [0.0.2] - 2025-06-15
### 🐛 Bug Fixes
- Update Codecov badge URL in README
- *(pagination)* Handle out-of-bounds slicing in pagination
## [0.0.1] - 2025-06-07
### 🚀 Features
+1 -1
View File
@@ -3,4 +3,4 @@
Pagination helper
[![Build Status](https://gitlab.com/unboundsoftware/pagination/badges/main/pipeline.svg)](https://gitlab.com/unboundsoftware/pagination/commits/main)
[![codecov](https://codecov.io/gl/unboundsoftware:pagination/branch/main/graph/badge.svg?token=AZ3AHHF0FS)](https://codecov.io/gl/unboundsoftware:pagination)
[![codecov](https://codecov.io/gl/unboundsoftware/pagination/branch/main/graph/badge.svg?token=AZ3AHHF0FS)](https://codecov.io/gl/unboundsoftware/pagination)
+5 -2
View File
@@ -52,7 +52,7 @@ func EncodeCursor(cursor string) string {
}
func GetPage[T any](items []T, first *int, after *string, last *int, before *string, max int, fn func(T) string) ([]T, PageInfo) {
if items == nil {
if len(items) == 0 {
return nil, PageInfo{}
}
tmp := min(max, len(items))
@@ -87,7 +87,10 @@ func GetPage[T any](items []T, first *int, after *string, last *int, before *str
sIx = f
eIx = idx
}
page := items[sIx:eIx]
page := items[sIx:min(eIx, len(items))]
if len(page) == 0 {
return nil, PageInfo{}
}
return page, PageInfo{
StartCursor: ptr(EncodeCursor(fn(page[0]))),
HasNextPage: eIx < len(items),
+23 -1
View File
@@ -24,11 +24,17 @@ func TestGetPage(t *testing.T) {
}
tests := []testCase[string]{
{
name: "empty",
name: "nil items",
args: args[string]{max: 10},
wantItems: nil,
wantPageInfo: PageInfo{},
},
{
name: "empty items",
args: args[string]{items: []string{}, max: 10},
wantItems: nil,
wantPageInfo: PageInfo{},
},
{
name: "first 2",
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(2), max: 10, fn: func(s string) string { return s }},
@@ -39,6 +45,22 @@ func TestGetPage(t *testing.T) {
EndCursor: ptr("Mg=="),
},
},
{
name: "no more items",
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(2), after: ptr("Mw=="), max: 10, fn: func(s string) string { return s }},
wantItems: nil,
wantPageInfo: PageInfo{},
},
{
name: "first 10",
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(10), max: 10, fn: func(s string) string { return s }},
wantItems: []string{"1", "2", "3"},
wantPageInfo: PageInfo{
StartCursor: ptr("MQ=="),
HasNextPage: false,
EndCursor: ptr("Mw=="),
},
},
{
name: "after 2",
args: args[string]{items: []string{"1", "2", "3", "4"}, first: ptr(2), after: ptr("Mg=="), max: 10, fn: func(s string) string { return s }},