debian-mirror-gitlab/app/controllers/projects/artifacts_controller.rb

108 lines
2.3 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
class Projects::ArtifactsController < Projects::ApplicationController
2016-09-29 09:46:39 +05:30
include ExtractsPath
2017-08-17 22:00:37 +05:30
include RendersBlob
2018-05-09 12:01:36 +05:30
include SendFileUpload
2016-09-29 09:46:39 +05:30
layout 'project'
2016-04-02 18:10:28 +05:30
before_action :authorize_read_build!
before_action :authorize_update_build!, only: [:keep]
2016-09-29 09:46:39 +05:30
before_action :extract_ref_name_and_path
2018-12-13 13:39:08 +05:30
before_action :validate_artifacts!, except: [:download]
2018-03-17 18:26:18 +05:30
before_action :entry, only: [:file]
def download
2018-12-05 23:21:45 +05:30
return render_404 unless artifacts_file
2018-12-13 13:39:08 +05:30
send_upload(artifacts_file, attachment: artifacts_file.filename, proxy: params[:proxy])
end
def browse
2017-08-17 22:00:37 +05:30
@path = params[:path]
directory = @path ? "#{@path}/" : ''
@entry = build.artifacts_metadata_entry(directory)
2016-09-29 09:46:39 +05:30
render_404 unless @entry.exists?
end
def file
2017-08-17 22:00:37 +05:30
blob = @entry.blob
2017-09-10 17:25:29 +05:30
conditionally_expand_blob(blob)
2018-03-17 18:26:18 +05:30
if blob.external_link?(build)
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-08-17 22:00:37 +05:30
end
end
end
2017-08-17 22:00:37 +05:30
def raw
2018-05-09 12:01:36 +05:30
path = Gitlab::Ci::Build::Artifacts::Path.new(params[:path])
2018-03-17 18:26:18 +05:30
send_artifacts_entry(build, path)
2017-08-17 22:00:37 +05:30
end
def keep
build.keep_artifacts!
2017-09-10 17:25:29 +05:30
redirect_to project_job_path(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
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
def validate_artifacts!
2018-05-09 12:01:36 +05:30
render_404 unless build&.artifacts?
end
def build
2017-08-17 22:00:37 +05:30
@build ||= begin
build = build_from_id || build_from_ref
build&.present(current_user: current_user)
end
2016-09-29 09:46:39 +05:30
end
def build_from_id
2019-03-02 22:35:43 +05:30
project.builds.find_by_id(params[:job_id]) if params[:job_id]
2016-09-29 09:46:39 +05:30
end
def build_from_ref
return unless @ref_name
2019-03-02 22:35:43 +05:30
project.latest_successful_build_for(params[:job], @ref_name)
end
def artifacts_file
2018-12-13 13:39:08 +05:30
@artifacts_file ||= build&.artifacts_file_for_type(params[:file_type] || :archive)
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
def entry
@entry = build.artifacts_metadata_entry(params[:path])
2017-08-17 22:00:37 +05:30
render_404 unless @entry.exists?
end
end