2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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|
|
2017-05-16 07:41:15 -04:00
|
|
|
url_to(:namespace_project_job, 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)
|
2017-08-03 22:20:34 -04:00
|
|
|
public_send("#{route}_url", build.project.namespace, build.project, id || build) # rubocop:disable GitlabSecurity/PublicSend
|
2016-11-14 05:52:29 -05:00
|
|
|
end
|
|
|
|
end
|