project.rb 13.4 KB
Newer Older
1 2 3
resources :projects, only: [:index, :new, :create]

draw :git_http
4

5
constraints(::Constraints::ProjectUrlConstrainer.new) do
6 7 8 9 10 11 12 13
  # If the route has a wildcard segment, the segment has a regex constraint,
  # the segment is potentially followed by _another_ wildcard segment, and
  # the `format` option is not set to false, we need to specify that
  # regex constraint _outside_ of `constraints: {}`.
  #
  # Otherwise, Rails will overwrite the constraint with `/.+?/`,
  # which breaks some of our wildcard routes like `/blob/*id`
  # and `/tree/*id` that depend on the negative lookahead inside
14
  # `Gitlab::PathRegex.full_namespace_route_regex`, which helps the router
15 16 17 18 19 20
  # determine whether a certain path segment is part of `*namespace_id`,
  # `:project_id`, or `*id`.
  #
  # See https://github.com/rails/rails/blob/v4.2.8/actionpack/lib/action_dispatch/routing/mapper.rb#L155
  scope(path: '*namespace_id',
        as: :namespace,
21
        namespace_id: Gitlab::PathRegex.full_namespace_route_regex) do
22
    scope(path: ':project_id',
23
          constraints: { project_id: Gitlab::PathRegex.project_route_regex },
24 25
          module: :projects,
          as: :project) do
26

27 28 29 30 31 32 33 34 35 36 37
      resources :autocomplete_sources, only: [] do
        collection do
          get 'members'
          get 'issues'
          get 'merge_requests'
          get 'labels'
          get 'milestones'
          get 'commands'
        end
      end

38 39 40
      #
      # Templates
      #
41
      get '/templates/:template_type/:key' => 'templates#show', as: :template, constraints: { key: %r{[^/]+} }
42 43 44 45 46 47 48 49 50

      resource  :avatar, only: [:show, :destroy]
      resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
        member do
          get :branches
          get :pipelines
          post :revert
          post :cherry_pick
          get :diff_for_path
51
          get :merge_requests
52 53 54
        end
      end

R
Rob Watson 已提交
55
      resource :pages, only: [:show, :update, :destroy] do
56
        resources :domains, except: :index, controller: 'pages_domains', constraints: { id: %r{[^/]+} } do
57 58 59 60
          member do
            post :verify
          end
        end
61 62
      end

63 64
      resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
65
          get :raw
S
Sean McGivern 已提交
66
          post :mark_as_spam
67 68 69
        end
      end

70
      resources :services, constraints: { id: %r{[^/]+} }, only: [:edit, :update] do
71
        member do
72
          put :test
73 74 75
        end
      end

K
Kamil Trzcinski 已提交
76
      resource :mattermost, only: [:new, :create]
Z
Z.J. van de Weg 已提交
77

78
      namespace :prometheus do
79 80 81
        resources :metrics, constraints: { id: %r{[^\/]+} }, only: [] do
          get :active_common, on: :collection
        end
82 83
      end

84
      resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create, :edit, :update] do
85 86 87 88 89 90
        member do
          put :enable
          put :disable
        end
      end

91
      resources :deploy_tokens, constraints: { id: /\d+/ }, only: [] do
M
Mayra Cabrera 已提交
92 93 94 95 96
        member do
          put :revoke
        end
      end

97 98 99
      resources :forks, only: [:index, :new, :create]
      resource :import, only: [:new, :create, :show]

D
Douwe Maan 已提交
100
      resources :merge_requests, concerns: :awardable, except: [:new, :create], constraints: { id: /\d+/ } do
101
        member do
F
Fatih Acet 已提交
102
          get :commit_change_content
103
          post :merge
J
James Lopez 已提交
104
          post :cancel_merge_when_pipeline_succeeds
105
          get :pipeline_status
106
          get :ci_environments_status
107 108
          post :toggle_subscription
          post :remove_wip
109
          post :assign_related_issues
110
          get :discussions, format: :json
111
          post :rebase
D
Douwe Maan 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

          scope constraints: { format: nil }, action: :show do
            get :commits, defaults: { tab: 'commits' }
            get :pipelines, defaults: { tab: 'pipelines' }
            get :diffs, defaults: { tab: 'diffs' }
          end

          scope constraints: { format: 'json' }, as: :json do
            get :commits
            get :pipelines
            get :diffs, to: 'merge_requests/diffs#show'
          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
132 133 134 135 136 137 138
        end

        collection do
          get :diff_for_path
          post :bulk_update
        end

139
        resources :discussions, only: [:show], constraints: { id: /\h{40}/ } do
140 141 142 143 144 145 146
          member do
            post :resolve
            delete :resolve, action: :unresolve
          end
        end
      end

D
Douwe Maan 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
      controller 'merge_requests/creations', path: 'merge_requests' do
        post '', action: :create, as: nil

        scope path: 'new', as: :new_merge_request do
          get '', action: :new

          scope constraints: { format: nil }, action: :new do
            get :diffs, defaults: { tab: 'diffs' }
            get :pipelines, defaults: { tab: 'pipelines' }
          end

          scope constraints: { format: 'json' }, as: :json do
            get :diffs
            get :pipelines
          end

          get :diff_for_path
          get :branch_from
          get :branch_to
        end
      end

169
      resource :variables, only: [:show, :update]
170

K
Kamil Trzciński 已提交
171 172 173 174 175
      resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
        member do
          post :take_ownership
        end
      end
176

177 178 179 180 181 182
      resource :mirror, only: [:show, :update] do
        member do
          post :update_now
        end
      end

183 184 185
      resources :pipelines, only: [:index, :new, :create, :show] do
        collection do
          resource :pipelines_settings, path: 'settings', only: [:show, :update]
186
          get :charts
187 188 189
        end

        member do
190
          get :stage
191
          get :stage_ajax
192 193
          post :cancel
          post :retry
F
Filipa Lacerda 已提交
194
          get :builds
195
          get :failures
196
          get :status
197 198 199
        end
      end

200 201
      resources :pipeline_schedules, except: [:show] do
        member do
202
          post :play
203 204 205 206
          post :take_ownership
        end
      end

207 208
      resources :clusters, except: [:edit, :create] do
        collection do
209 210
          post :create_gcp
          post :create_user
211 212
        end

213
        member do
214
          get :status, format: :json
215

216
          scope :applications do
217
            post '/:application', to: 'clusters/applications#create', as: :install_applications
218
          end
219
        end
220 221
      end

222
      resources :environments, except: [:destroy] do
223 224
        member do
          post :stop
225
          get :terminal
226
          get :metrics
227
          get :additional_metrics
228
          get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', constraints: { format: nil }
229
        end
230 231

        collection do
232
          get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ }
233
        end
234

F
Fatih Acet 已提交
235 236 237
        resources :deployments, only: [:index] do
          member do
            get :metrics
238
            get :additional_metrics
F
Fatih Acet 已提交
239 240
          end
        end
241
      end
242 243 244

      resource :cycle_analytics, only: [:show]

245
      namespace :cycle_analytics do
246
        scope :events, controller: 'events' do
247 248 249 250 251 252 253
          get :issue
          get :plan
          get :code
          get :test
          get :review
          get :staging
          get :production
254 255 256
        end
      end

257
      scope '-' do
J
James Ramsay 已提交
258 259
        get 'archive/*id', constraints: { format: Gitlab::PathRegex.archive_formats_regex, id: /.+?/ }, to: 'repositories#archive', as: 'archive'

260 261 262 263 264 265 266 267 268 269
        resources :jobs, only: [:index, :show], constraints: { id: /\d+/ } do
          collection do
            post :cancel_all

            resources :artifacts, only: [] do
              collection do
                get :latest_succeeded,
                  path: '*ref_name_and_path',
                  format: false
              end
270 271 272
            end
          end

273 274 275 276 277 278 279 280 281
          member do
            get :status
            post :cancel
            post :retry
            post :play
            post :erase
            get :trace, defaults: { format: 'json' }
            get :raw
          end
282

283 284 285 286 287 288 289
          resource :artifacts, only: [] do
            get :download
            get :browse, path: 'browse(/*path)', format: false
            get :file, path: 'file/*path', format: false
            get :raw, path: 'raw/*path', format: false
            post :keep
          end
290
        end
291 292 293 294

        namespace :ci do
          resource :lint, only: [:show, :create]
        end
295 296
      end

L
Lin Jen-Shin 已提交
297
      draw :legacy_builds
298

299
      resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
300 301 302
        member do
          get :test
        end
A
Alexander Randa 已提交
303 304 305 306 307 308

        resources :hook_logs, only: [:show] do
          member do
            get :retry
          end
        end
309 310
      end

311
      resources :container_registry, only: [:index, :destroy],
312
                                     controller: 'registry/repositories'
313

314 315
      namespace :registry do
        resources :repository, only: [] do
316 317 318 319 320 321 322
          # We default to JSON format in the controller to avoid ambiguity.
          # `latest.json` could either be a request for a tag named `latest`
          # in JSON format, or a request for tag named `latest.json`.
          scope format: false do
            resources :tags, only: [:index, :destroy],
                             constraints: { id: Gitlab::Regex.container_registry_tag_regex }
          end
323 324
        end
      end
325 326 327

      resources :milestones, constraints: { id: /\d+/ } do
        member do
328
          post :promote
329 330
          put :sort_issues
          put :sort_merge_requests
P
Phil Hughes 已提交
331 332 333
          get :merge_requests
          get :participants
          get :labels
334 335 336 337 338 339 340 341 342 343
        end
      end

      resources :labels, except: [:show], constraints: { id: /\d+/ } do
        collection do
          post :generate
          post :set_priorities
        end

        member do
344
          post :promote
345 346 347 348 349
          post :toggle_subscription
          delete :remove_priority
        end
      end

350
      get :issues, to: 'issues#calendar', constraints: lambda { |req| req.format == :ics }
351 352 353 354
      resources :issues, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
          post :toggle_subscription
          post :mark_as_spam
355
          post :move
356 357 358
          get :referenced_merge_requests
          get :related_branches
          get :can_create_branch
359
          get :realtime_changes
360
          post :create_merge_request
361
          get :discussions, format: :json
362 363 364 365 366 367
        end
        collection do
          post  :bulk_update
        end
      end

368
      resources :project_members, except: [:show, :new, :edit], constraints: { id: %r{[a-zA-Z./0-9_\-#%+]+} }, concerns: :access_requestable do
369 370 371 372 373 374 375 376 377 378 379 380 381 382
        collection do
          delete :leave

          # Used for import team
          # from another project
          get :import
          post :apply_import
        end

        member do
          post :resend_invite
        end
      end

383
      resources :group_links, only: [:index, :create, :update, :destroy], constraints: { id: /\d+/ }
384

385
      resources :notes, only: [:create, :destroy, :update], concerns: :awardable, constraints: { id: /\d+/ } do
386 387 388 389 390 391 392
        member do
          delete :delete_attachment
          post :resolve
          delete :resolve, action: :unresolve
        end
      end

393 394
      get 'noteable/:target_type/:target_id/notes' => 'notes#index', as: 'noteable_notes'

395
      # On CE only index and show are needed
F
Felipe Artur 已提交
396
      resources :boards, only: [:index, :show]
397 398 399 400 401

      resources :todos, only: [:create]

      resources :uploads, only: [:create] do
        collection do
402
          get ":secret/:filename", action: :show, as: :show, constraints: { filename: %r{[^/]+} }
403 404 405 406 407
        end
      end

      resources :runners, only: [:index, :edit, :update, :destroy, :show] do
        member do
408 409
          post :resume
          post :pause
410 411 412 413
        end

        collection do
          post :toggle_shared_runners
414
          post :toggle_group_runners
415 416 417 418 419 420
        end
      end

      resources :runner_projects, only: [:create, :destroy]
      resources :badges, only: [:index] do
        collection do
421
          scope '*ref', constraints: { ref: Gitlab::PathRegex.git_reference_regex } do
422
            constraints format: /svg/ do
423 424 425
              # Keep around until 10.0, see gitlab-org/gitlab-ce#35307
              get :build, to: "badges#pipeline"
              get :pipeline
426 427 428 429 430
              get :coverage
            end
          end
        end
      end
431
      namespace :settings do
432
        get :members, to: redirect("%{namespace_id}/%{project_id}/project_members")
433
        resource :ci_cd, only: [:show, :update], controller: 'ci_cd' do
434
          post :reset_cache
435
        end
436
        resource :integrations, only: [:show]
437 438 439
        resource :repository, only: [:show], controller: :repository do
          post :create_deploy_token, path: 'deploy_token/create'
        end
440
        resources :badges, only: [:index]
441 442
      end

D
Dmitriy Zaporozhets 已提交
443 444 445 446
      # Since both wiki and repository routing contains wildcard characters
      # its preferable to keep it below all other project routes
      draw :wiki
      draw :repository
447
    end
448 449 450

    resources(:projects,
              path: '/',
451
              constraints: { id: Gitlab::PathRegex.project_route_regex },
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
              only: [:edit, :show, :update, :destroy]) do
      member do
        put :transfer
        delete :remove_fork
        post :archive
        post :unarchive
        post :housekeeping
        post :toggle_star
        post :preview_markdown
        post :export
        post :remove_export
        post :generate_new_export
        get :download_export
        get :activity
        get :refs
J
Jan Provaznik 已提交
467
        put :new_issuable_address
468 469
      end
    end
470 471
  end
end