Commit 5133541f25f91b83d17550983bd4cf93d39ae574

Authored by Dmitriy Zaporozhets
2 parents 05848512 f9877c52

Merge pull request #1127 from riyad/use-decorators

Use CommitDecorator more
app/controllers/commits_controller.rb
@@ -17,6 +17,7 @@ class CommitsController < ApplicationController @@ -17,6 +17,7 @@ class CommitsController < ApplicationController
17 @limit, @offset = (params[:limit] || 40), (params[:offset] || 0) 17 @limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
18 18
19 @commits = @project.commits(@ref, params[:path], @limit, @offset) 19 @commits = @project.commits(@ref, params[:path], @limit, @offset)
  20 + @commits = CommitDecorator.decorate(@commits)
20 21
21 respond_to do |format| 22 respond_to do |format|
22 format.html # index.html.erb 23 format.html # index.html.erb
app/controllers/merge_requests_controller.rb
@@ -143,5 +143,6 @@ class MergeRequestsController < ApplicationController @@ -143,5 +143,6 @@ class MergeRequestsController < ApplicationController
143 # Get commits from repository 143 # Get commits from repository
144 # or from cache if already merged 144 # or from cache if already merged
145 @commits = @merge_request.commits 145 @commits = @merge_request.commits
  146 + @commits = CommitDecorator.decorate(@commits)
146 end 147 end
147 end 148 end
app/controllers/refs_controller.rb
@@ -51,7 +51,8 @@ class RefsController < ApplicationController @@ -51,7 +51,8 @@ class RefsController < ApplicationController
51 @logs = contents.map do |content| 51 @logs = contents.map do |content|
52 file = params[:path] ? File.join(params[:path], content.name) : content.name 52 file = params[:path] ? File.join(params[:path], content.name) : content.name
53 last_commit = @project.commits(@commit.id, file, 1).last 53 last_commit = @project.commits(@commit.id, file, 1).last
54 - { 54 + last_commit = CommitDecorator.decorate(last_commit)
  55 + {
55 :file_name => content.name, 56 :file_name => content.name,
56 :commit => last_commit 57 :commit => last_commit
57 } 58 }
app/decorators/commit_decorator.rb
1 class CommitDecorator < ApplicationDecorator 1 class CommitDecorator < ApplicationDecorator
2 decorates :commit 2 decorates :commit
3 3
  4 + def short_id(length = 10)
  5 + id.to_s[0..length]
  6 + end
  7 +
4 # Returns the commits title. 8 # Returns the commits title.
5 # 9 #
6 # Usually, the commit title is the first line of the commit message. 10 # Usually, the commit title is the first line of the commit message.
app/views/commits/_commit.html.haml
@@ -4,11 +4,11 @@ @@ -4,11 +4,11 @@
4 %strong= link_to "Browse Code »", tree_project_ref_path(@project, commit.id), :class => "right" 4 %strong= link_to "Browse Code »", tree_project_ref_path(@project, commit.id), :class => "right"
5 = link_to project_commit_path(@project, :id => commit.id) do 5 = link_to project_commit_path(@project, :id => commit.id) do
6 %p 6 %p
7 - %code.left= commit.id.to_s[0..10] 7 + %code.left= commit.short_id
8 %strong.cgray= commit.author_name 8 %strong.cgray= commit.author_name
9 &ndash; 9 &ndash;
10 = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 10 = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16
11 - %span.row_title= truncate(commit.safe_message, :length => 50) 11 + %span.row_title= truncate(commit.title, :length => 50)
12 12
13 %span.committed_ago 13 %span.committed_ago
14 = time_ago_in_words(commit.committed_date) 14 = time_ago_in_words(commit.committed_date)
app/views/commits/index.atom.builder
@@ -10,14 +10,14 @@ xml.feed &quot;xmlns&quot; =&gt; &quot;http://www.w3.org/2005/Atom&quot;, &quot;xmlns:media&quot; =&gt; &quot;http://sear @@ -10,14 +10,14 @@ xml.feed &quot;xmlns&quot; =&gt; &quot;http://www.w3.org/2005/Atom&quot;, &quot;xmlns:media&quot; =&gt; &quot;http://sear
10 xml.entry do 10 xml.entry do
11 xml.id project_commit_url(@project, :id => commit.id) 11 xml.id project_commit_url(@project, :id => commit.id)
12 xml.link :href => project_commit_url(@project, :id => commit.id) 12 xml.link :href => project_commit_url(@project, :id => commit.id)
13 - xml.title truncate(commit.safe_message, :length => 80) 13 + xml.title truncate(commit.title, :length => 80)
14 xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ") 14 xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ")
15 xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email) 15 xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email)
16 xml.author do |author| 16 xml.author do |author|
17 xml.name commit.author_name 17 xml.name commit.author_name
18 xml.email commit.author_email 18 xml.email commit.author_email
19 end 19 end
20 - xml.summary commit.safe_message 20 + xml.summary commit.description
21 end 21 end
22 end 22 end
23 end 23 end
app/views/events/_commit.html.haml
  1 +- commit = CommitDecorator.decorate(commit)
1 %li.wll.commit 2 %li.wll.commit
2 = link_to project_commit_path(project, :id => commit.id) do 3 = link_to project_commit_path(project, :id => commit.id) do
3 %p 4 %p
4 - %code.left= commit.id.to_s[0..10] 5 + %code.left= commit.short_id
5 %strong.cgray= commit.author_name 6 %strong.cgray= commit.author_name
6 &ndash; 7 &ndash;
7 = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 8 = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16
8 - %span.row_title= truncate(commit.safe_message, :length => 50) rescue "--broken encoding" 9 + %span.row_title= truncate(commit.title, :length => 50) rescue "--broken encoding"
9 10
app/views/refs/_tree_commit.html.haml
1 - if tm 1 - if tm
2 %strong= link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) 2 %strong= link_to "[#{tm.user_name}]", project_team_member_path(@project, tm)
3 -= link_to truncate(content_commit.safe_message, :length => tm ? 30 : 50), project_commit_path(@project, content_commit.id), :class => "tree-commit-link" 3 += link_to truncate(content_commit.title, :length => tm ? 30 : 50), project_commit_path(@project, content_commit.id), :class => "tree-commit-link"
app/views/refs/blame.html.haml
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 %table 25 %table
26 - @blame.each do |commit, lines| 26 - @blame.each do |commit, lines|
27 - commit = Commit.new(commit) 27 - commit = Commit.new(commit)
  28 + - commit = CommitDecorator.decorate(commit)
28 %tr 29 %tr
29 %td.author 30 %td.author
30 = image_tag gravatar_icon(commit.author_email, 16) 31 = image_tag gravatar_icon(commit.author_email, 16)
@@ -32,8 +33,8 @@ @@ -32,8 +33,8 @@
32 %td.blame_commit 33 %td.blame_commit
33 &nbsp; 34 &nbsp;
34 = link_to project_commit_path(@project, :id => commit.id) do 35 = link_to project_commit_path(@project, :id => commit.id) do
35 - %code= commit.id.to_s[0..10]  
36 - %span.row_title= truncate(commit.safe_message, :length => 30) rescue "--broken encoding" 36 + %code= commit.short_id
  37 + %span.row_title= truncate(commit.title, :length => 30) rescue "--broken encoding"
37 %td.lines 38 %td.lines
38 = preserve do 39 = preserve do
39 %pre 40 %pre
app/views/repositories/_branch.html.haml
  1 +- commit = Commit.new(branch.commit)
  2 +- commit = CommitDecorator.decorate(commit)
1 %tr 3 %tr
2 %td 4 %td
3 = link_to project_commits_path(@project, :ref => branch.name) do 5 = link_to project_commits_path(@project, :ref => branch.name) do
@@ -5,14 +7,14 @@ @@ -5,14 +7,14 @@
5 - if branch.name == @project.root_ref 7 - if branch.name == @project.root_ref
6 %span.label default 8 %span.label default
7 %td 9 %td
8 - = link_to project_commit_path(@project, :id => branch.commit.id) do  
9 - %code= branch.commit.id.to_s[0..10] 10 + = link_to project_commit_path(@project, :id => commit.id) do
  11 + %code= commit.short_id
10 12
11 - = image_tag gravatar_icon(Commit.new(branch.commit).author_email), :class => "", :width => 16  
12 - = truncate(Commit.new(branch.commit).safe_message, :length => 40) 13 + = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16
  14 + = truncate(commit.title, :length => 40)
13 %td 15 %td
14 %span.update-author.right 16 %span.update-author.right
15 - = time_ago_in_words(branch.commit.committed_date) 17 + = time_ago_in_words(commit.committed_date)
16 ago 18 ago
17 %td 19 %td
18 - if can? current_user, :download_code, @project 20 - if can? current_user, :download_code, @project
app/views/repositories/_feed.html.haml
1 - commit = update 1 - commit = update
  2 +- commit = CommitDecorator.new(commit)
2 %tr 3 %tr
3 %td 4 %td
4 = link_to project_commits_path(@project, :ref => commit.head.name) do 5 = link_to project_commits_path(@project, :ref => commit.head.name) do
@@ -10,9 +11,9 @@ @@ -10,9 +11,9 @@
10 %td 11 %td
11 %div 12 %div
12 = link_to project_commits_path(@project, commit.id) do 13 = link_to project_commits_path(@project, commit.id) do
13 - %code= commit.id.to_s[0..10] 14 + %code= commit.short_id
14 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 15 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16
15 - = truncate(commit.safe_message, :length => 40) 16 + = truncate(commit.title, :length => 40)
16 %td 17 %td
17 %span.right.cgray 18 %span.right.cgray
18 = time_ago_in_words(commit.committed_date) 19 = time_ago_in_words(commit.committed_date)
app/views/repositories/tags.html.haml
@@ -9,14 +9,15 @@ @@ -9,14 +9,15 @@
9 %th 9 %th
10 - @tags.each do |tag| 10 - @tags.each do |tag|
11 - commit = Commit.new(tag.commit) 11 - commit = Commit.new(tag.commit)
  12 + - commit = CommitDecorator.decorate(commit)
12 %tr 13 %tr
13 %td 14 %td
14 %strong= link_to tag.name, project_commits_path(@project, :ref => tag.name), :class => "" 15 %strong= link_to tag.name, project_commits_path(@project, :ref => tag.name), :class => ""
15 %td 16 %td
16 = link_to project_commit_path(@project, commit.id) do 17 = link_to project_commit_path(@project, commit.id) do
17 - %code= commit.id.to_s[0..10] 18 + %code= commit.short_id
18 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 19 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16
19 - = truncate(commit.safe_message, :length => 40) 20 + = truncate(commit.title, :length => 40)
20 %td 21 %td
21 %span.update-author.right 22 %span.update-author.right
22 = time_ago_in_words(commit.committed_date) 23 = time_ago_in_words(commit.committed_date)
spec/requests/commits_spec.rb
@@ -2,7 +2,7 @@ require &#39;spec_helper&#39; @@ -2,7 +2,7 @@ require &#39;spec_helper&#39;
2 2
3 describe "Commits" do 3 describe "Commits" do
4 let(:project) { Factory :project } 4 let(:project) { Factory :project }
5 - let!(:commit) { project.commit } 5 + let!(:commit) { CommitDecorator.decorate(project.commit) }
6 before do 6 before do
7 login_as :user 7 login_as :user
8 project.add_access(@user, :read) 8 project.add_access(@user, :read)
@@ -22,8 +22,8 @@ describe &quot;Commits&quot; do @@ -22,8 +22,8 @@ describe &quot;Commits&quot; do
22 end 22 end
23 23
24 it "should list commits" do 24 it "should list commits" do
25 - page.should have_content(commit.message)  
26 - page.should have_content(commit.id.to_s[0..5]) 25 + page.should have_content(commit.description)
  26 + page.should have_content(commit.short_id)
27 end 27 end
28 28
29 it "should render atom feed" do 29 it "should render atom feed" do
@@ -32,7 +32,7 @@ describe &quot;Commits&quot; do @@ -32,7 +32,7 @@ describe &quot;Commits&quot; do
32 page.response_headers['Content-Type'].should have_content("application/atom+xml") 32 page.response_headers['Content-Type'].should have_content("application/atom+xml")
33 page.body.should have_selector("title", :text => "Recent commits to #{project.name}") 33 page.body.should have_selector("title", :text => "Recent commits to #{project.name}")
34 page.body.should have_selector("author email", :text => commit.author_email) 34 page.body.should have_selector("author email", :text => commit.author_email)
35 - page.body.should have_selector("entry summary", :text => commit.message) 35 + page.body.should have_selector("entry summary", :text => commit.description)
36 end 36 end
37 37
38 it "should render atom feed via private token" do 38 it "should render atom feed via private token" do
@@ -42,7 +42,7 @@ describe &quot;Commits&quot; do @@ -42,7 +42,7 @@ describe &quot;Commits&quot; do
42 page.response_headers['Content-Type'].should have_content("application/atom+xml") 42 page.response_headers['Content-Type'].should have_content("application/atom+xml")
43 page.body.should have_selector("title", :text => "Recent commits to #{project.name}") 43 page.body.should have_selector("title", :text => "Recent commits to #{project.name}")
44 page.body.should have_selector("author email", :text => commit.author_email) 44 page.body.should have_selector("author email", :text => commit.author_email)
45 - page.body.should have_selector("entry summary", :text => commit.message) 45 + page.body.should have_selector("entry summary", :text => commit.description)
46 end 46 end
47 end 47 end
48 48