summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-05-19 14:59:05 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-05-19 14:59:05 +0800
commit876acc7e0d654ebc89df3c596cc504334a37f7d8 (patch)
tree6f8bb8725e05442fbe4e56e7c4c6b3c1cff85290
parentfb3077e67b527f92a917e0f8b6f2745a322bce9a (diff)
downloadgitlab-ce-876acc7e0d654ebc89df3c596cc504334a37f7d8.tar.gz
Separate artifacts from builds, reusing artifacts_action_path
-rw-r--r--lib/gitlab/routes/legacy_builds.rb49
-rw-r--r--spec/features/projects/jobs_spec.rb12
2 files changed, 39 insertions, 22 deletions
diff --git a/lib/gitlab/routes/legacy_builds.rb b/lib/gitlab/routes/legacy_builds.rb
index ecf0c65d70a..2ae6a93981b 100644
--- a/lib/gitlab/routes/legacy_builds.rb
+++ b/lib/gitlab/routes/legacy_builds.rb
@@ -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
diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb
index bd1bf64247f..984d9bdb58c 100644
--- a/spec/features/projects/jobs_spec.rb
+++ b/spec/features/projects/jobs_spec.rb
@@ -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