diff options
author | Małgorzata Ksionek <mksionek@gitlab.com> | 2019-07-06 22:15:13 +0200 |
---|---|---|
committer | Małgorzata Ksionek <mksionek@gitlab.com> | 2019-07-23 12:01:39 +0200 |
commit | 1b102f5d119009575bda43bfc9b0ae8365f67c50 (patch) | |
tree | 2bcd75bed34aa6f11fef53db9984d4851d4ce1de /lib | |
parent | f4101aeac73368adcab223f14bf3d4d92d718b8b (diff) | |
download | gitlab-ce-1b102f5d119009575bda43bfc9b0ae8365f67c50.tar.gz |
Add basic project extraction
To allow project filtering
Prepare summary for accepting multiple groups
Modify deploys group summary class
Add filtering by project name in issues summary
Fix rubocop offences
Add changelog entry
Change name to id in project filtering
Fix rebase problem
Add project extraction
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/cycle_analytics/base_data_extraction.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/base_event_fetcher.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/base_stage.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/group_stage_summary.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/summary/group/base.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/summary/group/deploy.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/summary/group/issue.rb | 13 |
7 files changed, 55 insertions, 35 deletions
diff --git a/lib/gitlab/cycle_analytics/base_data_extraction.rb b/lib/gitlab/cycle_analytics/base_data_extraction.rb new file mode 100644 index 00000000000..deadf47f146 --- /dev/null +++ b/lib/gitlab/cycle_analytics/base_data_extraction.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module BaseDataExtraction + private + + def projects + group ? extract_projects(options) : [project] + end + + def group + @group ||= options.fetch(:group, nil) + end + + def project + @project ||= options.fetch(:project, nil) + end + + def extract_projects(options) + projects = Project.inside_path(group.full_path) + projects = projects.where(id: options[:projects]) if options[:projects] + projects + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/base_event_fetcher.rb b/lib/gitlab/cycle_analytics/base_event_fetcher.rb index 96aa799e864..0f5186e06e7 100644 --- a/lib/gitlab/cycle_analytics/base_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/base_event_fetcher.rb @@ -4,6 +4,7 @@ module Gitlab module CycleAnalytics class BaseEventFetcher include BaseQuery + include BaseDataExtraction attr_reader :projections, :query, :stage, :order, :options @@ -73,18 +74,6 @@ module Gitlab def serialization_context {} end - - def projects - group ? Project.inside_path(group.full_path) : [project] - end - - def group - @group ||= options.fetch(:group, nil) - end - - def project - @project ||= options.fetch(:project, nil) - end end end end diff --git a/lib/gitlab/cycle_analytics/base_stage.rb b/lib/gitlab/cycle_analytics/base_stage.rb index 678a891e941..e641bed704b 100644 --- a/lib/gitlab/cycle_analytics/base_stage.rb +++ b/lib/gitlab/cycle_analytics/base_stage.rb @@ -4,6 +4,7 @@ module Gitlab module CycleAnalytics class BaseStage include BaseQuery + include BaseDataExtraction attr_reader :options @@ -77,18 +78,6 @@ module Gitlab def event_options options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs) end - - def projects - group ? Project.inside_path(group.full_path) : [project] - end - - def group - @group ||= options.fetch(:group, nil) - end - - def project - @project ||= options.fetch(:project, nil) - end end end end diff --git a/lib/gitlab/cycle_analytics/group_stage_summary.rb b/lib/gitlab/cycle_analytics/group_stage_summary.rb index 7b5c74e1a1b..f867d511f65 100644 --- a/lib/gitlab/cycle_analytics/group_stage_summary.rb +++ b/lib/gitlab/cycle_analytics/group_stage_summary.rb @@ -3,15 +3,16 @@ module Gitlab module CycleAnalytics class GroupStageSummary - def initialize(group, from:, current_user:) + def initialize(group, from:, current_user:, options:) @group = group @from = from @current_user = current_user + @options = options end def data - [serialize(Summary::Group::Issue.new(group: @group, from: @from, current_user: @current_user)), - serialize(Summary::Group::Deploy.new(group: @group, from: @from))] + [serialize(Summary::Group::Issue.new(group: @group, from: @from, current_user: @current_user, options: @options)), + serialize(Summary::Group::Deploy.new(group: @group, from: @from, options: @options))] end private diff --git a/lib/gitlab/cycle_analytics/summary/group/base.rb b/lib/gitlab/cycle_analytics/summary/group/base.rb index 7f18b61d309..d147879ace4 100644 --- a/lib/gitlab/cycle_analytics/summary/group/base.rb +++ b/lib/gitlab/cycle_analytics/summary/group/base.rb @@ -5,9 +5,10 @@ module Gitlab module Summary module Group class Base - def initialize(group:, from:) + def initialize(group:, from:, options:) @group = group @from = from + @options = options end def title diff --git a/lib/gitlab/cycle_analytics/summary/group/deploy.rb b/lib/gitlab/cycle_analytics/summary/group/deploy.rb index d8fcd8f2ce4..ec0b23e770d 100644 --- a/lib/gitlab/cycle_analytics/summary/group/deploy.rb +++ b/lib/gitlab/cycle_analytics/summary/group/deploy.rb @@ -10,15 +10,19 @@ module Gitlab end def value - @value ||= Deployment.joins(:project) - .where(projects: { id: projects }) - .where("deployments.created_at > ?", @from) - .success - .count + @value ||= find_deployments end private + def find_deployments + deployments = Deployment.joins(:project) + .where(projects: { id: projects }) + .where("deployments.created_at > ?", @from) + deployments = deployments.where(projects: { id: @options[:projects] }) if @options[:projects] + deployments.success.count + end + def projects Project.inside_path(@group.full_path).ids end diff --git a/lib/gitlab/cycle_analytics/summary/group/issue.rb b/lib/gitlab/cycle_analytics/summary/group/issue.rb index 70073e6d843..5df508efa78 100644 --- a/lib/gitlab/cycle_analytics/summary/group/issue.rb +++ b/lib/gitlab/cycle_analytics/summary/group/issue.rb @@ -5,10 +5,11 @@ module Gitlab module Summary module Group class Issue < Group::Base - def initialize(group:, from:, current_user:) + def initialize(group:, from:, current_user:, options:) @group = group @from = from @current_user = current_user + @options = options end def title @@ -16,7 +17,15 @@ module Gitlab end def value - @value ||= IssuesFinder.new(@current_user, group_id: @group.id, include_subgroups: true, created_after: @from).execute.count + @value ||= find_issues + end + + private + + def find_issues + issues = IssuesFinder.new(@current_user, group_id: @group.id, include_subgroups: true, created_after: @from).execute + issues = issues.where(projects: { id: @options[:projects] }) if @options[:projects] + issues.count end end end |