Commit 39c657930625ddc3ac8a921f01ffc83acadce68f

Authored by Robert Speicher
1 parent 37f0b600

Add BlameController, remove Refs#blame action

app/controllers/blame_controller.rb 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +# Controller for viewing a file's blame
  2 +class BlameController < ApplicationController
  3 + # Thrown when given an invalid path
  4 + class InvalidPathError < StandardError; end
  5 +
  6 + include RefExtractor
  7 +
  8 + layout "project"
  9 +
  10 + before_filter :project
  11 +
  12 + # Authorize
  13 + before_filter :add_project_abilities
  14 + before_filter :authorize_read_project!
  15 + before_filter :authorize_code_access!
  16 + before_filter :require_non_empty_project
  17 +
  18 + before_filter :define_tree_vars
  19 +
  20 + def show
  21 + @blame = Grit::Blob.blame(@repo, @commit.id, @path)
  22 + end
  23 +
  24 + private
  25 +
  26 + def define_tree_vars
  27 + @ref, @path = extract_ref(params[:id])
  28 +
  29 + @id = File.join(@ref, @path)
  30 + @repo = @project.repo
  31 + @commit = CommitDecorator.decorate(@project.commit(@ref))
  32 +
  33 + @tree = Tree.new(@commit.tree, @project, @ref, @path)
  34 + @tree = TreeDecorator.new(@tree)
  35 +
  36 + raise InvalidPathError if @tree.invalid?
  37 +
  38 + @hex_path = Digest::SHA1.hexdigest(@path)
  39 +
  40 + @history_path = project_tree_path(@project, @id)
  41 + @logs_path = logs_file_project_ref_path(@project, @ref, @path)
  42 + rescue NoMethodError, InvalidPathError
  43 + not_found!
  44 + end
  45 +end
... ...
app/controllers/refs_controller.rb
... ... @@ -9,7 +9,7 @@ class RefsController &lt; ApplicationController
9 9 before_filter :require_non_empty_project
10 10  
11 11 before_filter :ref
12   - before_filter :define_tree_vars, only: [:tree, :blob, :blame, :logs_tree]
  12 + before_filter :define_tree_vars, only: [:blob, :logs_tree]
13 13 before_filter :render_full_content
14 14  
15 15 layout "project"
... ... @@ -79,10 +79,6 @@ class RefsController &lt; ApplicationController
79 79 end
80 80 end
81 81  
82   - def blame
83   - @blame = Grit::Blob.blame(@repo, @commit.id, params[:path])
84   - end
85   -
86 82 protected
87 83  
88 84 def define_tree_vars
... ...
app/views/blame/_head.html.haml 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +%ul.nav.nav-tabs
  2 + %li
  3 + = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: params[:path]}
  4 + %li{class: "#{'active' if (controller.controller_name == "refs") }"}
  5 + = link_to project_tree_path(@project, @ref) do
  6 + Source
  7 + %li.right
  8 + .input-prepend.project_clone_holder
  9 + %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH
  10 + %button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP
  11 + = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
... ...
app/views/blame/show.html.haml
... ... @@ -20,7 +20,7 @@
20 20 %span.options
21 21 = link_to "raw", blob_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small", target: "_blank"
22 22 = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small"
23   - = link_to "source", project_tree_path(@project, tree_join(@ref, params[:path])), class: "btn very_small"
  23 + = link_to "source", project_tree_path(@project, @id), class: "btn very_small"
24 24 .file_content.blame
25 25 %table
26 26 - @blame.each do |commit, lines|
... ...
app/views/refs/_head.html.haml
... ... @@ -1,11 +0,0 @@
1   -%ul.nav.nav-tabs
2   - %li
3   - = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: params[:path]}
4   - %li{class: "#{'active' if (controller.controller_name == "refs") }"}
5   - = link_to project_tree_path(@project, @ref) do
6   - Source
7   - %li.right
8   - .input-prepend.project_clone_holder
9   - %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH
10   - %button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP
11   - = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
app/views/tree/_tree_file.html.haml
... ... @@ -7,7 +7,7 @@
7 7 %span.options
8 8 = link_to "raw", blob_project_ref_path(@project, @ref, path: @path), class: "btn very_small", target: "_blank"
9 9 = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small"
10   - = link_to "blame", blame_file_project_ref_path(@project, @ref, path: @path.gsub(/^\//, '')), class: "btn very_small"
  10 + = link_to "blame", project_blame_path(@project, @id), class: "btn very_small"
11 11 - if file.text?
12 12 - if gitlab_markdown?(name)
13 13 .file_content.wiki
... ...
config/routes.rb
... ... @@ -136,14 +136,6 @@ Gitlab::Application.routes.draw do
136 136 id: /[a-zA-Z.0-9\/_\-]+/,
137 137 path: /.*/
138 138 }
139   -
140   - # blame
141   - get "blame/:path" => "refs#blame",
142   - as: :blame_file,
143   - constraints: {
144   - id: /[a-zA-Z.0-9\/_\-]+/,
145   - path: /.*/
146   - }
147 139 end
148 140 end
149 141  
... ... @@ -204,7 +196,7 @@ Gitlab::Application.routes.draw do
204 196 end
205 197  
206 198 # XXX: WIP
207   - # resources :blame, only: [:show], constraints: {id: /.+/}
  199 + resources :blame, only: [:show], constraints: {id: /.+/}
208 200 # resources :blob, only: [:show], constraints: {id: /.+/}
209 201 # resources :raw, only: [:show], constraints: {id: /.+/}
210 202 resources :tree, only: [:show], constraints: {id: /.+/}
... ...
spec/requests/gitlab_flavored_markdown_spec.rb
... ... @@ -69,7 +69,7 @@ describe &quot;Gitlab Flavored Markdown&quot; do
69 69 end
70 70  
71 71 it "should render title in refs#blame" do
72   - visit blame_file_project_ref_path(project, id: @branch_name, path: @test_file)
  72 + visit blame_file_project_ref_path(project, File.join(@branch_name, @test_file))
73 73  
74 74 within(".blame_commit") do
75 75 page.should have_link("##{issue.id}")
... ...
spec/routing/project_routing_spec.rb
... ... @@ -195,7 +195,6 @@ end
195 195 # blob_project_ref GET /:project_id/:id/blob(.:format) refs#blob
196 196 # logs_tree_project_ref GET /:project_id/:id/logs_tree(.:format) refs#logs_tree
197 197 # logs_file_project_ref GET /:project_id/:id/logs_tree/:path(.:format) refs#logs_tree
198   -# blame_file_project_ref GET /:project_id/:id/blame/:path(.:format) refs#blame
199 198 describe RefsController, "routing" do
200 199 it "to #switch" do
201 200 get("/gitlabhq/switch").should route_to('refs#switch', project_id: 'gitlabhq')
... ... @@ -209,10 +208,6 @@ describe RefsController, &quot;routing&quot; do
209 208 it "to #blob" do
210 209 get("/gitlabhq/stable/blob").should route_to('refs#blob', project_id: 'gitlabhq', id: 'stable')
211 210 end
212   -
213   - it "to #blame" do
214   - get("/gitlabhq/stable/blame/foo/bar/baz").should route_to('refs#blame', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
215   - end
216 211 end
217 212  
218 213 # diffs_project_merge_request GET /:project_id/merge_requests/:id/diffs(.:format) merge_requests#diffs
... ... @@ -399,6 +394,12 @@ describe NotesController, &quot;routing&quot; do
399 394 end
400 395 end
401 396  
  397 +describe BlameController, "routing" do
  398 + it "to #show" do
  399 + get("/gitlabhq/blame/master/app/models/project.rb").should route_to('blame#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
  400 + end
  401 +end
  402 +
402 403 describe TreeController, "routing" do
403 404 it "to #show" do
404 405 get("/gitlabhq/tree/master/app/models/project.rb").should route_to('tree#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
... ... @@ -432,11 +433,7 @@ end
432 433 # /gitlabhq/tree/master/app
433 434 # /gitlabhq/tree/test/branch/name/app
434 435 describe "pending routing" do
435   - describe "/:project_id/blame/:id" do
436   - it "routes to a ref with a path" do
437   - get("/gitlabhq/blame/master/app/models/project.rb").should route_to('blame#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
438   - end
439   - end
  436 + before { pending }
440 437  
441 438 describe "/:project_id/blob/:id" do
442 439 it "routes to a ref with a path" do
... ...