BigW Consortium Gitlab

build_details_entity.rb 1.27 KB
Newer Older
1
class BuildDetailsEntity < JobEntity
2 3
  expose :coverage, :erased_at, :duration
  expose :tag_list, as: :tags
4
  expose :user, using: UserEntity
5 6
  expose :runner, using: RunnerEntity
  expose :pipeline, using: PipelineEntity
7

Z.J. van de Weg committed
8 9
  expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
  expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :update_build, project) } do |build|
10
    erase_project_job_path(project, build)
Z.J. van de Weg committed
11 12
  end

13
  expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
Z.J. van de Weg committed
14 15 16 17 18
    expose :iid do |build|
      build.merge_request.iid
    end

    expose :path do |build|
19 20
      project_merge_request_path(build.merge_request.project,
                                 build.merge_request)
Z.J. van de Weg committed
21
    end
22 23
  end

Kamil Trzcinski committed
24
  expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) && build.failed? } do |build|
25
    new_project_issue_path(project, issue: build_failed_issue_options)
26 27 28
  end

  expose :raw_path do |build|
29
    raw_project_job_path(project, build)
30
  end
31 32 33

  private

Kamil Trzcinski committed
34
  def build_failed_issue_options
35
    { title: "Build Failed ##{build.id}",
36
      description: project_job_path(project, build) }
Kamil Trzcinski committed
37 38
  end

39 40 41 42 43 44 45
  def current_user
    request.current_user
  end

  def project
    build.project
  end
46
end