mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-23 14:00:03 +02:00
Add the ability to use multiple labels as filters(#5786)
This commit is contained in:
parent
6a949af8ca
commit
075649572d
9 changed files with 74 additions and 24 deletions
|
@ -1210,7 +1210,7 @@ type IssuesOptions struct {
|
|||
PageSize int
|
||||
IsClosed util.OptionalBool
|
||||
IsPull util.OptionalBool
|
||||
Labels string
|
||||
LabelIDs []int64
|
||||
SortType string
|
||||
IssueIDs []int64
|
||||
}
|
||||
|
@ -1289,15 +1289,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) error {
|
|||
sess.And("issue.is_pull=?", false)
|
||||
}
|
||||
|
||||
if len(opts.Labels) > 0 && opts.Labels != "0" {
|
||||
labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(labelIDs) > 0 {
|
||||
sess.
|
||||
Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
|
||||
In("issue_label.label_id", labelIDs)
|
||||
if opts.LabelIDs != nil {
|
||||
for i, labelID := range opts.LabelIDs {
|
||||
sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
|
||||
fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -1475,9 +1470,11 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
|
|||
labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))
|
||||
if err != nil {
|
||||
log.Warn("Malformed Labels argument: %s", opts.Labels)
|
||||
} else if len(labelIDs) > 0 {
|
||||
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
|
||||
In("issue_label.label_id", labelIDs)
|
||||
} else {
|
||||
for i, labelID := range labelIDs {
|
||||
sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
|
||||
fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue