feat(issue): list issues without an assignee with --no-assignee

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:17:11 +02:00
1 parent bae885a4d2
commit 3a61db6533
7 files changed
+128 -44

No files matched your search

+40
View File
@@ -5,6 +5,7 @@ package services
import (
"context"
"errors"
"fmt"
"maps"
"net/http"
@@ -48,6 +49,45 @@ func listAll[T any](fetch func(page int) ([]T, error)) ([]T, error) {
return nil, fmt.Errorf("listing exceeded %d pages", maxListPages)
}
// filterPageSize is the page size filteredPage reads, Gitea's default maximum.
const filterPageSize = 50
// filteredPage applies a filter without a server equivalent: it reads pages of filterPageSize
// from fetch only until one item past the requested page is kept, and counts the matches when
// it reads them all.
func filteredPage[T any](limit, page int, fetch func(limit, page int) (Page[T], error), keep func(T) bool) (Page[T], error) {
if limit <= 0 || page <= 0 {
return Page[T]{}, errors.New("limit and page must be positive")
}
matching, wanted := []T{}, page*limit+1
for serverPage := 1; ; serverPage++ {
if serverPage > maxListPages {
return Page[T]{}, fmt.Errorf("listing exceeded %d pages", maxListPages)
}
window, err := fetch(filterPageSize, serverPage)
if err != nil {
return Page[T]{}, err
}
for _, item := range window.Items {
if keep(item) {
matching = append(matching, item)
}
}
if len(matching) >= wanted {
items, err := pageOf(matching, limit, page)
return Page[T]{Items: items, More: true}, err
}
if len(window.Items) == 0 || (!window.More && len(window.Items) < filterPageSize) {
break
}
}
items, err := pageOf(matching, limit, page)
if err != nil {
return Page[T]{}, err
}
return Page[T]{Items: items, More: page*limit < len(matching), Total: len(matching), Counted: true}, nil
}
// pageHints reads whether the server advertises a next page and the collection size.
func pageHints(headers http.Header) (next bool, total int, counted bool) {
links, err := nextPageLinks(headers.Values("Link"))