Extract ref_name and path in before_action, feedback:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5142#note_14469768
This commit is contained in:
Lin Jen-Shin 2016-08-26 13:10:03 +08:00
parent 6a2d2bd18d
commit b17df0507b

View file

@ -4,6 +4,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
layout 'project'
before_action :authorize_read_build!
before_action :authorize_update_build!, only: [:keep]
before_action :extract_ref_name_and_path
before_action :validate_artifacts!
def download
@ -48,6 +49,12 @@ class Projects::ArtifactsController < Projects::ApplicationController
private
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!
render_404 unless build && build.artifacts?
end
@ -61,13 +68,11 @@ class Projects::ArtifactsController < Projects::ApplicationController
end
def build_from_ref
if params[:ref_name_and_path]
ref_name, @path = extract_ref(params[:ref_name_and_path])
builds = project.latest_successful_builds_for(ref_name)
return unless @ref_name
builds = project.latest_successful_builds_for(@ref_name)
builds.find_by(name: params[:job])
end
end
def artifacts_file
@artifacts_file ||= build.artifacts_file