2015-12-18 07:41:16 +00:00
|
|
|
class Projects::ArtifactsController < Projects::ApplicationController
|
2016-08-24 08:02:56 +00:00
|
|
|
include ExtractsPath
|
2017-05-02 22:42:37 +00:00
|
|
|
include RendersBlob
|
2016-08-24 08:02:56 +00:00
|
|
|
|
2015-12-17 13:24:43 +00:00
|
|
|
layout 'project'
|
2016-02-01 22:58:04 +00:00
|
|
|
before_action :authorize_read_build!
|
2016-06-10 14:20:11 +00:00
|
|
|
before_action :authorize_update_build!, only: [:keep]
|
2016-08-26 05:10:03 +00:00
|
|
|
before_action :extract_ref_name_and_path
|
2016-06-10 12:39:36 +00:00
|
|
|
before_action :validate_artifacts!
|
2017-09-05 10:27:40 +00:00
|
|
|
before_action :entry, only: [:file]
|
2015-12-17 13:24:43 +00:00
|
|
|
|
|
|
|
def download
|
2016-07-11 11:06:14 +00:00
|
|
|
if artifacts_file.file_storage?
|
|
|
|
send_file artifacts_file.path, disposition: 'attachment'
|
|
|
|
else
|
|
|
|
redirect_to artifacts_file.url
|
2015-12-17 13:24:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-18 07:41:16 +00:00
|
|
|
def browse
|
2017-05-02 22:47:28 +00:00
|
|
|
@path = params[:path]
|
|
|
|
directory = @path ? "#{@path}/" : ''
|
2016-01-13 20:17:28 +00:00
|
|
|
@entry = build.artifacts_metadata_entry(directory)
|
2016-01-11 08:57:03 +00:00
|
|
|
|
2016-07-11 11:06:40 +00:00
|
|
|
render_404 unless @entry.exists?
|
2015-12-17 14:17:00 +00:00
|
|
|
end
|
|
|
|
|
2016-01-09 13:41:43 +00:00
|
|
|
def file
|
2017-05-02 22:42:37 +00:00
|
|
|
blob = @entry.blob
|
2017-05-26 23:27:30 +00:00
|
|
|
conditionally_expand_blob(blob)
|
2016-01-11 09:01:18 +00:00
|
|
|
|
2017-10-05 10:41:22 +00:00
|
|
|
if blob.external_link?(build)
|
2017-10-03 10:34:24 +00:00
|
|
|
redirect_to blob.external_url(@project, build)
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render 'file'
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
render_blob_json(blob)
|
|
|
|
end
|
2017-05-02 22:42:37 +00:00
|
|
|
end
|
2016-01-11 09:01:18 +00:00
|
|
|
end
|
2016-01-09 13:41:43 +00:00
|
|
|
end
|
|
|
|
|
2017-05-02 22:42:37 +00:00
|
|
|
def raw
|
2017-09-05 10:27:40 +00:00
|
|
|
path = Gitlab::Ci::Build::Artifacts::Path
|
|
|
|
.new(params[:path])
|
|
|
|
|
|
|
|
send_artifacts_entry(build, path)
|
2017-05-02 22:42:37 +00:00
|
|
|
end
|
|
|
|
|
2016-06-08 15:18:54 +00:00
|
|
|
def keep
|
|
|
|
build.keep_artifacts!
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_job_path(project, build)
|
2016-06-08 15:18:54 +00:00
|
|
|
end
|
|
|
|
|
2016-08-16 14:10:10 +00:00
|
|
|
def latest_succeeded
|
2016-08-25 07:04:15 +00:00
|
|
|
target_path = artifacts_action_path(@path, project, build)
|
2016-07-12 15:26:30 +00:00
|
|
|
|
2016-08-18 11:30:20 +00:00
|
|
|
if target_path
|
2016-08-18 07:31:20 +00:00
|
|
|
redirect_to(target_path)
|
2016-07-11 10:17:32 +00:00
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-17 13:24:43 +00:00
|
|
|
private
|
|
|
|
|
2016-08-26 05:10:03 +00:00
|
|
|
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-10 12:39:36 +00:00
|
|
|
def validate_artifacts!
|
2016-07-11 10:17:32 +00:00
|
|
|
render_404 unless build && build.artifacts?
|
2016-06-10 12:39:36 +00:00
|
|
|
end
|
|
|
|
|
2015-12-17 13:24:43 +00:00
|
|
|
def build
|
2017-05-02 22:47:28 +00:00
|
|
|
@build ||= begin
|
|
|
|
build = build_from_id || build_from_ref
|
|
|
|
build&.present(current_user: current_user)
|
|
|
|
end
|
2016-07-11 10:17:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_from_id
|
2017-05-16 11:41:15 +00:00
|
|
|
project.builds.find_by(id: params[:job_id]) if params[:job_id]
|
2016-07-11 10:17:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_from_ref
|
2016-08-26 05:10:03 +00:00
|
|
|
return unless @ref_name
|
2016-07-11 10:51:23 +00:00
|
|
|
|
2016-08-26 05:10:03 +00:00
|
|
|
builds = project.latest_successful_builds_for(@ref_name)
|
|
|
|
builds.find_by(name: params[:job])
|
2015-12-17 13:24:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def artifacts_file
|
|
|
|
@artifacts_file ||= build.artifacts_file
|
|
|
|
end
|
2017-05-02 22:42:37 +00:00
|
|
|
|
2017-09-05 10:27:40 +00:00
|
|
|
def entry
|
|
|
|
@entry = build.artifacts_metadata_entry(params[:path])
|
2017-05-02 22:42:37 +00:00
|
|
|
|
|
|
|
render_404 unless @entry.exists?
|
|
|
|
end
|
2015-12-17 13:24:43 +00:00
|
|
|
end
|