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