Commit 876acc7e authored by Lin Jen-Shin's avatar Lin Jen-Shin

Separate artifacts from builds, reusing artifacts_action_path

parent fb3077e6
......@@ -2,43 +2,60 @@
module Gitlab
module Routes
class LegacyBuilds
include Gitlab::Routing.url_helpers
include GitlabRoutingHelper
def initialize(map)
@map = map
end
def draw
redirect_builds_to_jobs = @map.redirect(&method(:redirect))
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_to_jobs,
as: 'legacy_build',
@map.get '/builds(/:id(/*action))', to: redirect_builds,
as: 'legacy_builds',
format: false
end
def redirect(params, req)
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
url_helpers = Gitlab::Routing.url_helpers
if params[:id]
case params[:action]
when 'status'
url_helpers.status_namespace_project_job_path(*args, format: params[:format])
status_namespace_project_job_path(*args, format: params[:format])
when 'trace'
url_helpers.trace_namespace_project_job_path(*args, format: params[:format])
trace_namespace_project_job_path(*args, format: params[:format])
when 'raw'
url_helpers.raw_namespace_project_job_path(*args)
when String
if params[:id] == 'artifacts'
url_helpers.latest_succeeded_namespace_project_artifacts_path(params[:namespace_id], params[:project_id], params[:action], job: req.GET[:job])
else
"#{url_helpers.namespace_project_job_path(*args)}/#{params[:action]}"
end
raw_namespace_project_job_path(*args)
else # show
url_helpers.namespace_project_job_path(*args)
namespace_project_job_path(*args)
end
else # index
url_helpers.namespace_project_jobs_path(*args)
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
end
......@@ -482,8 +482,8 @@ feature 'Jobs', :feature do
end
end
describe "GET /:project/builds/:id/trace.json" do
context "Build from project" do
describe "GET /:project/jobs/:id/trace.json" do
context "Job from project" do
before do
visit trace_namespace_project_job_path(project.namespace, project, build, format: :json)
end
......@@ -491,7 +491,7 @@ feature 'Jobs', :feature do
it { expect(page.status_code).to eq(200) }
end
context "Build from other project" do
context "Job from other project" do
before do
visit trace_namespace_project_job_path(project.namespace, project, build2, format: :json)
end
......@@ -514,8 +514,8 @@ feature 'Jobs', :feature do
end
end
describe "GET /:project/builds/:id/status" do
context "Build from project" do
describe "GET /:project/jobs/:id/status" do
context "Job from project" do
before do
visit status_namespace_project_job_path(project.namespace, project, build)
end
......@@ -523,7 +523,7 @@ feature 'Jobs', :feature do
it { expect(page.status_code).to eq(200) }
end
context "Build from other project" do
context "Job from other project" do
before do
visit status_namespace_project_job_path(project.namespace, project, build2)
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