summaryrefslogtreecommitdiff
path: root/app/services/milestones
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-06-25 16:19:03 +0200
committerMarin Jankovski <marin@gitlab.com>2014-06-30 09:44:30 +0200
commit58570880f0ffde173de31a0093f6a9d243467fef (patch)
tree60663bfd1930411e1a49afbe827394d4031bc840 /app/services/milestones
parente1afea777a6f0d2e28adc2765c9445cb10bd25f8 (diff)
downloadgitlab-ce-58570880f0ffde173de31a0093f6a9d243467fef.tar.gz
Create group milestones service.
Diffstat (limited to 'app/services/milestones')
-rw-r--r--app/services/milestones/group_service.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/app/services/milestones/group_service.rb b/app/services/milestones/group_service.rb
new file mode 100644
index 00000000000..1655100e012
--- /dev/null
+++ b/app/services/milestones/group_service.rb
@@ -0,0 +1,73 @@
+module Milestones
+ class GroupService < Milestones::BaseService
+ def initialize(group, user, project_milestones)
+ @group = group
+ @user = user
+ @project_milestones = project_milestones.group_by(&:title)
+ end
+
+ def titles
+ @project_milestones.map{ |title, milestone| title }
+ end
+
+ def project_names
+ names = {}
+ @project_milestones.map do |title, milestone|
+ projects = milestone.map{|m| m.project.name }
+ names.store(title, projects)
+ end
+ names
+ end
+
+ def issue_count
+ @project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.issues.count }.sum }
+ end
+
+ def mr_count
+ @project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.merge_requests.count }.sum }
+ end
+
+ def open_issues_count
+ @project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.issues.opened.count }.sum }
+ end
+
+ def closed_issues_count
+ @project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.issues.closed.count }.sum }
+ end
+
+ def open_mr_count
+ @project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.merge_requests.opened.count }.sum }
+ end
+
+ def close_mr_count
+ @project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.merge_requests.closed.count }.sum }
+ end
+
+ def open_items_count
+ open_issues_count.merge(open_mr_count){ |title,issue,mr| issue + mr }
+ end
+
+ def closed_items_count
+ closed_issues_count.merge(close_mr_count){ |title,issue,mr| issue + mr }
+ end
+
+ def total_items_count
+ issue_count.merge(mr_count){ |title,issue,mr| issue + mr }
+ end
+
+ def percent_complete
+ percentage_per_milestone = {}
+ closed_items_count.map do |title, closed_items|
+ total_items = total_items_count[title]
+ percentage = begin
+ ((closed_items * 100) / total_items).abs
+ rescue ZeroDivisionError
+ 100
+ end
+ percentage_per_milestone.store(title, percentage)
+ end
+ percentage_per_milestone
+ end
+
+ end
+end