BigW Consortium Gitlab

build_artifacts_controller.rb 1.31 KB
Newer Older
1 2 3 4
class Projects::BuildArtifactsController < Projects::ApplicationController
  include ExtractsPath
  include RendersBlob

5
  before_action :authorize_read_build!
6
  before_action :extract_ref_name_and_path
7
  before_action :validate_artifacts!
8 9

  def download
10
    redirect_to download_project_job_artifacts_path(project, job)
11 12 13
  end

  def browse
14
    redirect_to browse_project_job_artifacts_path(project, job, path: params[:path])
15 16 17
  end

  def file
18
    redirect_to file_project_job_artifacts_path(project, job, path: params[:path])
19 20 21
  end

  def raw
22
    redirect_to raw_project_job_artifacts_path(project, job, path: params[:path])
23 24 25
  end

  def latest_succeeded
26
    redirect_to latest_succeeded_project_artifacts_path(project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
27 28 29 30
  end

  private

31 32 33 34
  def validate_artifacts!
    render_404 unless job && job.artifacts?
  end

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  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

  def job_from_id
    project.builds.find_by(id: params[:build_id]) if params[:build_id]
  end

  def job_from_ref
    return unless @ref_name

    jobs = project.latest_successful_builds_for(@ref_name)
    jobs.find_by(name: params[:job])
  end
end