Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-11-14 13:52:29 +0300
committerJames Lopez <james@jameslopez.es>2016-11-17 10:22:58 +0300
commit81d0146c4cf0d34b1b81da770483ed864482149c (patch)
tree5c634b0fff5df0b5fe148a7cbbaee914b47cfcf5 /app/serializers/analytics_build_entity.rb
parent1744d633eded81103ee4691e6980efb6930dc975 (diff)
WIP - refactoring URL builder and events presenter into serializers
Diffstat (limited to 'app/serializers/analytics_build_entity.rb')
-rw-r--r--app/serializers/analytics_build_entity.rb27
1 files changed, 27 insertions, 0 deletions
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