2016-11-14 05:52:29 -05:00
|
|
|
class AnalyticsBuildEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
2016-11-15 05:36:39 -05:00
|
|
|
include EntityDateHelper
|
2016-11-14 05:52:29 -05:00
|
|
|
|
|
|
|
expose :name
|
2016-11-14 08:53:06 -05:00
|
|
|
expose :id
|
2016-11-14 05:52:29 -05:00
|
|
|
expose :ref, as: :branch
|
|
|
|
expose :short_sha
|
2016-11-14 08:53:06 -05:00
|
|
|
expose :author, using: UserEntity
|
2016-11-14 05:52:29 -05:00
|
|
|
|
2016-11-15 05:36:39 -05:00
|
|
|
expose :started_at, as: :date do |build|
|
|
|
|
interval_in_words(build[:started_at])
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :duration, as: :total_time do |build|
|
2016-11-29 06:41:11 -05:00
|
|
|
build.duration ? distance_of_time_as_hash(build.duration.to_f) : {}
|
2016-11-15 05:36:39 -05:00
|
|
|
end
|
|
|
|
|
2016-11-14 08:53:06 -05:00
|
|
|
expose :branch do
|
|
|
|
expose :ref, as: :name
|
|
|
|
|
|
|
|
expose :url do |build|
|
|
|
|
url_to(:namespace_project_tree, build, build.ref)
|
|
|
|
end
|
2016-11-14 05:52:29 -05:00
|
|
|
end
|
|
|
|
|
2016-11-14 08:53:06 -05:00
|
|
|
expose :url do |build|
|
|
|
|
url_to(:namespace_project_build, build)
|
2016-11-14 05:52:29 -05:00
|
|
|
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
|