refactor(services): share the SDK list-page wrapper

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 20:49:33 +02:00
1 parent 9df6cb7dd3
commit dbe2d376fe
12 files changed
+98 -142

No files matched your search

+11
View File
@@ -13,6 +13,7 @@ import (
"strings"
"time"
gitea "gitea.dev/sdk"
"gitea.dev/tea/internal/transport"
)
@@ -99,6 +100,16 @@ func listPage[T any](limit, page int, fetch func(limit, page int) ([]T, http.Hea
return Page[T]{Items: result[:min(len(result), limit)], More: more, Total: total, Counted: counted}, nil
}
// callPage is listPage over an SDK list call.
func callPage[T any](ctx context.Context, client *transport.Client, limit, page int, list func(context.Context, *gitea.Client, gitea.ListOptions) ([]T, *gitea.Response, error)) (Page[T], error) {
return listPage(limit, page, func(limit, page int) ([]T, http.Header, error) {
items, resp, err := call(ctx, client, func(ctx context.Context, c *gitea.Client) ([]T, *gitea.Response, error) {
return list(ctx, c, listOptions(limit, page))
})
return items, headerOf(resp), err
})
}
// rawPage is listPage over a raw JSON collection endpoint; it sets limit and page on query.
func rawPage[T any](ctx context.Context, client *transport.Client, endpoint string, query url.Values, limit, page int) (Page[T], error) {
query = maps.Clone(query)