Commit b6641d69326db65da0a746f46bd4c2743bb6725f

Authored by Dmitriy Zaporozhets
2 parents 979dcdba a1fe375e

Merge branch 'fix-404-json-file' of https://github.com/hiroponz/gitlabhq into hi…

…roponz-fix-404-json-file
app/controllers/blame_controller.rb
@@ -7,8 +7,6 @@ class BlameController < ProjectResourceController @@ -7,8 +7,6 @@ class BlameController < ProjectResourceController
7 before_filter :authorize_code_access! 7 before_filter :authorize_code_access!
8 before_filter :require_non_empty_project 8 before_filter :require_non_empty_project
9 9
10 - before_filter :assign_ref_vars  
11 -  
12 def show 10 def show
13 @repo = @project.repo 11 @repo = @project.repo
14 @blame = Grit::Blob.blame(@repo, @commit.id, @path) 12 @blame = Grit::Blob.blame(@repo, @commit.id, @path)
app/controllers/blob_controller.rb
@@ -7,8 +7,6 @@ class BlobController < ProjectResourceController @@ -7,8 +7,6 @@ class BlobController < ProjectResourceController
7 before_filter :authorize_code_access! 7 before_filter :authorize_code_access!
8 before_filter :require_non_empty_project 8 before_filter :require_non_empty_project
9 9
10 - before_filter :assign_ref_vars  
11 -  
12 def show 10 def show
13 if @tree.is_blob? 11 if @tree.is_blob?
14 send_data( 12 send_data(
app/controllers/tree_controller.rb
@@ -7,7 +7,6 @@ class TreeController < ProjectResourceController @@ -7,7 +7,6 @@ class TreeController < ProjectResourceController
7 before_filter :authorize_code_access! 7 before_filter :authorize_code_access!
8 before_filter :require_non_empty_project 8 before_filter :require_non_empty_project
9 9
10 - before_filter :assign_ref_vars  
11 before_filter :edit_requirements, only: [:edit, :update] 10 before_filter :edit_requirements, only: [:edit, :update]
12 11
13 def show 12 def show
lib/extracts_path.rb
@@ -8,7 +8,7 @@ module ExtractsPath @@ -8,7 +8,7 @@ module ExtractsPath
8 8
9 included do 9 included do
10 if respond_to?(:before_filter) 10 if respond_to?(:before_filter)
11 - before_filter :assign_ref_vars, only: [:show] 11 + before_filter :assign_ref_vars
12 end 12 end
13 end 13 end
14 14
@@ -33,7 +33,7 @@ module ExtractsPath @@ -33,7 +33,7 @@ module ExtractsPath
33 # extract_ref("v2.0.0/README.md") 33 # extract_ref("v2.0.0/README.md")
34 # # => ['v2.0.0', 'README.md'] 34 # # => ['v2.0.0', 'README.md']
35 # 35 #
36 - # extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb') 36 + # extract_ref('master/app/models/project.rb')
37 # # => ['master', 'app/models/project.rb'] 37 # # => ['master', 'app/models/project.rb']
38 # 38 #
39 # extract_ref('issues/1234/app/models/project.rb') 39 # extract_ref('issues/1234/app/models/project.rb')
@@ -45,22 +45,12 @@ module ExtractsPath @@ -45,22 +45,12 @@ module ExtractsPath
45 # 45 #
46 # Returns an Array where the first value is the tree-ish and the second is the 46 # Returns an Array where the first value is the tree-ish and the second is the
47 # path 47 # path
48 - def extract_ref(input) 48 + def extract_ref(id)
49 pair = ['', ''] 49 pair = ['', '']
50 50
51 return pair unless @project 51 return pair unless @project
52 52
53 - # Remove relative_url_root from path  
54 - input.gsub!(/^#{Gitlab.config.gitlab.relative_url_root}/, "")  
55 - # Remove project, actions and all other staff from path  
56 - input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "")  
57 - input.gsub!(/^\/(tree|commits|blame|blob|refs|graph)\//, "") # remove actions  
58 - input.gsub!(/\?.*$/, "") # remove stamps suffix  
59 - input.gsub!(/.atom$/, "") # remove rss feed  
60 - input.gsub!(/.json$/, "") # remove json suffix  
61 - input.gsub!(/\/edit$/, "") # remove edit route part  
62 -  
63 - if input.match(/^([[:alnum:]]{40})(.+)/) 53 + if id.match(/^([[:alnum:]]{40})(.+)/)
64 # If the ref appears to be a SHA, we're done, just split the string 54 # If the ref appears to be a SHA, we're done, just split the string
65 pair = $~.captures 55 pair = $~.captures
66 else 56 else
@@ -68,7 +58,6 @@ module ExtractsPath @@ -68,7 +58,6 @@ module ExtractsPath
68 # branches and tags 58 # branches and tags
69 59
70 # Append a trailing slash if we only get a ref and no file path 60 # Append a trailing slash if we only get a ref and no file path
71 - id = input  
72 id += '/' unless id.ends_with?('/') 61 id += '/' unless id.ends_with?('/')
73 62
74 valid_refs = @project.repository.ref_names 63 valid_refs = @project.repository.ref_names
@@ -105,11 +94,9 @@ module ExtractsPath @@ -105,11 +94,9 @@ module ExtractsPath
105 # Automatically renders `not_found!` if a valid tree path could not be 94 # Automatically renders `not_found!` if a valid tree path could not be
106 # resolved (e.g., when a user inserts an invalid path or ref). 95 # resolved (e.g., when a user inserts an invalid path or ref).
107 def assign_ref_vars 96 def assign_ref_vars
108 - path = CGI::unescape(request.fullpath.dup)  
109 -  
110 - @ref, @path = extract_ref(path) 97 + @id = params[:id]
111 98
112 - @id = File.join(@ref, @path) 99 + @ref, @path = extract_ref(@id)
113 100
114 # It is used "@project.repository.commits(@ref, @path, 1, 0)", 101 # It is used "@project.repository.commits(@ref, @path, 1, 0)",
115 # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name. 102 # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.
spec/lib/extracts_path_spec.rb
@@ -54,47 +54,5 @@ describe ExtractsPath do @@ -54,47 +54,5 @@ describe ExtractsPath do
54 extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG'] 54 extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
55 end 55 end
56 end 56 end
57 -  
58 - context "with a fullpath" do  
59 - it "extracts a valid branch" do  
60 - extract_ref('/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']  
61 - end  
62 -  
63 - it "extracts a valid tag" do  
64 - extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']  
65 - end  
66 -  
67 - it "extracts a valid commit SHA" do  
68 - extract_ref('/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==  
69 - ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']  
70 - end  
71 -  
72 - it "extracts a timestamp" do  
73 - extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']  
74 - end  
75 - end  
76 -  
77 - context "with a fullpath and a relative_url_root" do  
78 - before do  
79 - Gitlab.config.gitlab.stub(relative_url_root: '/relative')  
80 - end  
81 -  
82 - it "extracts a valid branch with relative_url_root" do  
83 - extract_ref('/relative/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']  
84 - end  
85 -  
86 - it "extracts a valid tag" do  
87 - extract_ref('/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']  
88 - end  
89 -  
90 - it "extracts a valid commit SHA" do  
91 - extract_ref('/relative/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==  
92 - ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']  
93 - end  
94 -  
95 - it "extracts a timestamp" do  
96 - extract_ref('/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']  
97 - end  
98 - end  
99 end 57 end
100 end 58 end