2016-01-19 16:12:03 +05:30
|
|
|
class Projects::ArtifactsController < Projects::ApplicationController
|
2016-09-29 09:46:39 +05:30
|
|
|
include ExtractsPath
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
layout 'project'
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :authorize_read_build!
|
2016-06-16 23:09:34 +05:30
|
|
|
before_action :authorize_update_build!, only: [:keep]
|
2016-09-29 09:46:39 +05:30
|
|
|
before_action :extract_ref_name_and_path
|
2016-06-16 23:09:34 +05:30
|
|
|
before_action :validate_artifacts!
|
2016-01-19 16:12:03 +05:30
|
|
|
|
|
|
|
def download
|
2016-09-29 09:46:39 +05:30
|
|
|
if artifacts_file.file_storage?
|
|
|
|
send_file artifacts_file.path, disposition: 'attachment'
|
|
|
|
else
|
|
|
|
redirect_to artifacts_file.url
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def browse
|
|
|
|
directory = params[:path] ? "#{params[:path]}/" : ''
|
|
|
|
@entry = build.artifacts_metadata_entry(directory)
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
render_404 unless @entry.exists?
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def file
|
|
|
|
entry = build.artifacts_metadata_entry(params[:path])
|
|
|
|
|
|
|
|
if entry.exists?
|
2016-08-24 12:49:21 +05:30
|
|
|
send_artifacts_entry(build, entry)
|
2016-01-19 16:12:03 +05:30
|
|
|
else
|
2016-08-24 12:49:21 +05:30
|
|
|
render_404
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def keep
|
|
|
|
build.keep_artifacts!
|
|
|
|
redirect_to namespace_project_build_path(project.namespace, project, build)
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def latest_succeeded
|
|
|
|
target_path = artifacts_action_path(@path, project, build)
|
|
|
|
|
|
|
|
if target_path
|
|
|
|
redirect_to(target_path)
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
private
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def extract_ref_name_and_path
|
|
|
|
return unless params[:ref_name_and_path]
|
|
|
|
|
|
|
|
@ref_name, @path = extract_ref(params[:ref_name_and_path])
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def validate_artifacts!
|
2016-09-29 09:46:39 +05:30
|
|
|
render_404 unless build && build.artifacts?
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
def build
|
2016-09-29 09:46:39 +05:30
|
|
|
@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
|
|
|
|
return unless @ref_name
|
|
|
|
|
|
|
|
builds = project.latest_successful_builds_for(@ref_name)
|
|
|
|
builds.find_by(name: params[:job])
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def artifacts_file
|
|
|
|
@artifacts_file ||= build.artifacts_file
|
|
|
|
end
|
|
|
|
end
|