diff --git a/changelogs/unreleased/dz-move-repo-routes-2.yml b/changelogs/unreleased/dz-move-repo-routes-2.yml new file mode 100644 index 0000000000000000000000000000000000000000..349c2a9f4800a78e257c46be47c2f98b811ac956 --- /dev/null +++ b/changelogs/unreleased/dz-move-repo-routes-2.yml @@ -0,0 +1,5 @@ +--- +title: Copy repository route under - scope +merge_request: 22092 +author: +type: changed diff --git a/config/routes/project.rb b/config/routes/project.rb index 0cc8e83de2c4ddca0b29288ec57f15431305f4db..ddd1693ef029c56fb421e01779a8b39cfa369e87 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -274,8 +274,9 @@ end end - # The wiki routing contains wildcard characters so + # The wiki and repository routing contains wildcard characters so # its preferable to keep it below all other project routes + draw :repository_scoped draw :wiki end # End of the /-/ scope. @@ -481,6 +482,13 @@ # its preferable to keep it below all other project routes draw :repository + # To ensure an old unscoped routing is used for the UI we need to + # add prefix 'as' to the scope routing and place it below original routing. + # Issue https://gitlab.com/gitlab-org/gitlab/issues/118849 + scope '-', as: 'scoped' do + draw :repository + end + # All new routes should go under /-/ scope. # Look for scope '-' at the top of the file. # rubocop: enable Cop/PutProjectRoutesUnderScope diff --git a/config/routes/repository.rb b/config/routes/repository.rb index 4815575ba9f8fa1d8be87e4d55a7d71ed74ced3e..d4805b67a5cd6e9b4297f238bf771af2257b3a25 100644 --- a/config/routes/repository.rb +++ b/config/routes/repository.rb @@ -39,32 +39,6 @@ end end - scope path: '-', constraints: { id: Gitlab::PathRegex.git_reference_regex } do - resources :network, only: [:show] - - resources :graphs, only: [:show] do - member do - get :charts - get :commits - get :ci - get :languages - end - end - - get '/branches/:state', to: 'branches#index', as: :branches_filtered, constraints: { state: /active|stale|all/ } - resources :branches, only: [:index, :new, :create, :destroy] do - get :diverging_commit_counts, on: :collection - end - - delete :merged_branches, controller: 'branches', action: :destroy_all_merged - resources :tags, only: [:index, :show, :new, :create, :destroy] do - resource :release, controller: 'tags/releases', only: [:edit, :update] - end - - resources :protected_branches, only: [:index, :show, :create, :update, :destroy, :patch], constraints: { id: Gitlab::PathRegex.git_reference_regex } - resources :protected_tags, only: [:index, :show, :create, :update, :destroy] - end - scope constraints: { id: /[^\0]+/ } do scope controller: :blob do get '/new/*id', action: :new, as: :new_blob diff --git a/config/routes/repository_scoped.rb b/config/routes/repository_scoped.rb new file mode 100644 index 0000000000000000000000000000000000000000..c6343039d629b7b334eab5409fcfd57ef898c631 --- /dev/null +++ b/config/routes/repository_scoped.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# All routing related to repository browsing +# that is already under /-/ scope only + +# Don't use format parameter as file extension (old 3.0.x behavior) +# See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments +scope format: false do + scope constraints: { id: Gitlab::PathRegex.git_reference_regex } do + resources :network, only: [:show] + + resources :graphs, only: [:show] do + member do + get :charts + get :commits + get :ci + get :languages + end + end + + get '/branches/:state', to: 'branches#index', as: :branches_filtered, constraints: { state: /active|stale|all/ } + resources :branches, only: [:index, :new, :create, :destroy] do + get :diverging_commit_counts, on: :collection + end + + delete :merged_branches, controller: 'branches', action: :destroy_all_merged + resources :tags, only: [:index, :show, :new, :create, :destroy] do + resource :release, controller: 'tags/releases', only: [:edit, :update] + end + + resources :protected_branches, only: [:index, :show, :create, :update, :destroy, :patch], constraints: { id: Gitlab::PathRegex.git_reference_regex } + resources :protected_tags, only: [:index, :show, :create, :update, :destroy] + end +end diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index b736d58bf58464dd7905aff1ba5d351e25e27876..efd7d3f374211b2c759860d106449798419e1682 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -579,6 +579,10 @@ namespace_id: 'gitlab', project_id: 'gitlabhq', id: "blob/master/blob/#{newline_file}" }) end + + it 'to #show from scope routing' do + expect(get('/gitlab/gitlabhq/-/blob/master/app/models/project.rb')).to route_to('projects/blob#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb') + end end # project_tree GET /:project_id/tree/:id(.:format) tree#show {id: /[^\0]+/, project_id: /[^\/]+/} @@ -596,6 +600,10 @@ namespace_id: 'gitlab', project_id: 'gitlabhq', id: "master/#{newline_file}" }) end + + it 'to #show from scope routing' do + expect(get('/gitlab/gitlabhq/-/tree/master/app/models/project.rb')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb') + end end # project_find_file GET /:namespace_id/:project_id/find_file/*id(.:format) projects/find_file#show {:id=>/[^\0]+/, :namespace_id=>/[a-zA-Z.0-9_\-]+/, :project_id=>/[a-zA-Z.0-9_\-]+(?/html/}