diff options
author | James Lopez <james@jameslopez.es> | 2016-11-17 15:22:27 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 15:22:27 +0300 |
commit | ed39d61d746925e49d952bd8169499d3200ae68b (patch) | |
tree | 33128144980f4b62e96309e9ed4c23133422159b /app | |
parent | f9de157e70234748cf4285fafda7b3ec13862f5c (diff) |
refactor events facade so it uses separate classes and refactor query stuff
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/cycle_analytics/events_controller.rb | 2 | ||||
-rw-r--r-- | app/models/cycle_analytics.rb | 17 | ||||
-rw-r--r-- | app/serializers/analytics_generic_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/analytics_issue_entity.rb (renamed from app/serializers/analytics_generic_entity.rb) | 5 | ||||
-rw-r--r-- | app/serializers/analytics_issue_serializer.rb | 3 | ||||
-rw-r--r-- | app/serializers/analytics_merge_request_entity.rb | 7 | ||||
-rw-r--r-- | app/serializers/analytics_merge_request_serializer.rb | 3 |
7 files changed, 24 insertions, 15 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index 2b4db0fd4aa..81b59b4804b 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -19,7 +19,7 @@ module Projects end def test - @options = { from: start_date(events_params), branch: events_params[:branch_name] } + @options[:branch] = events_params[:branch_name] render_events(events.test_events) end diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index 30ca3273a2c..314a1ce9b63 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -1,9 +1,8 @@ class CycleAnalytics - include Gitlab::CycleAnalytics::MetricsFetcher - def initialize(project, from:) @project = project @from = from + @fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: from, branch: nil) end def summary @@ -11,45 +10,45 @@ class CycleAnalytics end def issue - calculate_metric(:issue, + @fetcher.calculate_metric(:issue, Issue.arel_table[:created_at], [Issue::Metrics.arel_table[:first_associated_with_milestone_at], Issue::Metrics.arel_table[:first_added_to_board_at]]) end def plan - calculate_metric(:plan, + @fetcher.calculate_metric(:plan, [Issue::Metrics.arel_table[:first_associated_with_milestone_at], Issue::Metrics.arel_table[:first_added_to_board_at]], Issue::Metrics.arel_table[:first_mentioned_in_commit_at]) end def code - calculate_metric(:code, + @fetcher.calculate_metric(:code, Issue::Metrics.arel_table[:first_mentioned_in_commit_at], MergeRequest.arel_table[:created_at]) end def test - calculate_metric(:test, + @fetcher.calculate_metric(:test, MergeRequest::Metrics.arel_table[:latest_build_started_at], MergeRequest::Metrics.arel_table[:latest_build_finished_at]) end def review - calculate_metric(:review, + @fetcher.calculate_metric(:review, MergeRequest.arel_table[:created_at], MergeRequest::Metrics.arel_table[:merged_at]) end def staging - calculate_metric(:staging, + @fetcher.calculate_metric(:staging, MergeRequest::Metrics.arel_table[:merged_at], MergeRequest::Metrics.arel_table[:first_deployed_to_production_at]) end def production - calculate_metric(:production, + @fetcher.calculate_metric(:production, Issue.arel_table[:created_at], MergeRequest::Metrics.arel_table[:first_deployed_to_production_at]) end diff --git a/app/serializers/analytics_generic_serializer.rb b/app/serializers/analytics_generic_serializer.rb index 9000e25a91d..9f4859e8410 100644 --- a/app/serializers/analytics_generic_serializer.rb +++ b/app/serializers/analytics_generic_serializer.rb @@ -1,6 +1,4 @@ class AnalyticsGenericSerializer < BaseSerializer - entity AnalyticsGenericEntity - def represent(resource, opts = {}) resource.symbolize_keys! diff --git a/app/serializers/analytics_generic_entity.rb b/app/serializers/analytics_issue_entity.rb index 203cf39b940..44c50f18613 100644 --- a/app/serializers/analytics_generic_entity.rb +++ b/app/serializers/analytics_issue_entity.rb @@ -1,9 +1,8 @@ -class AnalyticsGenericEntity < Grape::Entity +class AnalyticsIssueEntity < Grape::Entity include RequestAwareEntity include EntityDateHelper expose :title - expose :state, if: ->(_instance, options) { options[:request].entity == :merge_request } expose :author, using: UserEntity expose :iid do |object| @@ -19,7 +18,7 @@ class AnalyticsGenericEntity < Grape::Entity end expose :url do |object| - url_to("namespace_project_#{request.entity}".to_sym, id: object[:iid].to_s) + url_to(:namespace_project_issue, id: object[:iid].to_s) end private diff --git a/app/serializers/analytics_issue_serializer.rb b/app/serializers/analytics_issue_serializer.rb new file mode 100644 index 00000000000..4fb3e8f1bb4 --- /dev/null +++ b/app/serializers/analytics_issue_serializer.rb @@ -0,0 +1,3 @@ +class AnalyticsIssueSerializer < AnalyticsGenericSerializer + entity AnalyticsIssueEntity +end diff --git a/app/serializers/analytics_merge_request_entity.rb b/app/serializers/analytics_merge_request_entity.rb new file mode 100644 index 00000000000..888265eaa38 --- /dev/null +++ b/app/serializers/analytics_merge_request_entity.rb @@ -0,0 +1,7 @@ +class AnalyticsMergeRequestEntity < AnalyticsIssueEntity + expose :state + + expose :url do |object| + url_to(:namespace_project_merge_request, id: object[:iid].to_s) + end +end diff --git a/app/serializers/analytics_merge_request_serializer.rb b/app/serializers/analytics_merge_request_serializer.rb new file mode 100644 index 00000000000..4622a1dd855 --- /dev/null +++ b/app/serializers/analytics_merge_request_serializer.rb @@ -0,0 +1,3 @@ +class AnalyticsMergeRequestSerializer < AnalyticsGenericSerializer + entity AnalyticsMergeRequestEntity +end |