Skip to content

ListIssues API labels parameter does AND instead of OR #33509

Open
@wdoekes

Description

@wdoekes

Description

In 024871a the following was added:

--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -43,6 +43,10 @@ func ListIssues(ctx *context.APIContext) {
        //   in: query
        //   description: whether issue is open or closed
        //   type: string
+       // - name: labels
+       //   in: query
+       //   description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
+       //   type: string
...
                issues, err = models.Issues(&models.IssuesOptions{
                        RepoIDs:  []int64{ctx.Repo.Repository.ID},
                        Page:     ctx.QueryInt("page"),
                        PageSize: setting.UI.IssuePagingNum,
                        IsClosed: isClosed,
                        IssueIDs: issueIDs,
+                       LabelIDs: labelIDs,
                })

(which now looks like this since 1e76a82)

+       if len(labelIDs) == 1 && labelIDs[0] == 0 {
+               searchOpt.NoLabelOnly = true
+       } else {
+               for _, labelID := range labelIDs {
+                       if labelID > 0 {
+                               searchOpt.IncludedLabelIDs = append(searchOpt.IncludedLabelIDs, labelID)
+                       } else {
+                               searchOpt.ExcludedLabelIDs = append(searchOpt.ExcludedLabelIDs, -labelID)
+                       }
                }
+       }

These end up in ./modules/indexer/issues/meilisearch/meilisearch.go:

        if options.NoLabelOnly {
                query.And(inner_meilisearch.NewFilterEq("no_label", true))
        } else {
                if len(options.IncludedLabelIDs) > 0 {
                        q := &inner_meilisearch.FilterAnd{}
                        for _, labelID := range options.IncludedLabelIDs {
                                q.And(inner_meilisearch.NewFilterEq("label_ids", labelID))
                        }
                        query.And(q)
                } else if len(options.IncludedAnyLabelIDs) > 0 {
                        query.And(inner_meilisearch.NewFilterIn("label_ids", options.IncludedAnyLabelIDs...))
                }

So, the ListIssues sets the IncludedLabelIDs, not the IncludedAnyLabelIDs option.

There is also a similar API, called SearchIssues, which used to behave the same (in 887a8fe). But that has been refactored to use IncludedAnyLabelIDs (1e76a82 and d638067).

  • Now SearchIssues has proper English ("these labels"),
  • and SearchIssues does what it promises (do an OR-search).

It would be nice if ListIssues either:

  • Has the same labels search behaviour,
  • or updates the documentation.

Thanks!
Walter Doekes
OSSO B.V.

Gitea Version

main/7e596bd7a9378cadbbd9efaf9cc622de554e056c

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

linux

How are you running Gitea?

(running downloaded gitea 1.21.5)

Database

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions