gitlab-org--gitlab-foss/app/controllers/projects/artifacts_controller.rb

81 lines
1.7 KiB
Ruby
Raw Normal View History

class Projects::ArtifactsController < Projects::ApplicationController
include ExtractsPath
layout 'project'
before_action :authorize_read_build!
before_action :authorize_update_build!, only: [:keep]
before_action :validate_artifacts!
def download
if artifacts_file.file_storage?
send_file artifacts_file.path, disposition: 'attachment'
else
redirect_to artifacts_file.url
end
end
def browse
directory = params[:path] ? "#{params[:path]}/" : ''
@entry = build.artifacts_metadata_entry(directory)
2016-07-11 11:06:40 +00:00
render_404 unless @entry.exists?
end
def file
entry = build.artifacts_metadata_entry(params[:path])
if entry.exists?
send_artifacts_entry(build, entry)
else
render_404
end
end
2016-06-08 15:18:54 +00:00
def keep
build.keep_artifacts!
redirect_to namespace_project_build_path(project.namespace, project, build)
end
def latest_succeeded
path = ref_name_and_path.last
target_path = artifacts_action_path(path, project, build)
2016-08-18 11:30:20 +00:00
if target_path
redirect_to(target_path)
else
render_404
end
end
private
def validate_artifacts!
render_404 unless build && build.artifacts?
end
def build
@build ||= build_from_id || build_from_ref
end
def build_from_id
project.builds.find_by(id: params[:build_id]) if params[:build_id]
end
def build_from_ref
if params[:ref_name_and_path]
ref_name = ref_name_and_path.first
builds = project.latest_successful_builds_for(ref_name)
builds.find_by(name: params[:job])
end
end
def ref_name_and_path
@ref_name_and_path ||= extract_ref(params[:ref_name_and_path])
end
def artifacts_file
@artifacts_file ||= build.artifacts_file
end
end