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 7 before_filter :authorize_code_access!
8 8 before_filter :require_non_empty_project
9 9  
10   - before_filter :assign_ref_vars
11   -
12 10 def show
13 11 @repo = @project.repo
14 12 @blame = Grit::Blob.blame(@repo, @commit.id, @path)
... ...
app/controllers/blob_controller.rb
... ... @@ -7,8 +7,6 @@ class BlobController < ProjectResourceController
7 7 before_filter :authorize_code_access!
8 8 before_filter :require_non_empty_project
9 9  
10   - before_filter :assign_ref_vars
11   -
12 10 def show
13 11 if @tree.is_blob?
14 12 send_data(
... ...
app/controllers/tree_controller.rb
... ... @@ -7,7 +7,6 @@ class TreeController < ProjectResourceController
7 7 before_filter :authorize_code_access!
8 8 before_filter :require_non_empty_project
9 9  
10   - before_filter :assign_ref_vars
11 10 before_filter :edit_requirements, only: [:edit, :update]
12 11  
13 12 def show
... ...
lib/extracts_path.rb
... ... @@ -8,7 +8,7 @@ module ExtractsPath
8 8  
9 9 included do
10 10 if respond_to?(:before_filter)
11   - before_filter :assign_ref_vars, only: [:show]
  11 + before_filter :assign_ref_vars
12 12 end
13 13 end
14 14  
... ... @@ -33,7 +33,7 @@ module ExtractsPath
33 33 # extract_ref("v2.0.0/README.md")
34 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 37 # # => ['master', 'app/models/project.rb']
38 38 #
39 39 # extract_ref('issues/1234/app/models/project.rb')
... ... @@ -45,22 +45,12 @@ module ExtractsPath
45 45 #
46 46 # Returns an Array where the first value is the tree-ish and the second is the
47 47 # path
48   - def extract_ref(input)
  48 + def extract_ref(id)
49 49 pair = ['', '']
50 50  
51 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 54 # If the ref appears to be a SHA, we're done, just split the string
65 55 pair = $~.captures
66 56 else
... ... @@ -68,7 +58,6 @@ module ExtractsPath
68 58 # branches and tags
69 59  
70 60 # Append a trailing slash if we only get a ref and no file path
71   - id = input
72 61 id += '/' unless id.ends_with?('/')
73 62  
74 63 valid_refs = @project.repository.ref_names
... ... @@ -105,11 +94,9 @@ module ExtractsPath
105 94 # Automatically renders `not_found!` if a valid tree path could not be
106 95 # resolved (e.g., when a user inserts an invalid path or ref).
107 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 101 # It is used "@project.repository.commits(@ref, @path, 1, 0)",
115 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 54 extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
55 55 end
56 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 57 end
100 58 end
... ...