BigW Consortium Gitlab

analytics_build_entity.rb 890 Bytes
Newer Older
1 2
class AnalyticsBuildEntity < Grape::Entity
  include RequestAwareEntity
3
  include EntityDateHelper
4 5

  expose :name
6
  expose :id
7 8
  expose :ref, as: :branch
  expose :short_sha
9
  expose :author, using: UserEntity
10

11 12 13 14 15
  expose :started_at, as: :date do |build|
    interval_in_words(build[:started_at])
  end

  expose :duration, as: :total_time do |build|
James Lopez committed
16
    build.duration ? distance_of_time_as_hash(build.duration.to_f) : {}
17 18
  end

19 20 21 22 23 24
  expose :branch do
    expose :ref, as: :name

    expose :url do |build|
      url_to(:namespace_project_tree, build, build.ref)
    end
25 26
  end

27 28
  expose :url do |build|
    url_to(:namespace_project_build, build)
29 30 31 32 33 34 35 36 37 38 39 40
  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