build_details_entity.rb 2.17 KB
Newer Older
1
2
# frozen_string_literal: true

3
class BuildDetailsEntity < JobEntity
4
5
  expose :coverage, :erased_at, :duration
  expose :tag_list, as: :tags
6
  expose :user, using: UserEntity
7
8
  expose :runner, using: RunnerEntity
  expose :pipeline, using: PipelineEntity
9

Tomasz Maczukin's avatar
Tomasz Maczukin committed
10
  expose :metadata, using: BuildMetadataEntity
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do
    expose :download_path, if: -> (*) { build.artifacts? } do |build|
      download_project_job_artifacts_path(project, build)
    end

    expose :browse_path, if: -> (*) { build.browsable_artifacts? } do |build|
      browse_project_job_artifacts_path(project, build)
    end

    expose :keep_path, if: -> (*) { build.has_expiring_artifacts? && can?(current_user, :update_build, build) } do |build|
      keep_project_job_artifacts_path(project, build)
    end

    expose :expire_at, if: -> (*) { build.artifacts_expire_at.present? } do |build|
      build.artifacts_expire_at
    end

    expose :expired, if: -> (*) { build.artifacts_expire_at.present? } do |build|
      build.artifacts_expired?
    end
  end

Z.J. van de Weg's avatar
Z.J. van de Weg committed
34
  expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
Shinya Maeda's avatar
Shinya Maeda committed
35
  expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
36
    erase_project_job_path(project, build)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
37
38
  end

39
  expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
Z.J. van de Weg's avatar
Z.J. van de Weg committed
40
41
42
43
44
    expose :iid do |build|
      build.merge_request.iid
    end

    expose :path do |build|
45
46
      project_merge_request_path(build.merge_request.project,
                                 build.merge_request)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
47
    end
48
49
  end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
50
  expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) && build.failed? } do |build|
51
    new_project_issue_path(project, issue: build_failed_issue_options)
52
53
54
  end

  expose :raw_path do |build|
55
    raw_project_job_path(project, build)
56
  end
Z.J. van de Weg's avatar
Z.J. van de Weg committed
57
58
59

  private

Kamil Trzcinski's avatar
Kamil Trzcinski committed
60
  def build_failed_issue_options
61
    { title: "Job Failed ##{build.id}",
62
      description: "Job [##{build.id}](#{project_job_url(project, build)}) failed for #{build.sha}:\n" }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
63
64
  end

Z.J. van de Weg's avatar
Z.J. van de Weg committed
65
66
67
68
69
70
71
  def current_user
    request.current_user
  end

  def project
    build.project
  end
72
end