diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-23 03:08:10 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-23 03:08:10 +0000 |
commit | fe0fbe3838a49c738cb161b3fe54712c11b4b283 (patch) | |
tree | 9dfd859adf7f3eef8c7eefab9e7b0b29823ec05f | |
parent | cef56ec097d4abcb56aeb3dd5d3c1e1888942bd4 (diff) | |
download | gitlab-ce-fe0fbe3838a49c738cb161b3fe54712c11b4b283.tar.gz |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | changelogs/unreleased/dz-move-mr-routes-2.yml | 5 | ||||
-rw-r--r-- | config/routes/merge_requests.rb | 76 | ||||
-rw-r--r-- | config/routes/project.rb | 83 | ||||
-rw-r--r-- | spec/routing/project_routing_spec.rb | 6 |
4 files changed, 96 insertions, 74 deletions
diff --git a/changelogs/unreleased/dz-move-mr-routes-2.yml b/changelogs/unreleased/dz-move-mr-routes-2.yml new file mode 100644 index 00000000000..60a77149ab1 --- /dev/null +++ b/changelogs/unreleased/dz-move-mr-routes-2.yml @@ -0,0 +1,5 @@ +--- +title: Copy merge request routes to the - scope +merge_request: 22082 +author: +type: changed diff --git a/config/routes/merge_requests.rb b/config/routes/merge_requests.rb new file mode 100644 index 00000000000..fd80c21deb1 --- /dev/null +++ b/config/routes/merge_requests.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true +resources :merge_requests, concerns: :awardable, except: [:new, :create, :show], constraints: { id: /\d+/ } do + member do + get :show # Insert this first to ensure redirections using merge_requests#show match this route + get :commit_change_content + post :merge + post :cancel_auto_merge + get :pipeline_status + get :ci_environments_status + post :toggle_subscription + post :remove_wip + post :assign_related_issues + get :discussions, format: :json + post :rebase + get :test_reports + get :exposed_artifacts + + scope constraints: ->(req) { req.format == :json }, as: :json do + get :commits + get :pipelines + get :diffs, to: 'merge_requests/diffs#show' + get :diffs_batch, to: 'merge_requests/diffs#diffs_batch' + get :diffs_metadata, to: 'merge_requests/diffs#diffs_metadata' + get :widget, to: 'merge_requests/content#widget' + get :cached_widget, to: 'merge_requests/content#cached_widget' + end + + scope action: :show do + get :commits, defaults: { tab: 'commits' } + get :pipelines, defaults: { tab: 'pipelines' } + get :diffs, defaults: { tab: 'diffs' } + end + + get :diff_for_path, controller: 'merge_requests/diffs' + + scope controller: 'merge_requests/conflicts' do + get :conflicts, action: :show + get :conflict_for_path + post :resolve_conflicts + end + end + + collection do + get :diff_for_path + post :bulk_update + end + + resources :discussions, only: [:show], constraints: { id: /\h{40}/ } do + member do + post :resolve + delete :resolve, action: :unresolve + end + end +end + +scope path: 'merge_requests', controller: 'merge_requests/creations' do + post '', action: :create, as: nil + + scope path: 'new', as: :new_merge_request do + get '', action: :new + + scope constraints: ->(req) { req.format == :json }, as: :json do + get :diffs + get :pipelines + end + + scope action: :new do + get :diffs, defaults: { tab: 'diffs' } + get :pipelines, defaults: { tab: 'pipelines' } + end + + get :diff_for_path + get :branch_from + get :branch_to + end +end diff --git a/config/routes/project.rb b/config/routes/project.rb index 398041083ef..0cc8e83de2c 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -331,80 +331,15 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do end end - resources :merge_requests, concerns: :awardable, except: [:new, :create, :show], constraints: { id: /\d+/ } do - member do - get :show # Insert this first to ensure redirections using merge_requests#show match this route - get :commit_change_content - post :merge - post :cancel_auto_merge - get :pipeline_status - get :ci_environments_status - post :toggle_subscription - post :remove_wip - post :assign_related_issues - get :discussions, format: :json - post :rebase - get :test_reports - get :exposed_artifacts - - scope constraints: ->(req) { req.format == :json }, as: :json do - get :commits - get :pipelines - get :diffs, to: 'merge_requests/diffs#show' - get :diffs_batch, to: 'merge_requests/diffs#diffs_batch' - get :diffs_metadata, to: 'merge_requests/diffs#diffs_metadata' - get :widget, to: 'merge_requests/content#widget' - get :cached_widget, to: 'merge_requests/content#cached_widget' - end - - scope action: :show do - get :commits, defaults: { tab: 'commits' } - get :pipelines, defaults: { tab: 'pipelines' } - get :diffs, defaults: { tab: 'diffs' } - end - - get :diff_for_path, controller: 'merge_requests/diffs' - - scope controller: 'merge_requests/conflicts' do - get :conflicts, action: :show - get :conflict_for_path - post :resolve_conflicts - end - end - - collection do - get :diff_for_path - post :bulk_update - end - - resources :discussions, only: [:show], constraints: { id: /\h{40}/ } do - member do - post :resolve - delete :resolve, action: :unresolve - end - end - end - - scope path: 'merge_requests', controller: 'merge_requests/creations' do - post '', action: :create, as: nil - - scope path: 'new', as: :new_merge_request do - get '', action: :new - - scope constraints: ->(req) { req.format == :json }, as: :json do - get :diffs - get :pipelines - end - - scope action: :new do - get :diffs, defaults: { tab: 'diffs' } - get :pipelines, defaults: { tab: 'pipelines' } - end - - get :diff_for_path - get :branch_from - get :branch_to - end + # Unscoped route. It will be replaced with redirect to /-/merge_requests/ + # Issue https://gitlab.com/gitlab-org/gitlab/issues/118849 + draw :merge_requests + + # 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 MR routing. + # Issue https://gitlab.com/gitlab-org/gitlab/issues/118849 + scope '-', as: 'scoped' do + draw :merge_requests end resources :pipelines, only: [:index, :new, :create, :show] do diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 287db20448a..b736d58bf58 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -314,6 +314,12 @@ describe 'project routing' do expect(get('/gitlab/gitlabhq/merge_requests/1/pipelines')).to route_to('projects/merge_requests#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1', tab: 'pipelines') end + it 'to #show from scoped route' do + expect(get('/gitlab/gitlabhq/-/merge_requests/1.diff')).to route_to('projects/merge_requests#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1', format: 'diff') + expect(get('/gitlab/gitlabhq/-/merge_requests/1.patch')).to route_to('projects/merge_requests#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1', format: 'patch') + expect(get('/gitlab/gitlabhq/-/merge_requests/1/diffs')).to route_to('projects/merge_requests#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1', tab: 'diffs') + end + it_behaves_like 'RESTful project resources' do let(:controller) { 'merge_requests' } let(:actions) { [:index, :edit, :show, :update] } |