Commit f07e1876 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Use controllers to redirect

parent 41490904
class Projects::BuildArtifactsController < Projects::ApplicationController
include ExtractsPath
include RendersBlob
before_action :extract_ref_name_and_path
def download
redirect_to download_namespace_project_job_artifacts_path(project.namespace, project, job)
end
def browse
redirect_to browse_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
end
def file
redirect_to file_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
end
def raw
redirect_to raw_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
end
def latest_succeeded
redirect_to latest_succeeded_namespace_project_artifacts_path(project.namespace, project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
end
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 job
@job ||= job_from_id || job_from_ref
end
def job_from_id
project.builds.find_by(id: params[:build_id]) if params[:build_id]
end
def job_from_ref
return unless @ref_name
jobs = project.latest_successful_builds_for(@ref_name)
jobs.find_by(name: params[:job])
end
end
class Projects::BuildsController < Projects::ApplicationController
def index
redirect_to namespace_project_jobs_path(project.namespace, project)
end
def show
redirect_to namespace_project_job_path(project.namespace, project, job)
end
def trace
redirect_to trace_namespace_project_job_path(project.namespace, project, job, format: params[:format])
end
def status
redirect_to status_namespace_project_job_path(project.namespace, project, job, format: params[:format])
end
def raw
redirect_to raw_namespace_project_job_path(project.namespace, project, job)
end
private
def job
@job ||= project.builds.find(params[:id])
end
end
module Gitlab
module Routes
class LegacyBuilds
......@@ -10,51 +9,32 @@ module Gitlab
end
def draw
redirect_artifacts = @map.redirect(&method(:redirect_artifacts))
redirect_builds = @map.redirect(&method(:redirect_builds))
@map.get '/builds(/:id)/artifacts/*action', to: redirect_artifacts,
as: 'legacy_artifacts',
format: false
@map.get '/builds(/:id(/*action))', to: redirect_builds,
as: 'legacy_builds',
@map.instance_eval do
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do
resources :artifacts, only: [], controller: 'build_artifacts' do
collection do
get :latest_succeeded,
path: '*ref_name_and_path',
format: false
end
private
def redirect_artifacts(params, req)
if params[:id]
project = fake_project(*params.values_at(:namespace_id, :project_id))
artifacts_action_path(params[:action], project, params[:id])
else
latest_succeeded_namespace_project_artifacts_path(params[:namespace_id], params[:project_id], params[:action], job: req.GET[:job])
end
end
def redirect_builds(params, req)
args = params.values_at(:namespace_id, :project_id, :id).compact
member do
get :status
get :trace, defaults: { format: 'json' }
get :raw
end
if params[:id]
case params[:action]
when 'status'
status_namespace_project_job_path(*args, format: params[:format])
when 'trace'
trace_namespace_project_job_path(*args, format: params[:format])
when 'raw'
raw_namespace_project_job_path(*args)
else # show
namespace_project_job_path(*args)
resource :artifacts, only: [], controller: 'build_artifacts' do
get :download
get :browse, path: 'browse(/*path)', format: false
get :file, path: 'file/*path', format: false
get :raw, path: 'raw/*path', format: false
end
else # index
namespace_project_jobs_path(*args)
end
end
def fake_project(namespace_id, project_id)
Struct.new(:namespace, :to_param).new(namespace_id, project_id)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment