summaryrefslogtreecommitdiff
path: root/app/models/cycle_analytics
diff options
context:
space:
mode:
authorMałgorzata Ksionek <mksionek@gitlab.com>2019-07-04 16:42:31 +0200
committerMałgorzata Ksionek <mksionek@gitlab.com>2019-07-15 15:06:40 +0200
commitbeaa63530669d10c7244d187fa386144bc5da7eb (patch)
treebc541f200d5a5b2c37ff50e1a75ad1b848e6c396 /app/models/cycle_analytics
parent0e8af2525f16d871510c24e6e15f1bc80f133edd (diff)
downloadgitlab-ce-beaa63530669d10c7244d187fa386144bc5da7eb.tar.gz
Add class for group level analytics
Add specs for group level Update entities Update base classes Add groups-centric changes Update plan and review stage Add summary classes Add summary spec Update specs files Add to specs test cases for group Add changelog entry Add group serializer Fix typo Fix typo Add fetching namespace in sql query Update specs Add rubocop fix Add rubocop fix Modify method to be in sync with code review Add counting deploys from subgroup To group summary stage Add subgroups handling In group stage summary Add additional spec Add additional specs Add more precise inheritance Add attr reader to group level Fix rubocop offence Fix problems with specs Add cr remarks Renaming median method and a lot of calls in specs Move spec setup Rename method in specs Add code review remarks regarding module Add proper module name
Diffstat (limited to 'app/models/cycle_analytics')
-rw-r--r--app/models/cycle_analytics/base_methods.rb (renamed from app/models/cycle_analytics/base.rb)6
-rw-r--r--app/models/cycle_analytics/group_level.rb30
-rw-r--r--app/models/cycle_analytics/project_level.rb5
3 files changed, 36 insertions, 5 deletions
diff --git a/app/models/cycle_analytics/base.rb b/app/models/cycle_analytics/base_methods.rb
index d7b28cd1b67..1c2a0854769 100644
--- a/app/models/cycle_analytics/base.rb
+++ b/app/models/cycle_analytics/base_methods.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
module CycleAnalytics
- class Base
+ module BaseMethods
STAGES = %i[issue plan code test review staging production].freeze
def all_medians_by_stage
STAGES.each_with_object({}) do |stage_name, medians_per_stage|
- medians_per_stage[stage_name] = self[stage_name].median
+ medians_per_stage[stage_name] = self[stage_name].project_median
end
end
@@ -21,7 +21,7 @@ module CycleAnalytics
end
def [](stage_name)
- Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
+ Gitlab::CycleAnalytics::Stage[stage_name].new(options: options)
end
end
end
diff --git a/app/models/cycle_analytics/group_level.rb b/app/models/cycle_analytics/group_level.rb
new file mode 100644
index 00000000000..58bd2eb0d9a
--- /dev/null
+++ b/app/models/cycle_analytics/group_level.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module CycleAnalytics
+ class GroupLevel
+ include BaseMethods
+ attr_reader :options
+
+ def initialize(options:)
+ @options = options
+ end
+
+ def summary
+ @summary ||= ::Gitlab::CycleAnalytics::GroupStageSummary.new(options[:group],
+ from: options[:from],
+ current_user: options[:current_user]).data
+ end
+
+ def permissions(user: nil)
+ STAGES.each_with_object({}) do |stage, obj|
+ obj[stage] = true
+ end
+ end
+
+ def stats
+ @stats ||= STAGES.map do |stage_name|
+ self[stage_name].as_json(serializer: GroupAnalyticsStageSerializer)
+ end
+ end
+ end
+end
diff --git a/app/models/cycle_analytics/project_level.rb b/app/models/cycle_analytics/project_level.rb
index 22631cc7d41..abe1be11eae 100644
--- a/app/models/cycle_analytics/project_level.rb
+++ b/app/models/cycle_analytics/project_level.rb
@@ -1,12 +1,13 @@
# frozen_string_literal: true
module CycleAnalytics
- class ProjectLevel < Base
+ class ProjectLevel
+ include BaseMethods
attr_reader :project, :options
def initialize(project, options:)
@project = project
- @options = options
+ @options = options.merge(project: project)
end
def summary