This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

build_artifacts_controller.rb 1.45 KB
Newer Older
1
2
# frozen_string_literal: true

Lin Jen-Shin's avatar
Lin Jen-Shin committed
3
4
5
6
class Projects::BuildArtifactsController < Projects::ApplicationController
  include ExtractsPath
  include RendersBlob

7
  before_action :authorize_read_build!
Lin Jen-Shin's avatar
Lin Jen-Shin committed
8
  before_action :extract_ref_name_and_path
9
  before_action :validate_artifacts!, except: [:download]
Lin Jen-Shin's avatar
Lin Jen-Shin committed
10
11

  def download
12
    redirect_to download_project_job_artifacts_path(project, job, params: request.query_parameters)
Lin Jen-Shin's avatar
Lin Jen-Shin committed
13
14
15
  end

  def browse
16
    redirect_to browse_project_job_artifacts_path(project, job, path: params[:path])
Lin Jen-Shin's avatar
Lin Jen-Shin committed
17
18
19
  end

  def file
20
    redirect_to file_project_job_artifacts_path(project, job, path: params[:path])
Lin Jen-Shin's avatar
Lin Jen-Shin committed
21
22
23
  end

  def raw
24
    redirect_to raw_project_job_artifacts_path(project, job, path: params[:path])
Lin Jen-Shin's avatar
Lin Jen-Shin committed
25
26
27
  end

  def latest_succeeded
28
    redirect_to latest_succeeded_project_artifacts_path(project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
Lin Jen-Shin's avatar
Lin Jen-Shin committed
29
30
31
32
  end

  private

33
34
35
36
  def validate_artifacts!
    render_404 unless job && job.artifacts?
  end

Lin Jen-Shin's avatar
Lin Jen-Shin committed
37
38
39
40
41
42
43
44
45
46
  def extract_ref_name_and_path
    return unless params[:ref_name_and_path]

    @ref_name, @path = extract_ref(params[:ref_name_and_path])
  end

  def job
    @job ||= job_from_id || job_from_ref
  end

47
  # rubocop: disable CodeReuse/ActiveRecord
Lin Jen-Shin's avatar
Lin Jen-Shin committed
48
49
50
  def job_from_id
    project.builds.find_by(id: params[:build_id]) if params[:build_id]
  end
51
  # rubocop: enable CodeReuse/ActiveRecord
Lin Jen-Shin's avatar
Lin Jen-Shin committed
52
53
54
55

  def job_from_ref
    return unless @ref_name

56
    project.latest_successful_build_for(params[:job], @ref_name)
Lin Jen-Shin's avatar
Lin Jen-Shin committed
57
58
  end
end