Fix routing issues when navigating over tree, commits etc
This commit is contained in:
parent
49e73f8ac1
commit
c8ba5c2d58
|
@ -70,4 +70,12 @@ module CommitsHelper
|
|||
escape_javascript(render 'commits/commit', commit: commit)
|
||||
end
|
||||
end
|
||||
|
||||
def diff_line_content(line)
|
||||
if line.blank?
|
||||
" "
|
||||
else
|
||||
line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -102,7 +102,7 @@ class Project < ActiveRecord::Base
|
|||
if id.include?("/")
|
||||
id = id.split("/")
|
||||
namespace_id = Namespace.find_by_path(id.first).id
|
||||
where(namespace_id: namespace_id).find_by_path(id.last)
|
||||
where(namespace_id: namespace_id).find_by_path(id.second)
|
||||
else
|
||||
where(path: id, namespace_id: nil).last
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
- if @comments_allowed
|
||||
= render "notes/per_line_note_link", line_code: line_code
|
||||
%td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code
|
||||
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line} "
|
||||
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line)
|
||||
|
||||
- if @comments_allowed
|
||||
- comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at)
|
||||
|
|
|
@ -112,7 +112,7 @@ Gitlab::Application.routes.draw do
|
|||
#
|
||||
# Project Area
|
||||
#
|
||||
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do
|
||||
resources :projects, constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }, except: [:new, :create, :index], path: "/" do
|
||||
member do
|
||||
get "wall"
|
||||
get "graph"
|
||||
|
@ -190,12 +190,12 @@ Gitlab::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/}
|
||||
resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/}
|
||||
resources :commits, only: [:show], constraints: {id: /.+/}
|
||||
resources :compare, only: [:index, :create]
|
||||
resources :blame, only: [:show], constraints: {id: /.+/}
|
||||
resources :blob, only: [:show], constraints: {id: /.+/}
|
||||
resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/}
|
||||
match "/compare/:from...:to" => "compare#show", as: "compare",
|
||||
:via => [:get, :post], constraints: {from: /.+/, to: /.+/}
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ module ExtractsPath
|
|||
# extract_ref("v2.0.0/README.md")
|
||||
# # => ['v2.0.0', 'README.md']
|
||||
#
|
||||
# extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb')
|
||||
# # => ['master', 'app/models/project.rb']
|
||||
#
|
||||
# extract_ref('issues/1234/app/models/project.rb')
|
||||
# # => ['issues/1234', 'app/models/project.rb']
|
||||
#
|
||||
|
@ -47,6 +50,13 @@ module ExtractsPath
|
|||
|
||||
return pair unless @project
|
||||
|
||||
# Remove project, actions and all other staff from path
|
||||
input.gsub!("/#{@project.path_with_namespace}", "")
|
||||
input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions
|
||||
input.gsub!(/\?.*$/, "") # remove stamps suffix
|
||||
input.gsub!(/.atom$/, "") # remove rss feed
|
||||
input.gsub!(/\/edit$/, "") # remove edit route part
|
||||
|
||||
if input.match(/^([[:alnum:]]{40})(.+)/)
|
||||
# If the ref appears to be a SHA, we're done, just split the string
|
||||
pair = $~.captures
|
||||
|
@ -98,7 +108,7 @@ module ExtractsPath
|
|||
request.format = :atom
|
||||
end
|
||||
|
||||
@ref, @path = extract_ref(params[:id])
|
||||
@ref, @path = extract_ref(request.fullpath)
|
||||
|
||||
@id = File.join(@ref, @path)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ describe ExtractsPath do
|
|||
before do
|
||||
@project = project
|
||||
project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])
|
||||
project.stub(path_with_namespace: 'gitlab/gitlab-ci')
|
||||
end
|
||||
|
||||
describe '#extract_ref' do
|
||||
|
@ -53,5 +54,24 @@ describe ExtractsPath do
|
|||
extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
|
||||
end
|
||||
end
|
||||
|
||||
context "with a fullpath" do
|
||||
it "extracts a valid branch" do
|
||||
extract_ref('/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
|
||||
end
|
||||
|
||||
it "extracts a valid tag" do
|
||||
extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
|
||||
end
|
||||
|
||||
it "extracts a valid commit SHA" do
|
||||
extract_ref('/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
|
||||
['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
|
||||
end
|
||||
|
||||
it "extracts a timestamp" do
|
||||
extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'rake'
|
|||
|
||||
describe 'gitlab:app namespace rake task' do
|
||||
before :all do
|
||||
Rake.application.rake_require "tasks/gitlab/task_helpers"
|
||||
Rake.application.rake_require "tasks/gitlab/backup"
|
||||
# empty task as env is already loaded
|
||||
Rake::Task.define_task :environment
|
||||
|
|
Loading…
Reference in a new issue