summaryrefslogtreecommitdiff
path: root/app/services/labels
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-10-14 12:33:39 +0200
committerDouwe Maan <douwe@gitlab.com>2015-10-14 12:33:39 +0200
commit3a69dd20a1d8e54c25f871f35f09a1b8b5d4b2a4 (patch)
tree8240d16965886c2a462fe969664de4e7d22b96e9 /app/services/labels
parent03b7fe71a5c5372fc8239a26e757685ab12eed87 (diff)
downloadgitlab-ce-3a69dd20a1d8e54c25f871f35f09a1b8b5d4b2a4.tar.gz
Allow dashboard and group issues/MRs to be filtered by label
Diffstat (limited to 'app/services/labels')
-rw-r--r--app/services/labels/group_service.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/services/labels/group_service.rb b/app/services/labels/group_service.rb
new file mode 100644
index 00000000000..b26cee24d56
--- /dev/null
+++ b/app/services/labels/group_service.rb
@@ -0,0 +1,26 @@
+module Labels
+ class GroupService < ::BaseService
+ def initialize(project_labels)
+ @project_labels = project_labels.group_by(&:title)
+ end
+
+ def execute
+ build(@project_labels)
+ end
+
+ def label(title)
+ if title
+ group_label = @project_labels[title].group_by(&:title)
+ build(group_label).first
+ else
+ nil
+ end
+ end
+
+ private
+
+ def build(label)
+ label.map { |title, labels| GroupLabel.new(title, labels) }
+ end
+ end
+end