<commit_before>require 'constraints/project_url_constrainer'

resources :projects, only: [:index, :new, :create]

draw :git_http

constraints(ProjectUrlConstrainer.new) do
  scope(path: '*namespace_id', as: :namespace) do
    scope(path: ':project_id',
          constraints: { project_id: Gitlab::Regex.project_route_regex },
          module: :projects,
          as: :project) do

      resources :autocomplete_sources, only: [] do
        collection do
          get 'members'
          get 'issues'
          get 'merge_requests'
          get 'labels'
          get 'milestones'
          get 'commands'
        end
      end

      #
      # Templates
      #
      get '/templates/:template_type/:key' => 'templates#show', as: :template

      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
        end
      end

      resource :pages, only: [:show, :destroy] do
        resources :domains, only: [:show, :new, :create, :destroy], controller: 'pages_domains', constraints: { id: /[^\/]+/ }
      end

      resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
          get :raw
          post :mark_as_spam
        end
      end

      resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
        member do
          get :test
        end
      end

      resource :mattermost, only: [:new, :create]

      resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
        member do
          put :enable
          put :disable
        end
      end

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

      resources :merge_requests, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
          get :commits
          get :diffs
          get :conflicts
          get :conflict_for_path
          get :pipelines
          get :merge_check
          get :commit_change_content
          post :merge
          post :cancel_merge_when_pipeline_succeeds
          get :pipeline_status
          get :ci_environments_status
          post :toggle_subscription
          post :remove_wip
          get :diff_for_path
          post :resolve_conflicts
          post :assign_related_issues
        end

        collection do
          get :branch_from
          get :branch_to
          get :update_branches
          get :diff_for_path
          post :bulk_update
          get :new_diffs, path: 'new/diffs'
        end

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

      resources :variables, only: [:index, :show, :update, :create, :destroy]
      resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
        member do
          post :take_ownership
        end
      end

      resources :pipelines, only: [:index, :new, :create, :show] do
        collection do
          resource :pipelines_settings, path: 'settings', only: [:show, :update]
          get :charts
        end

        member do
          get :stage
          post :cancel
          post :retry
          get :builds
          get :failures
          get :status
        end
      end

      resources :pipeline_schedules, except: [:show] do
        member do
          post :take_ownership
        end
      end

      resources :environments, except: [:destroy] do
        member do
          post :stop
          get :terminal
          get :metrics
          get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', constraints: { format: nil }
        end

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

        resources :deployments, only: [:index] do
          member do
            get :metrics
          end
        end
      end

      resource :cycle_analytics, only: [:show]

      namespace :cycle_analytics do
        scope :events, controller: 'events' do
          get :issue
          get :plan
          get :code
          get :test
          get :review
          get :staging
          get :production
        end
      end

      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
          end
        end

        member do
          get :status
          post :cancel
          post :retry
          post :play
          post :erase
          get :trace, defaults: { format: 'json' }
          get :raw
        end

        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
      end

      # It's a block, not a hash, disabling style check for hash
      # rubocop:disable Style/AlignHash
      get '/builds/:id/:action', as: 'action_legacy_build',
        to: redirect { |params, req|
          args = params.values_at(:namespace_id, :project_id, :id)

          case params[:action]
          when 'status'
            Gitlab::Routing.url_helpers.status_namespace_project_job_path(*args, format: params[:format])
          when 'trace'
            Gitlab::Routing.url_helpers.trace_namespace_project_job_path(*args, format: params[:format])
          when 'raw'
            Gitlab::Routing.url_helpers.raw_namespace_project_job_path(*args)
          else
            Gitlab::Routing.url_helpers.namespace_project_job_path(*args)
          end
        }

      # It's a block, not a hash, disabling style check for hash
      # rubocop:disable Style/AlignHash
      get '/builds/:id', as: 'legacy_build',
        to: redirect { |params, req|
          Gitlab::Routing.url_helpers.namespace_project_job_path(
            params[:namespace_id], params[:project_id], params[:id])
        }

      # It's a block, not a hash, disabling style check for hash
      # rubocop:disable Style/AlignHash
      get '/builds', as: 'legacy_builds',
        to: redirect { |params, req|
          Gitlab::Routing.url_helpers.namespace_project_jobs_path(
            params[:namespace_id], params[:project_id])
        }

      resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
        member do
          get :test
        end
      end
<commit_msg>Use a single route, reducing duplication<commit_after>require 'constraints/project_url_constrainer'

resources :projects, only: [:index, :new, :create]

draw :git_http

constraints(ProjectUrlConstrainer.new) do
  scope(path: '*namespace_id', as: :namespace) do
    scope(path: ':project_id',
          constraints: { project_id: Gitlab::Regex.project_route_regex },
          module: :projects,
          as: :project) do

      resources :autocomplete_sources, only: [] do
        collection do
          get 'members'
          get 'issues'
          get 'merge_requests'
          get 'labels'
          get 'milestones'
          get 'commands'
        end
      end

      #
      # Templates
      #
      get '/templates/:template_type/:key' => 'templates#show', as: :template

      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
        end
      end

      resource :pages, only: [:show, :destroy] do
        resources :domains, only: [:show, :new, :create, :destroy], controller: 'pages_domains', constraints: { id: /[^\/]+/ }
      end

      resources :snippets, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
          get :raw
          post :mark_as_spam
        end
      end

      resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
        member do
          get :test
        end
      end

      resource :mattermost, only: [:new, :create]

      resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
        member do
          put :enable
          put :disable
        end
      end

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

      resources :merge_requests, concerns: :awardable, constraints: { id: /\d+/ } do
        member do
          get :commits
          get :diffs
          get :conflicts
          get :conflict_for_path
          get :pipelines
          get :merge_check
          get :commit_change_content
          post :merge
          post :cancel_merge_when_pipeline_succeeds
          get :pipeline_status
          get :ci_environments_status
          post :toggle_subscription
          post :remove_wip
          get :diff_for_path
          post :resolve_conflicts
          post :assign_related_issues
        end

        collection do
          get :branch_from
          get :branch_to
          get :update_branches
          get :diff_for_path
          post :bulk_update
          get :new_diffs, path: 'new/diffs'
        end

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

      resources :variables, only: [:index, :show, :update, :create, :destroy]
      resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
        member do
          post :take_ownership
        end
      end

      resources :pipelines, only: [:index, :new, :create, :show] do
        collection do
          resource :pipelines_settings, path: 'settings', only: [:show, :update]
          get :charts
        end

        member do
          get :stage
          post :cancel
          post :retry
          get :builds
          get :failures
          get :status
        end
      end

      resources :pipeline_schedules, except: [:show] do
        member do
          post :take_ownership
        end
      end

      resources :environments, except: [:destroy] do
        member do
          post :stop
          get :terminal
          get :metrics
          get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', constraints: { format: nil }
        end

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

        resources :deployments, only: [:index] do
          member do
            get :metrics
          end
        end
      end

      resource :cycle_analytics, only: [:show]

      namespace :cycle_analytics do
        scope :events, controller: 'events' do
          get :issue
          get :plan
          get :code
          get :test
          get :review
          get :staging
          get :production
        end
      end

      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
          end
        end

        member do
          get :status
          post :cancel
          post :retry
          post :play
          post :erase
          get :trace, defaults: { format: 'json' }
          get :raw
        end

        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
      end

      redirect_builds_to_jobs = redirect do |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])
          when 'trace'
            url_helpers.trace_namespace_project_job_path(*args, format: params[:format])
          when 'raw'
            url_helpers.raw_namespace_project_job_path(*args)
          else # show
            url_helpers.namespace_project_job_path(*args)
          end
        else # index
          url_helpers.namespace_project_jobs_path(*args)
        end
      end

      get '/builds(/:id(/:action))', to: redirect_builds_to_jobs,
                                     as: 'legacy_build'

      resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
        member do
          get :test
        end
      end

{'fraction_non_alphanumeric': 0.09840126097725738, 'fraction_numerical': 0.000750581700818134, 'mean_word_length': 1.7483498349834983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4405840', 'n_tokens_mistral': 3853, 'n_tokens_neox': 3733, 'n_words': 1094}