2017-05-18 12:57:37 -04:00
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Routes
|
|
|
|
class LegacyBuilds
|
2017-05-19 02:59:05 -04:00
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
include GitlabRoutingHelper
|
|
|
|
|
2017-05-18 12:57:37 -04:00
|
|
|
def initialize(map)
|
|
|
|
@map = map
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2017-05-19 02:59:05 -04:00
|
|
|
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
|
2017-05-18 12:57:37 -04:00
|
|
|
|
2017-05-19 02:59:05 -04:00
|
|
|
@map.get '/builds(/:id(/*action))', to: redirect_builds,
|
|
|
|
as: 'legacy_builds',
|
2017-05-18 12:57:37 -04:00
|
|
|
format: false
|
|
|
|
end
|
|
|
|
|
2017-05-19 02:59:05 -04:00
|
|
|
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)
|
2017-05-18 12:57:37 -04:00
|
|
|
args = params.values_at(:namespace_id, :project_id, :id).compact
|
|
|
|
|
|
|
|
if params[:id]
|
|
|
|
case params[:action]
|
|
|
|
when 'status'
|
2017-05-19 02:59:05 -04:00
|
|
|
status_namespace_project_job_path(*args, format: params[:format])
|
2017-05-18 12:57:37 -04:00
|
|
|
when 'trace'
|
2017-05-19 02:59:05 -04:00
|
|
|
trace_namespace_project_job_path(*args, format: params[:format])
|
2017-05-18 12:57:37 -04:00
|
|
|
when 'raw'
|
2017-05-19 02:59:05 -04:00
|
|
|
raw_namespace_project_job_path(*args)
|
2017-05-18 12:57:37 -04:00
|
|
|
else # show
|
2017-05-19 02:59:05 -04:00
|
|
|
namespace_project_job_path(*args)
|
2017-05-18 12:57:37 -04:00
|
|
|
end
|
|
|
|
else # index
|
2017-05-19 02:59:05 -04:00
|
|
|
namespace_project_jobs_path(*args)
|
2017-05-18 12:57:37 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-19 02:59:05 -04:00
|
|
|
|
|
|
|
def fake_project(namespace_id, project_id)
|
|
|
|
Struct.new(:namespace, :to_param).new(namespace_id, project_id)
|
|
|
|
end
|
2017-05-18 12:57:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|