Commit c8ba5c2d58b882fd7cd5342a42158bb5f810fd60
1 parent
49e73f8a
Exists in
master
and in
4 other branches
Fix routing issues when navigating over tree, commits etc
Showing
7 changed files
with
44 additions
and
5 deletions
Show diff stats
app/helpers/commits_helper.rb
app/models/project.rb
| ... | ... | @@ -102,7 +102,7 @@ class Project < ActiveRecord::Base |
| 102 | 102 | if id.include?("/") |
| 103 | 103 | id = id.split("/") |
| 104 | 104 | namespace_id = Namespace.find_by_path(id.first).id |
| 105 | - where(namespace_id: namespace_id).find_by_path(id.last) | |
| 105 | + where(namespace_id: namespace_id).find_by_path(id.second) | |
| 106 | 106 | else |
| 107 | 107 | where(path: id, namespace_id: nil).last |
| 108 | 108 | end | ... | ... |
app/views/commits/_text_file.html.haml
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | - if @comments_allowed |
| 16 | 16 | = render "notes/per_line_note_link", line_code: line_code |
| 17 | 17 | %td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code |
| 18 | - %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line} " | |
| 18 | + %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line) | |
| 19 | 19 | |
| 20 | 20 | - if @comments_allowed |
| 21 | 21 | - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) | ... | ... |
config/routes.rb
| ... | ... | @@ -112,7 +112,7 @@ Gitlab::Application.routes.draw do |
| 112 | 112 | # |
| 113 | 113 | # Project Area |
| 114 | 114 | # |
| 115 | - resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do | |
| 115 | + resources :projects, constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }, except: [:new, :create, :index], path: "/" do | |
| 116 | 116 | member do |
| 117 | 117 | get "wall" |
| 118 | 118 | get "graph" |
| ... | ... | @@ -190,12 +190,12 @@ Gitlab::Application.routes.draw do |
| 190 | 190 | end |
| 191 | 191 | end |
| 192 | 192 | |
| 193 | + resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/} | |
| 193 | 194 | resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/} |
| 194 | 195 | resources :commits, only: [:show], constraints: {id: /.+/} |
| 195 | 196 | resources :compare, only: [:index, :create] |
| 196 | 197 | resources :blame, only: [:show], constraints: {id: /.+/} |
| 197 | 198 | resources :blob, only: [:show], constraints: {id: /.+/} |
| 198 | - resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/} | |
| 199 | 199 | match "/compare/:from...:to" => "compare#show", as: "compare", |
| 200 | 200 | :via => [:get, :post], constraints: {from: /.+/, to: /.+/} |
| 201 | 201 | ... | ... |
lib/extracts_path.rb
| ... | ... | @@ -33,6 +33,9 @@ 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') | |
| 37 | + # # => ['master', 'app/models/project.rb'] | |
| 38 | + # | |
| 36 | 39 | # extract_ref('issues/1234/app/models/project.rb') |
| 37 | 40 | # # => ['issues/1234', 'app/models/project.rb'] |
| 38 | 41 | # |
| ... | ... | @@ -47,6 +50,13 @@ module ExtractsPath |
| 47 | 50 | |
| 48 | 51 | return pair unless @project |
| 49 | 52 | |
| 53 | + # Remove project, actions and all other staff from path | |
| 54 | + input.gsub!("/#{@project.path_with_namespace}", "") | |
| 55 | + input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions | |
| 56 | + input.gsub!(/\?.*$/, "") # remove stamps suffix | |
| 57 | + input.gsub!(/.atom$/, "") # remove rss feed | |
| 58 | + input.gsub!(/\/edit$/, "") # remove edit route part | |
| 59 | + | |
| 50 | 60 | if input.match(/^([[:alnum:]]{40})(.+)/) |
| 51 | 61 | # If the ref appears to be a SHA, we're done, just split the string |
| 52 | 62 | pair = $~.captures |
| ... | ... | @@ -98,7 +108,7 @@ module ExtractsPath |
| 98 | 108 | request.format = :atom |
| 99 | 109 | end |
| 100 | 110 | |
| 101 | - @ref, @path = extract_ref(params[:id]) | |
| 111 | + @ref, @path = extract_ref(request.fullpath) | |
| 102 | 112 | |
| 103 | 113 | @id = File.join(@ref, @path) |
| 104 | 114 | ... | ... |
spec/lib/extracts_path_spec.rb
| ... | ... | @@ -8,6 +8,7 @@ describe ExtractsPath do |
| 8 | 8 | before do |
| 9 | 9 | @project = project |
| 10 | 10 | project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']) |
| 11 | + project.stub(path_with_namespace: 'gitlab/gitlab-ci') | |
| 11 | 12 | end |
| 12 | 13 | |
| 13 | 14 | describe '#extract_ref' do |
| ... | ... | @@ -53,5 +54,24 @@ describe ExtractsPath do |
| 53 | 54 | extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG'] |
| 54 | 55 | end |
| 55 | 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 | |
| 56 | 76 | end |
| 57 | 77 | end | ... | ... |
spec/tasks/gitlab/backup_rake_spec.rb
| ... | ... | @@ -3,6 +3,7 @@ require 'rake' |
| 3 | 3 | |
| 4 | 4 | describe 'gitlab:app namespace rake task' do |
| 5 | 5 | before :all do |
| 6 | + Rake.application.rake_require "tasks/gitlab/task_helpers" | |
| 6 | 7 | Rake.application.rake_require "tasks/gitlab/backup" |
| 7 | 8 | # empty task as env is already loaded |
| 8 | 9 | Rake::Task.define_task :environment | ... | ... |