2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class Projects::BuildArtifactsController < Projects::ApplicationController
|
|
|
|
include ExtractsPath
|
|
|
|
include RendersBlob
|
|
|
|
|
|
|
|
before_action :authorize_read_build!
|
|
|
|
before_action :extract_ref_name_and_path
|
2018-12-13 13:39:08 +05:30
|
|
|
before_action :validate_artifacts!, except: [:download]
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def download
|
2018-12-13 13:39:08 +05:30
|
|
|
redirect_to download_project_job_artifacts_path(project, job, params: request.query_parameters)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def browse
|
|
|
|
redirect_to browse_project_job_artifacts_path(project, job, path: params[:path])
|
|
|
|
end
|
|
|
|
|
|
|
|
def file
|
|
|
|
redirect_to file_project_job_artifacts_path(project, job, path: params[:path])
|
|
|
|
end
|
|
|
|
|
|
|
|
def raw
|
|
|
|
redirect_to raw_project_job_artifacts_path(project, job, path: params[:path])
|
|
|
|
end
|
|
|
|
|
|
|
|
def latest_succeeded
|
|
|
|
redirect_to latest_succeeded_project_artifacts_path(project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_artifacts!
|
|
|
|
render_404 unless job && job.artifacts?
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
def job_from_id
|
|
|
|
project.builds.find_by(id: params[:build_id]) if params[:build_id]
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
def job_from_ref
|
|
|
|
return unless @ref_name
|
|
|
|
|
|
|
|
jobs = project.latest_successful_builds_for(@ref_name)
|
|
|
|
jobs.find_by(name: params[:job])
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|