diff options
author | James Lopez <james@jameslopez.es> | 2016-11-14 11:52:29 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:58 +0100 |
commit | 81d0146c4cf0d34b1b81da770483ed864482149c (patch) | |
tree | 5c634b0fff5df0b5fe148a7cbbaee914b47cfcf5 /app | |
parent | 1744d633eded81103ee4691e6980efb6930dc975 (diff) | |
download | gitlab-ce-81d0146c4cf0d34b1b81da770483ed864482149c.tar.gz |
WIP - refactoring URL builder and events presenter into serializers
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/cycle_analytics/events_controller.rb | 4 | ||||
-rw-r--r-- | app/serializers/analytics_build_entity.rb | 27 | ||||
-rw-r--r-- | app/serializers/analytics_build_serializer.rb | 3 |
3 files changed, 32 insertions, 2 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index bb9f93908ad..77b49d6c4b9 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -35,10 +35,10 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll private - def render_events(events) + def render_events(events_list) respond_to do |format| format.html - format.json { render json: { events: events } } + format.json { render json: { events: events_list } } end end diff --git a/app/serializers/analytics_build_entity.rb b/app/serializers/analytics_build_entity.rb new file mode 100644 index 00000000000..7ed89f1f347 --- /dev/null +++ b/app/serializers/analytics_build_entity.rb @@ -0,0 +1,27 @@ +class AnalyticsBuildEntity < Grape::Entity + include RequestAwareEntity + + expose :name + expose :ref, as: :branch + expose :short_sha + expose :started_at, as: :date + expose :duration, as: :total_time + + expose :url do |build| + url_to(:namespace_project_build, build) + end + + expose :branch_url do |build| + url_to(:namespace_project_tree, build, build.ref) + end + + expose :commit_url do |build| + url_to(:namespace_project_commit, build, build.sha) + end + + private + + def url_to(route, build, id = nil) + public_send("#{route}_url", build.project.namespace, build.project, id || build) + end +end diff --git a/app/serializers/analytics_build_serializer.rb b/app/serializers/analytics_build_serializer.rb new file mode 100644 index 00000000000..f172d67d356 --- /dev/null +++ b/app/serializers/analytics_build_serializer.rb @@ -0,0 +1,3 @@ +class AnalyticsBuildSerializer < BaseSerializer + entity AnalyticsBuildEntity +end |