BigW Consortium Gitlab

build_details_entity.rb 1.22 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
      project_merge_request_path(project, build.merge_request)
Z.J. van de Weg committed
20
    end
21 22
  end

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

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

  private

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

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

  def project
    build.project
  end
45
end