Commit c03bc268 authored by Kia Mei Somabes's avatar Kia Mei Somabes

Transfer to commits_controller, add test, and update changelog

parent 3b4734ce
...@@ -63,10 +63,6 @@ class ApplicationController < ActionController::Base ...@@ -63,10 +63,6 @@ class ApplicationController < ActionController::Base
render_503 render_503
end end
def redirect_commits_root
redirect_to controller: 'commits', action: 'show', id: @repository.root_ref
end
def redirect_back_or_default(default: root_path, options: {}) def redirect_back_or_default(default: root_path, options: {})
redirect_to request.referer.present? ? :back : default, options redirect_to request.referer.present? ? :back : default, options
end end
......
...@@ -4,13 +4,17 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -4,13 +4,17 @@ class Projects::CommitsController < Projects::ApplicationController
include ExtractsPath include ExtractsPath
include RendersCommits include RendersCommits
before_action :whitelist_query_limiting before_action :whitelist_query_limiting, except: :commits_root
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :assign_ref_vars before_action :assign_ref_vars, except: :commits_root
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :set_commits before_action :set_commits, except: :commits_root
before_action :set_request_format, only: :show before_action :set_request_format, only: :show
def commits_root
redirect_to project_commits_path(@project, @project.default_branch)
end
def show def show
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened @merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref) .find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
......
--- ---
title: Redirect commits to root if no ref is provided (31576) title: Redirect commits to root if no ref is provided (31576)
merge_request: merge_request: 20738
author: Kia Mei Somabes author: Kia Mei Somabes
type: added type: added
...@@ -83,7 +83,7 @@ scope format: false do ...@@ -83,7 +83,7 @@ scope format: false do
get '/raw/*id', to: 'raw#show', as: :raw get '/raw/*id', to: 'raw#show', as: :raw
get '/blame/*id', to: 'blame#show', as: :blame get '/blame/*id', to: 'blame#show', as: :blame
get '/commits/', to: 'application#redirect_commits_root', as: :commits_root get '/commits', to: 'commits#commits_root', as: :commits_root
get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures
get '/commits/*id', to: 'commits#show', as: :commits get '/commits/*id', to: 'commits#show', as: :commits
......
...@@ -9,6 +9,20 @@ describe Projects::CommitsController do ...@@ -9,6 +9,20 @@ describe Projects::CommitsController do
project.add_master(user) project.add_master(user)
end end
describe "GET commits_root" do
context "no ref is provided" do
before do
get(:commits_root,
namespace_id: project.namespace,
project_id: project)
end
it 'should redirect to the default branch of the project' do
expect(response).to redirect_to project_commits_path(project)
end
end
end
describe "GET show" do describe "GET show" do
render_views render_views
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment