summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2019-01-23 06:10:38 +0200
committertechknowlogick <matti@mdranta.net>2019-01-22 23:10:38 -0500
commit075649572d4472b588a8484ce3d7c37df7621f85 (patch)
tree5658dfda46b32c0686895615bceffbdac01ef4a3 /models/issue.go
parent6a949af8ca3aaa30f917c8ed792ae88bbaafdd75 (diff)
downloadgitea-075649572d4472b588a8484ce3d7c37df7621f85.tar.gz
gitea-075649572d4472b588a8484ce3d7c37df7621f85.zip
Add the ability to use multiple labels as filters(#5786)
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go23
1 files changed, 10 insertions, 13 deletions
diff --git a/models/issue.go b/models/issue.go
index baca512ab0..850346674b 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -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))
+ }
}
}