routes.rb 25.8 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
require 'sidekiq/web'
2
require 'sidekiq/cron/web'
3
require 'api/api'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4

Valery Sizov's avatar
Valery Sizov committed
5
Rails.application.routes.draw do
6 7 8 9 10 11 12 13 14 15 16 17 18
  if Gitlab::Sherlock.enabled?
    namespace :sherlock do
      resources :transactions, only: [:index, :show] do
        resources :queries, only: [:show]
        resources :file_samples, only: [:show]

        collection do
          delete :destroy_all
        end
      end
    end
  end

19
  if Rails.env.development?
20 21 22 23
    # Make the built-in Rails routes available in development, otherwise they'd
    # get swallowed by the `namespace/project` route matcher below.
    #
    # See https://git.io/va79N
24 25 26 27 28
    get '/rails/mailers'         => 'rails/mailers#index'
    get '/rails/mailers/:path'   => 'rails/mailers#preview'
    get '/rails/info/properties' => 'rails/info#properties'
    get '/rails/info/routes'     => 'rails/info#routes'
    get '/rails/info'            => 'rails/info#index'
29 30

    mount LetterOpenerWeb::Engine, at: '/rails/letter_opener'
31 32
  end

33 34
  concern :access_requestable do
    post :request_access, on: :collection
35
    post :approve_access_request, on: :member
36 37
  end

38 39 40 41 42 43 44
  namespace :ci do
    # CI API
    Ci::API::API.logger Rails.logger
    mount Ci::API::API => '/api'

    resource :lint, only: [:show, :create]

Josef Strzibny's avatar
Josef Strzibny committed
45
    resources :projects, only: [:index, :show] do
46 47 48 49 50 51 52 53
      member do
        get :status, to: 'projects#badge'
      end
    end

    root to: 'projects#index'
  end

Valery Sizov's avatar
Valery Sizov committed
54
  use_doorkeeper do
55 56 57
    controllers applications: 'oauth/applications',
                authorized_applications: 'oauth/authorized_applications',
                authorizations: 'oauth/authorizations'
Valery Sizov's avatar
Valery Sizov committed
58
  end
59

60 61 62
  # Autocomplete
  get '/autocomplete/users' => 'autocomplete#users'
  get '/autocomplete/users/:id' => 'autocomplete#user'
63
  get '/autocomplete/projects' => 'autocomplete#projects'
64

Annabel Dunstone's avatar
Annabel Dunstone committed
65 66
  # Emojis
  resources :emojis, only: :index
67

68
  # Search
69 70
  get 'search' => 'search#show'
  get 'search/autocomplete' => 'search#autocomplete', as: :search_autocomplete
Valery Sizov's avatar
Valery Sizov committed
71

Kamil Trzcinski's avatar
Kamil Trzcinski committed
72 73 74
  # JSON Web Token
  get 'jwt/auth' => 'jwt#auth'

75
  # API
76 77
  API::API.logger Rails.logger
  mount API::API => '/api'
78

79
  constraint = lambda { |request| request.env['warden'].authenticate? and request.env['warden'].user.admin? }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
80
  constraints constraint do
81
    mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
82
  end
Ariejan de Vroom's avatar
Ariejan de Vroom committed
83

84
  # Health check
85
  get 'health_check(/:checks)' => 'health_check#index', as: :health_check
86

87
  # Help
88 89 90 91
  get 'help'           => 'help#index'
  get 'help/shortcuts' => 'help#shortcuts'
  get 'help/ui'        => 'help#ui'
  get 'help/*path'     => 'help#show', as: :help_page
92

93 94 95 96 97
  #
  # Koding route
  #
  get 'koding' => 'koding#index'

Andrew8xx8's avatar
Andrew8xx8 committed
98 99 100 101 102
  #
  # Global snippets
  #
  resources :snippets do
    member do
103
      get 'raw'
Andrew8xx8's avatar
Andrew8xx8 committed
104 105
    end
  end
106

Long Nguyen's avatar
Long Nguyen committed
107
  get '/s/:username', to: redirect('/u/%{username}/snippets'),
Long Nguyen's avatar
Long Nguyen committed
108
                      constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
Andrew8xx8's avatar
Andrew8xx8 committed
109

Douwe Maan's avatar
Douwe Maan committed
110 111 112 113 114 115 116
  #
  # Invites
  #

  resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do
    member do
      post :accept
Douwe Maan's avatar
Douwe Maan committed
117
      match :decline, via: [:get, :post]
Douwe Maan's avatar
Douwe Maan committed
118 119
    end
  end
120

121
  resources :sent_notifications, only: [], constraints: { id: /\h{32}/ } do
122 123 124 125 126
    member do
      get :unsubscribe
    end
  end

127
  #
128
  # Spam reports
129
  #
130 131
  resources :abuse_reports, only: [:new, :create]

132 133 134 135 136
  #
  # Notification settings
  #
  resources :notification_settings, only: [:create, :update]

Valery Sizov's avatar
Valery Sizov committed
137
  #
138
  # Import
Valery Sizov's avatar
Valery Sizov committed
139
  #
140 141
  namespace :import do
    resource :github, only: [:create, :new], controller: :github do
142
      post :personal_access_token
143 144 145 146 147
      get :status
      get :callback
      get :jobs
    end

Josef Strzibny's avatar
Josef Strzibny committed
148
    resource :gitlab, only: [:create], controller: :gitlab do
149 150 151 152
      get :status
      get :callback
      get :jobs
    end
Marcin Kulik's avatar
Marcin Kulik committed
153

Josef Strzibny's avatar
Josef Strzibny committed
154
    resource :bitbucket, only: [:create], controller: :bitbucket do
Douwe Maan's avatar
Douwe Maan committed
155 156 157 158
      get :status
      get :callback
      get :jobs
    end
159

160 161 162 163
    resource :google_code, only: [:create, :new], controller: :google_code do
      get :status
      post :callback
      get :jobs
164 165 166

      get   :new_user_map,    path: :user_map
      post  :create_user_map, path: :user_map
167
    end
Jared Szechy's avatar
Jared Szechy committed
168 169 170 171 172 173 174 175 176

    resource :fogbugz, only: [:create, :new], controller: :fogbugz do
      get :status
      post :callback
      get :jobs

      get   :new_user_map,    path: :user_map
      post  :create_user_map, path: :user_map
    end
177

178
    resource :gitlab_project, only: [:create, :new] do
179
      post :create
180
    end
Valery Sizov's avatar
Valery Sizov committed
181
  end
182

183 184 185
  #
  # Uploads
  #
186

187 188
  scope path: :uploads do
    # Note attachments and User/Group/Project avatars
189 190
    get ":model/:mounted_as/:id/:filename",
        to:           "uploads#show",
191
        constraints:  { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /[^\/]+/ }
192

193 194 195 196 197
    # Appearance
    get ":model/:mounted_as/:id/:filename",
        to:           "uploads#show",
        constraints:  { model: /appearance/, mounted_as: /logo|header_logo/, filename: /.+/ }

198
    # Project markdown uploads
199
    get ":namespace_id/:project_id/:secret/:filename",
200
      to:           "projects/uploads#show",
201
      constraints:  { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: /[^\/]+/ }
202
  end
Valery Sizov's avatar
Valery Sizov committed
203

204
  # Redirect old note attachments path to new uploads path.
205 206
  get "files/note/:id/:filename",
    to:           redirect("uploads/note/attachment/%{id}/%{filename}"),
207
    constraints:  { filename: /[^\/]+/ }
208

209
  #
Yatish Mehta's avatar
Yatish Mehta committed
210
  # Explore area
211
  #
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
212 213 214 215
  namespace :explore do
    resources :projects, only: [:index] do
      collection do
        get :trending
216
        get :starred
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
217 218 219
      end
    end

220
    resources :groups, only: [:index]
221
    resources :snippets, only: [:index]
222
    root to: 'projects#trending'
223 224
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
225
  # Compatibility with old routing
226 227
  get 'public' => 'explore/projects#index'
  get 'public/projects' => 'explore/projects#index'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
228

229 230 231
  #
  # Admin Area
  #
Nihad Abbasov's avatar
Nihad Abbasov committed
232
  namespace :admin do
233
    resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
234
      resources :keys, only: [:show, :destroy]
235
      resources :identities, except: [:show]
236

237
      member do
238 239 240
        get :projects
        get :keys
        get :groups
241 242
        put :block
        put :unblock
243
        put :unlock
244
        put :confirm
Douwe Maan's avatar
Douwe Maan committed
245
        post :impersonate
246
        patch :disable_two_factor
247
        delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
248 249
      end
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
250

Douwe Maan's avatar
Douwe Maan committed
251 252
    resource :impersonation, only: :destroy

253
    resources :abuse_reports, only: [:index, :destroy]
254 255 256 257 258
    resources :spam_logs, only: [:index, :destroy] do
      member do
        post :mark_as_ham
      end
    end
259

Valery Sizov's avatar
Valery Sizov committed
260 261
    resources :applications

262 263
    resources :groups, constraints: { id: /[^\/]+/ } do
      member do
264
        put :members_update
265
      end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
266
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
267

268
    resources :deploy_keys, only: [:index, :new, :create, :destroy]
269

270
    resources :hooks, only: [:index, :create, :destroy] do
Valeriy Sizov's avatar
Valeriy Sizov committed
271 272
      get :test
    end
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
273

274 275 276 277
    resources :broadcast_messages, only: [:index, :edit, :create, :update, :destroy] do
      post :preview, on: :collection
    end

278
    resource :logs, only: [:show]
279
    resource :health_check, controller: 'health_check', only: [:show]
280
    resource :background_jobs, controller: 'background_jobs', only: [:show]
281
    resource :system_info, controller: 'system_info', only: [:show]
282
    resources :requests_profiles, only: [:index, :show], param: :name, constraints: { name: /.+\.html/ }
283

Vinnie Okada's avatar
Vinnie Okada committed
284 285 286
    resources :namespaces, path: '/projects', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
      root to: 'projects#index', as: :projects

287 288
      resources(:projects,
                path: '/',
Vinnie Okada's avatar
Vinnie Okada committed
289 290 291 292 293 294
                constraints: { id: /[a-zA-Z.0-9_\-]+/ },
                only: [:index, :show]) do
        root to: 'projects#show'

        member do
          put :transfer
295
          post :repository_check
Vinnie Okada's avatar
Vinnie Okada committed
296
        end
297

298
        resources :runner_projects, only: [:create, :destroy]
299 300 301
      end
    end

Josef Strzibny's avatar
Josef Strzibny committed
302
    resource :appearances, only: [:show, :create, :update], path: 'appearance' do
303 304 305 306 307 308
      member do
        get :preview
        delete :logo
        delete :header_logos
      end
    end
309

310
    resource :application_settings, only: [:show, :update] do
Josef Strzibny's avatar
Josef Strzibny committed
311
      resources :services, only: [:index, :edit, :update]
312
      put :reset_runners_token
313
      put :reset_health_check_token
314
      put :clear_repository_check_states
315
    end
316

Valery Sizov's avatar
Valery Sizov committed
317 318
    resources :labels

319 320 321 322 323 324 325 326 327 328 329 330 331
    resources :runners, only: [:index, :show, :update, :destroy] do
      member do
        get :resume
        get :pause
      end
    end

    resources :builds, only: :index do
      collection do
        post :cancel_all
      end
    end

332
    root to: 'dashboard#index'
gitlabhq's avatar
gitlabhq committed
333 334
  end

randx's avatar
randx committed
335 336 337
  #
  # Profile Area
  #
338 339
  resource :profile, only: [:show, :update] do
    member do
340
      get :audit_log
341
      get :applications, to: 'oauth/applications#index'
342 343 344 345

      put :reset_private_token
      put :update_username
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
346

347
    scope module: :profiles do
Josef Strzibny's avatar
Josef Strzibny committed
348
      resource :account, only: [:show] do
349 350 351 352
        member do
          delete :unlink
        end
      end
353
      resource :notifications, only: [:show, :update]
354 355 356 357 358
      resource :password, only: [:new, :create, :edit, :update] do
        member do
          put :reset
        end
      end
359
      resource :preferences, only: [:show, :update]
Josef Strzibny's avatar
Josef Strzibny committed
360
      resources :keys, only: [:index, :show, :new, :create, :destroy]
361
      resources :emails, only: [:index, :create, :destroy]
362
      resource :avatar, only: [:destroy]
363

364 365 366 367 368
      resources :personal_access_tokens, only: [:index, :create] do
        member do
          put :revoke
        end
      end
369

370
      resource :two_factor_auth, only: [:show, :create, :destroy] do
371
        member do
372
          post :create_u2f
373
          post :codes
374
          patch :skip
375 376
        end
      end
Timothy Andrew's avatar
Timothy Andrew committed
377 378

      resources :u2f_registrations, only: [:destroy]
379
    end
380
  end
381

Long Nguyen's avatar
Long Nguyen committed
382
  scope(path: 'u/:username',
Long Nguyen's avatar
Long Nguyen committed
383
        as: :user,
Long Nguyen's avatar
Long Nguyen committed
384 385
        constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ },
        controller: :users) do
Long Nguyen's avatar
Long Nguyen committed
386 387 388 389 390 391 392
    get :calendar
    get :calendar_activities
    get :groups
    get :projects
    get :contributed, as: :contributed_projects
    get :snippets
    get '/', action: :show
Long Nguyen's avatar
Long Nguyen committed
393
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
394

randx's avatar
randx committed
395 396 397
  #
  # Dashboard Area
  #
398 399 400 401
  resource :dashboard, controller: 'dashboard', only: [] do
    get :issues
    get :merge_requests
    get :activity
Douwe Maan's avatar
Douwe Maan committed
402 403 404

    scope module: :dashboard do
      resources :milestones, only: [:index, :show]
405
      resources :labels, only: [:index]
406

407
      resources :groups, only: [:index]
408
      resources :snippets, only: [:index]
409 410 411 412 413 414

      resources :todos, only: [:index, :destroy] do
        collection do
          delete :destroy_all
        end
      end
415

416
      resources :projects, only: [:index] do
417 418 419 420
        collection do
          get :starred
        end
      end
Douwe Maan's avatar
Douwe Maan committed
421
    end
422 423

    root to: "dashboard/projects#index"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
424
  end
gitlabhq's avatar
gitlabhq committed
425

randx's avatar
randx committed
426 427 428
  #
  # Groups Area
  #
429
  resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }  do
randx's avatar
randx committed
430 431 432
    member do
      get :issues
      get :merge_requests
433
      get :projects
434
      get :activity
randx's avatar
randx committed
435
    end
436

Steven Thonus's avatar
Steven Thonus committed
437
    scope module: :groups do
438
      resources :group_members, only: [:index, :create, :update, :destroy], concerns: :access_requestable do
439
        post :resend_invite, on: :member
440
        delete :leave, on: :collection
441
      end
442

Steven Thonus's avatar
Steven Thonus committed
443
      resource :avatar, only: [:destroy]
444
      resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
Steven Thonus's avatar
Steven Thonus committed
445
    end
randx's avatar
randx committed
446 447
  end

448
  resources :projects, constraints: { id: /[^\/]+/ }, only: [:index, :new, :create]
449

450 451 452 453 454
  devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks,
                                    registrations: :registrations,
                                    passwords: :passwords,
                                    sessions: :sessions,
                                    confirmations: :confirmations }
gitlabhq's avatar
gitlabhq committed
455

456
  devise_scope :user do
457
    get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
Phil Hughes's avatar
Phil Hughes committed
458
    get '/users/almost_there' => 'confirmations#almost_there'
459
  end
Vinnie Okada's avatar
Vinnie Okada committed
460

461
  root to: "root#index"
Vinnie Okada's avatar
Vinnie Okada committed
462

463 464 465
  #
  # Project Area
  #
Vinnie Okada's avatar
Vinnie Okada committed
466
  resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do
467
    resources(:projects, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, except:
Vinnie Okada's avatar
Vinnie Okada committed
468 469 470
              [:new, :create, :index], path: "/") do
      member do
        put :transfer
471
        delete :remove_fork
Vinnie Okada's avatar
Vinnie Okada committed
472 473
        post :archive
        post :unarchive
474
        post :housekeeping
Vinnie Okada's avatar
Vinnie Okada committed
475
        post :toggle_star
476
        post :preview_markdown
477
        post :export
478
        post :remove_export
479
        post :generate_new_export
480
        get :download_export
Vinnie Okada's avatar
Vinnie Okada committed
481
        get :autocomplete_sources
482
        get :activity
483
        get :refs
skv's avatar
skv committed
484
      end
485

Vinnie Okada's avatar
Vinnie Okada committed
486
      scope module: :projects do
487
        scope constraints: { id: /.+\.git/, format: nil } do
Jacob Vosmaer's avatar
Jacob Vosmaer committed
488
          # Git HTTP clients ('git clone' etc.)
Jacob Vosmaer's avatar
Jacob Vosmaer committed
489 490 491
          get '/info/refs', to: 'git_http#info_refs'
          post '/git-upload-pack', to: 'git_http#git_upload_pack'
          post '/git-receive-pack', to: 'git_http#git_receive_pack'
Jacob Vosmaer's avatar
Jacob Vosmaer committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506

          # Git LFS API (metadata)
          post '/info/lfs/objects/batch', to: 'lfs_api#batch'
          post '/info/lfs/objects', to: 'lfs_api#deprecated'
          get '/info/lfs/objects/*oid', to: 'lfs_api#deprecated'

          # GitLab LFS object storage
          scope constraints: { oid: /[a-f0-9]{64}/ } do
            get '/gitlab-lfs/objects/*oid', to: 'lfs_storage#download'

            scope constraints: { size: /[0-9]+/ } do
              put '/gitlab-lfs/objects/*oid/*size/authorize', to: 'lfs_storage#upload_authorize'
              put '/gitlab-lfs/objects/*oid/*size', to: 'lfs_storage#upload_finalize'
            end
          end
507 508
        end

509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
        # Allow /info/refs, /info/refs?service=git-upload-pack, and
        # /info/refs?service=git-receive-pack, but nothing else.
        #
        git_http_handshake = lambda do |request|
          request.query_string.blank? ||
            request.query_string.match(/\Aservice=git-(upload|receive)-pack\z/)
        end

        ref_redirect = redirect do |params, request|
          path = "#{params[:namespace_id]}/#{params[:project_id]}.git/info/refs"
          path << "?#{request.query_string}" unless request.query_string.blank?
          path
        end

        get '/info/refs', constraints: git_http_handshake, to: ref_redirect

Vinnie Okada's avatar
Vinnie Okada committed
525 526 527 528 529 530 531
        # Blob routes:
        get '/new/*id', to: 'blob#new', constraints: { id: /.+/ }, as: 'new_blob'
        post '/create/*id', to: 'blob#create', constraints: { id: /.+/ }, as: 'create_blob'
        get '/edit/*id', to: 'blob#edit', constraints: { id: /.+/ }, as: 'edit_blob'
        put '/update/*id', to: 'blob#update', constraints: { id: /.+/ }, as: 'update_blob'
        post '/preview/*id', to: 'blob#preview', constraints: { id: /.+/ }, as: 'preview_blob'

532 533 534 535 536
        #
        # Templates
        #
        get '/templates/:template_type/:key' => 'templates#show', as: :template

Vinnie Okada's avatar
Vinnie Okada committed
537
        scope do
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
          get(
            '/blob/*id/diff',
            to: 'blob#diff',
            constraints: { id: /.+/, format: false },
            as: :blob_diff
          )
          get(
            '/blob/*id',
            to: 'blob#show',
            constraints: { id: /.+/, format: false },
            as: :blob
          )
          delete(
            '/blob/*id',
            to: 'blob#destroy',
            constraints: { id: /.+/, format: false }
          )
555 556 557 558 559 560 561 562 563 564
          put(
            '/blob/*id',
            to: 'blob#update',
            constraints: { id: /.+/, format: false }
          )
          post(
            '/blob/*id',
            to: 'blob#create',
            constraints: { id: /.+/, format: false }
          )
Vinnie Okada's avatar
Vinnie Okada committed
565
        end
566

Vinnie Okada's avatar
Vinnie Okada committed
567 568 569 570 571 572 573
        scope do
          get(
            '/raw/*id',
            to: 'raw#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :raw
          )
574
        end
575

Vinnie Okada's avatar
Vinnie Okada committed
576 577 578 579 580 581 582 583 584
        scope do
          get(
            '/tree/*id',
            to: 'tree#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :tree
          )
        end

585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
        scope do
          get(
            '/find_file/*id',
            to: 'find_file#show',
            constraints: { id: /.+/, format: /html/ },
            as: :find_file
          )
        end

        scope do
          get(
            '/files/*id',
            to: 'find_file#list',
            constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ },
            as: :files
          )
        end

Stan Hu's avatar
Stan Hu committed
603 604
        scope do
          post(
Gabriel Mazetto's avatar
Gabriel Mazetto committed
605
            '/create_dir/*id',
Stan Hu's avatar
Stan Hu committed
606 607 608 609 610 611
              to: 'tree#create_dir',
              constraints: { id: /.+/ },
              as: 'create_dir'
          )
        end

Vinnie Okada's avatar
Vinnie Okada committed
612 613 614 615 616 617 618
        scope do
          get(
            '/blame/*id',
            to: 'blame#show',
            constraints: { id: /.+/, format: /(html|js)/ },
            as: :blame
          )
619
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
620

621 622 623 624
        scope do
          get(
            '/commits/*id',
            to: 'commits#show',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
625
            constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
626 627 628 629 630
            as: :commits
          )
        end

        resource  :avatar, only: [:show, :destroy]
631
        resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
632 633
          member do
            get :branches
Kamil Trzcinski's avatar
Kamil Trzcinski committed
634 635 636
            get :builds
            post :cancel_builds
            post :retry_builds
637
            post :revert
638
            post :cherry_pick
639
            get :diff_for_path
640
          end
641 642
        end

643 644
        resources :compare, only: [:index, :create] do
          collection do
645
            get :diff_for_path
646 647 648 649 650
          end
        end

        get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ }

651 652 653 654
        # 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
          resources :network, only: [:show], constraints: { id: Gitlab::Regex.git_reference_regex }
655

656 657 658 659 660 661
          resources :graphs, only: [:show], constraints: { id: Gitlab::Regex.git_reference_regex } do
            member do
              get :commits
              get :ci
              get :languages
            end
Vinnie Okada's avatar
Vinnie Okada committed
662
          end
663
        end
664

Vinnie Okada's avatar
Vinnie Okada committed
665 666 667 668
        resources :snippets, constraints: { id: /\d+/ } do
          member do
            get 'raw'
          end
669
        end
670

671
        WIKI_SLUG_ID = { id: /\S+/ } unless defined? WIKI_SLUG_ID
672

Stan Hu's avatar
Stan Hu committed
673 674 675 676 677 678 679 680 681 682 683 684
        scope do
          # Order matters to give priority to these matches
          get '/wikis/git_access', to: 'wikis#git_access'
          get '/wikis/pages', to: 'wikis#pages', as: 'wiki_pages'
          post '/wikis', to: 'wikis#create'

          get '/wikis/*id/history', to: 'wikis#history', as: 'wiki_history', constraints: WIKI_SLUG_ID
          get '/wikis/*id/edit', to: 'wikis#edit', as: 'wiki_edit', constraints: WIKI_SLUG_ID

          get '/wikis/*id', to: 'wikis#show', as: 'wiki', constraints: WIKI_SLUG_ID
          delete '/wikis/*id', to: 'wikis#destroy', constraints: WIKI_SLUG_ID
          put '/wikis/*id', to: 'wikis#update', constraints: WIKI_SLUG_ID
685
          post '/wikis/*id/preview_markdown', to: 'wikis#preview_markdown', constraints: WIKI_SLUG_ID, as: 'wiki_preview_markdown'
686
        end
687

Josef Strzibny's avatar
Josef Strzibny committed
688
        resource :repository, only: [:create] do
Vinnie Okada's avatar
Vinnie Okada committed
689 690 691 692
          member do
            get 'archive', constraints: { format: Gitlab::Regex.archive_formats_regex }
          end
        end
miks's avatar
miks committed
693

Vinnie Okada's avatar
Vinnie Okada committed
694 695 696 697
        resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
          member do
            get :test
          end
698
        end
gitlabhq's avatar
gitlabhq committed
699

700
        resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
Vinnie Okada's avatar
Vinnie Okada committed
701 702 703 704
          member do
            put :enable
            put :disable
          end
705
        end
gitlabhq's avatar
gitlabhq committed
706

707
        resources :forks, only: [:index, :new, :create]
Vinnie Okada's avatar
Vinnie Okada committed
708 709 710 711 712 713 714 715 716 717
        resource :import, only: [:new, :create, :show]

        resources :refs, only: [] do
          collection do
            get 'switch'
          end

          member do
            # tree viewer logs
            get 'logs_tree', constraints: { id: Gitlab::Regex.git_reference_regex }
718 719
            # Directories with leading dots erroneously get rejected if git
            # ref regex used in constraints. Regex verification now done in controller.
720
            get 'logs_tree/*path' => 'refs#logs_tree', as: :logs_file, constraints: {
721
              id: /.*/,
Vinnie Okada's avatar
Vinnie Okada committed
722 723 724
              path: /.*/
            }
          end
725
        end
726

727
        resources :merge_requests, constraints: { id: /\d+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
728
          member do
729
            get :commits
Vinnie Okada's avatar
Vinnie Okada committed
730
            get :diffs
731
            get :conflicts
732
            get :builds
733
            get :pipelines
734 735
            get :merge_check
            post :merge
736
            post :cancel_merge_when_build_succeeds
Vinnie Okada's avatar
Vinnie Okada committed
737
            get :ci_status
Valery Sizov's avatar
tests  
Valery Sizov committed
738
            post :toggle_subscription
739
            post :toggle_award_emoji
740
            post :remove_wip
741
            get :diff_for_path
742
            post :resolve_conflicts
Vinnie Okada's avatar
Vinnie Okada committed
743 744 745 746 747 748
          end

          collection do
            get :branch_from
            get :branch_to
            get :update_branches
749
            get :diff_for_path
Vinnie Okada's avatar
Vinnie Okada committed
750
          end
751 752 753 754 755 756 757

          resources :discussions, only: [], constraints: { id: /\h{40}/ } do
            member do
              post :resolve
              delete :resolve, action: :unresolve
            end
          end
758
        end
759

Vinnie Okada's avatar
Vinnie Okada committed
760
        resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
761 762
        resources :tags, only: [:index, :show, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } do
          resource :release, only: [:edit, :update]
763 764
        end

765
        resources :protected_branches, only: [:index, :show, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
Phil Hughes's avatar
Phil Hughes committed
766
        resources :variables, only: [:index, :show, :update, :create, :destroy]
767
        resources :triggers, only: [:index, :create, :destroy]
768

Kamil Trzcinski's avatar
Kamil Trzcinski committed
769
        resources :pipelines, only: [:index, :new, :create, :show] do
770 771 772
          collection do
            resource :pipelines_settings, path: 'settings', only: [:show, :update]
          end
773

Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
774 775 776 777 778 779
          member do
            post :cancel
            post :retry
          end
        end

780
        resources :environments
Kamil Trzcinski's avatar
Kamil Trzcinski committed
781

782
        resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
783
          collection do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
784
            post :cancel_all
785 786 787

            resources :artifacts, only: [] do
              collection do
788
                get :latest_succeeded,
789 790
                  path: '*ref_name_and_path',
                  format: false
791 792
              end
            end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
793 794
          end

795 796
          member do
            get :status
797
            post :cancel
798
            post :retry
799
            post :play
800
            post :erase
801
            get :trace
802
            get :raw
803
          end
804

805 806
          resource :artifacts, only: [] do
            get :download
807 808
            get :browse, path: 'browse(/*path)', format: false
            get :file, path: 'file/*path', format: false
809
            post :keep
810
          end
811
        end
812

Vinnie Okada's avatar
Vinnie Okada committed
813 814 815 816
        resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
          member do
            get :test
          end
817
        end
818

Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
819
        resources :container_registry, only: [:index, :destroy], constraints: { id: Gitlab::Regex.container_registry_reference_regex }
820

821
        resources :milestones, constraints: { id: /\d+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
822 823 824 825
          member do
            put :sort_issues
            put :sort_merge_requests
          end
826
        end
827

Josef Strzibny's avatar
Josef Strzibny committed
828
        resources :labels, except: [:show], constraints: { id: /\d+/ } do
Vinnie Okada's avatar
Vinnie Okada committed
829 830
          collection do
            post :generate
Alfredo Sumaran's avatar
Alfredo Sumaran committed
831
            post :set_priorities
Vinnie Okada's avatar
Vinnie Okada committed
832
          end
833 834 835

          member do
            post :toggle_subscription
836
            delete :remove_priority
837
          end
838
        end
839

840
        resources :issues, constraints: { id: /\d+/ } do
Valery Sizov's avatar
Valery Sizov committed
841
          member do
Valery Sizov's avatar
tests  
Valery Sizov committed
842
            post :toggle_subscription
843
            post :toggle_award_emoji
844
            post :mark_as_spam
845 846
            get :referenced_merge_requests
            get :related_branches
847
            get :can_create_branch
Valery Sizov's avatar
Valery Sizov committed
848
          end
Vinnie Okada's avatar
Vinnie Okada committed
849 850 851
          collection do
            post  :bulk_update
          end
852
        end
Robert Speicher's avatar
Robert Speicher committed
853

Josef Strzibny's avatar
Josef Strzibny committed
854
        resources :project_members, except: [:show, :new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ }, concerns: :access_requestable do
Vinnie Okada's avatar
Vinnie Okada committed
855 856
          collection do
            delete :leave
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
857

Vinnie Okada's avatar
Vinnie Okada committed
858 859 860 861 862
            # Used for import team
            # from another project
            get :import
            post :apply_import
          end
863 864 865 866

          member do
            post :resend_invite
          end
867
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
868

869 870
        resources :group_links, only: [:index, :create, :destroy], constraints: { id: /\d+/ }

Vinnie Okada's avatar
Vinnie Okada committed
871 872
        resources :notes, only: [:index, :create, :destroy, :update], constraints: { id: /\d+/ } do
          member do
Fatih Acet's avatar
Fatih Acet committed
873
            post :toggle_award_emoji
Vinnie Okada's avatar
Vinnie Okada committed
874
            delete :delete_attachment
875
            post :resolve
876
            delete :resolve, action: :unresolve
Vinnie Okada's avatar
Vinnie Okada committed
877
          end
878
        end
879

880
        resource :board, only: [:show] do
881 882
          scope module: :boards do
            resources :issues, only: [:update]
883

884
            resources :lists, only: [:index, :create, :update, :destroy] do
885 886 887
              collection do
                post :generate
              end
888

889 890
              resources :issues, only: [:index]
            end
891
          end
892
        end
893

Phil Hughes's avatar
Phil Hughes committed
894
        resources :todos, only: [:create]
895

896 897
        resources :uploads, only: [:create] do
          collection do
898
            get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
899
          end
900
        end
901

902 903 904 905 906
        resources :runners, only: [:index, :edit, :update, :destroy, :show] do
          member do
            get :resume
            get :pause
          end
907 908 909 910

          collection do
            post :toggle_shared_runners
          end
911
        end
912 913

        resources :runner_projects, only: [:create, :destroy]
914
        resources :badges, only: [:index] do
915
          collection do
916
            scope '*ref', constraints: { ref: Gitlab::Regex.git_reference_regex } do
917 918 919 920
              constraints format: /svg/ do
                get :build
                get :coverage
              end
921
            end
922 923
          end
        end
924
      end
925
    end
gitlabhq's avatar
gitlabhq committed
926
  end
927

928
  # Get all keys of user
929
  get ':username.keys' => 'profiles/keys#get_keys', constraints: { username: /.*/ }
930

931
  get ':id' => 'namespaces#show', constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }
gitlabhq's avatar
gitlabhq committed
932
end