summaryrefslogtreecommitdiff
path: root/app/controllers/projects/build_artifacts_controller.rb
blob: 873246f484ef20c5a1a19ff77ccb718fe70cee89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Projects::BuildArtifactsController < Projects::ApplicationController
  include ExtractsPath
  include RendersBlob

  before_action :extract_ref_name_and_path

  def download
    redirect_to download_namespace_project_job_artifacts_path(project.namespace, project, job)
  end

  def browse
    redirect_to browse_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
  end

  def file
    redirect_to file_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
  end

  def raw
    redirect_to raw_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
  end

  def latest_succeeded
    redirect_to latest_succeeded_namespace_project_artifacts_path(project.namespace, project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
  end

  private

  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