mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
feat(issue): list issues without an assignee with --no-assignee
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
7 files changed
+128
-44
No files matched your search
+10
-35
@@ -143,15 +143,16 @@ type PullListOptions struct {
|
||||
Limit, Page int
|
||||
Milestone int64
|
||||
Labels []int64
|
||||
// Draft, Head (BRANCH or OWNER:BRANCH), Assignee, Search (text in the title or body) and the
|
||||
// merged state have no server filter; List applies them to every pull request it reads.
|
||||
Draft bool
|
||||
// Draft, Head (BRANCH or OWNER:BRANCH), Assignee, NoAssignee, Search (text in the title or
|
||||
// body) and the merged state have no server filter; List applies them to every pull request
|
||||
// it reads.
|
||||
Draft, NoAssignee bool
|
||||
Head, Assignee, Search string
|
||||
}
|
||||
|
||||
// filtered reports whether a filter needs every pull request read.
|
||||
func (o PullListOptions) filtered() bool {
|
||||
return o.State == "merged" || o.Draft || o.Head != "" || o.Assignee != "" || o.Search != ""
|
||||
return o.State == "merged" || o.Draft || o.NoAssignee || o.Head != "" || o.Assignee != "" || o.Search != ""
|
||||
}
|
||||
|
||||
// matches applies the filters without a server equivalent to item.
|
||||
@@ -165,6 +166,7 @@ func (o PullListOptions) matches(item Pull) bool {
|
||||
return (o.State != "merged" || item.Merged) && (!o.Draft || item.Draft) &&
|
||||
(branch == "" || (item.Head == branch && (owner == "" || strings.EqualFold(owner, headOwner)))) &&
|
||||
(o.Assignee == "" || slices.ContainsFunc(item.Assignees, func(name string) bool { return strings.EqualFold(name, o.Assignee) })) &&
|
||||
(!o.NoAssignee || len(item.Assignees) == 0) &&
|
||||
(search == "" || strings.Contains(strings.ToLower(item.Title), search) || strings.Contains(strings.ToLower(item.Body), search))
|
||||
}
|
||||
|
||||
@@ -182,41 +184,14 @@ func (s Pulls) ListPage(ctx context.Context, options PullListOptions) (Page[Pull
|
||||
if !options.filtered() {
|
||||
return s.listPage(ctx, options)
|
||||
}
|
||||
if options.Limit <= 0 || options.Page <= 0 {
|
||||
return Page[Pull]{}, errors.New("limit and page must be positive")
|
||||
}
|
||||
query := options
|
||||
if query.State == "merged" {
|
||||
query.State = "closed"
|
||||
}
|
||||
matching, wanted := []Pull{}, options.Page*options.Limit+1
|
||||
for page := 1; ; page++ {
|
||||
if page > maxListPages {
|
||||
return Page[Pull]{}, fmt.Errorf("listing exceeded %d pages", maxListPages)
|
||||
}
|
||||
query.Limit, query.Page = 50, page
|
||||
window, err := s.listPage(ctx, query)
|
||||
if err != nil {
|
||||
return Page[Pull]{}, err
|
||||
}
|
||||
for _, item := range window.Items {
|
||||
if options.matches(item) {
|
||||
matching = append(matching, item)
|
||||
}
|
||||
}
|
||||
if len(matching) >= wanted {
|
||||
items, err := pageOf(matching, options.Limit, options.Page)
|
||||
return Page[Pull]{Items: items, More: true}, err
|
||||
}
|
||||
if len(window.Items) == 0 || (!window.More && len(window.Items) < query.Limit) {
|
||||
break
|
||||
}
|
||||
}
|
||||
items, err := pageOf(matching, options.Limit, options.Page)
|
||||
if err != nil {
|
||||
return Page[Pull]{}, err
|
||||
}
|
||||
return Page[Pull]{Items: items, More: options.Page*options.Limit < len(matching), Total: len(matching), Counted: true}, nil
|
||||
return filteredPage(options.Limit, options.Page, func(limit, page int) (Page[Pull], error) {
|
||||
query.Limit, query.Page = limit, page
|
||||
return s.listPage(ctx, query)
|
||||
}, options.matches)
|
||||
}
|
||||
|
||||
func (s Pulls) listPage(ctx context.Context, options PullListOptions) (Page[Pull], error) {
|
||||
|
||||
Reference in new issue
Block a user