From ff40b7de7a6451bb9e3bc12a18070bbff13b6a68 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 21 Jul 2012 19:37:31 +0200 Subject: [PATCH 1/3] Add CommitDecorator#short_id --- app/decorators/commit_decorator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/decorators/commit_decorator.rb b/app/decorators/commit_decorator.rb index cc8fa975..d9c880be 100644 --- a/app/decorators/commit_decorator.rb +++ b/app/decorators/commit_decorator.rb @@ -1,6 +1,10 @@ class CommitDecorator < ApplicationDecorator decorates :commit + def short_id(length = 10) + id.to_s[0..length] + end + # Returns the commits title. # # Usually, the commit title is the first line of the commit message. From 34cea1cb632c907ae399df64c60e93a5c716eeca Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 22 Jul 2012 13:08:24 +0200 Subject: [PATCH 2/3] Update views to use CommitDecorator --- app/controllers/commits_controller.rb | 1 + app/controllers/merge_requests_controller.rb | 1 + app/controllers/refs_controller.rb | 3 ++- app/views/commits/_commit.html.haml | 4 ++-- app/views/commits/index.atom.builder | 4 ++-- app/views/events/_commit.html.haml | 5 +++-- app/views/refs/_tree_commit.html.haml | 2 +- app/views/refs/blame.html.haml | 5 +++-- app/views/repositories/_branch.html.haml | 12 +++++++----- app/views/repositories/_feed.html.haml | 5 +++-- app/views/repositories/tags.html.haml | 5 +++-- 11 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index cb1f7452..a8540569 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -17,6 +17,7 @@ class CommitsController < ApplicationController @limit, @offset = (params[:limit] || 40), (params[:offset] || 0) @commits = @project.commits(@ref, params[:path], @limit, @offset) + @commits = CommitDecorator.decorate(@commits) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index 1cb1d388..f9a1c1dd 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -143,5 +143,6 @@ class MergeRequestsController < ApplicationController # Get commits from repository # or from cache if already merged @commits = @merge_request.commits + @commits = CommitDecorator.decorate(@commits) end end diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index b610c9f3..d180e708 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -51,7 +51,8 @@ class RefsController < ApplicationController @logs = contents.map do |content| file = params[:path] ? File.join(params[:path], content.name) : content.name last_commit = @project.commits(@commit.id, file, 1).last - { + last_commit = CommitDecorator.decorate(last_commit) + { :file_name => content.name, :commit => last_commit } diff --git a/app/views/commits/_commit.html.haml b/app/views/commits/_commit.html.haml index 9f9502e3..c77e22d9 100644 --- a/app/views/commits/_commit.html.haml +++ b/app/views/commits/_commit.html.haml @@ -4,11 +4,11 @@ %strong= link_to "Browse Code ยป", tree_project_ref_path(@project, commit.id), :class => "right" = link_to project_commit_path(@project, :id => commit.id) do %p - %code.left= commit.id.to_s[0..10] + %code.left= commit.short_id %strong.cgray= commit.author_name – = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 - %span.row_title= truncate(commit.safe_message, :length => 50) + %span.row_title= truncate(commit.title, :length => 50) %span.committed_ago = time_ago_in_words(commit.committed_date) diff --git a/app/views/commits/index.atom.builder b/app/views/commits/index.atom.builder index 2a352dac..86c9fc04 100644 --- a/app/views/commits/index.atom.builder +++ b/app/views/commits/index.atom.builder @@ -10,14 +10,14 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear xml.entry do xml.id project_commit_url(@project, :id => commit.id) xml.link :href => project_commit_url(@project, :id => commit.id) - xml.title truncate(commit.safe_message, :length => 80) + xml.title truncate(commit.title, :length => 80) xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ") xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email) xml.author do |author| xml.name commit.author_name xml.email commit.author_email end - xml.summary commit.safe_message + xml.summary commit.description end end end diff --git a/app/views/events/_commit.html.haml b/app/views/events/_commit.html.haml index 60112b50..b26b8f0a 100644 --- a/app/views/events/_commit.html.haml +++ b/app/views/events/_commit.html.haml @@ -1,9 +1,10 @@ +- commit = CommitDecorator.decorate(commit) %li.wll.commit = link_to project_commit_path(project, :id => commit.id) do %p - %code.left= commit.id.to_s[0..10] + %code.left= commit.short_id %strong.cgray= commit.author_name – = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 - %span.row_title= truncate(commit.safe_message, :length => 50) rescue "--broken encoding" + %span.row_title= truncate(commit.title, :length => 50) rescue "--broken encoding" diff --git a/app/views/refs/_tree_commit.html.haml b/app/views/refs/_tree_commit.html.haml index 1f2524a4..7da8ae1c 100644 --- a/app/views/refs/_tree_commit.html.haml +++ b/app/views/refs/_tree_commit.html.haml @@ -1,3 +1,3 @@ - if tm %strong= link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) -= link_to truncate(content_commit.safe_message, :length => tm ? 30 : 50), project_commit_path(@project, content_commit.id), :class => "tree-commit-link" += link_to truncate(content_commit.title, :length => tm ? 30 : 50), project_commit_path(@project, content_commit.id), :class => "tree-commit-link" diff --git a/app/views/refs/blame.html.haml b/app/views/refs/blame.html.haml index 6a86b91f..0f0b6927 100644 --- a/app/views/refs/blame.html.haml +++ b/app/views/refs/blame.html.haml @@ -25,6 +25,7 @@ %table - @blame.each do |commit, lines| - commit = Commit.new(commit) + - commit = CommitDecorator.decorate(commit) %tr %td.author = image_tag gravatar_icon(commit.author_email, 16) @@ -32,8 +33,8 @@ %td.blame_commit   = link_to project_commit_path(@project, :id => commit.id) do - %code= commit.id.to_s[0..10] - %span.row_title= truncate(commit.safe_message, :length => 30) rescue "--broken encoding" + %code= commit.short_id + %span.row_title= truncate(commit.title, :length => 30) rescue "--broken encoding" %td.lines = preserve do %pre diff --git a/app/views/repositories/_branch.html.haml b/app/views/repositories/_branch.html.haml index 4742b92b..3efe83ec 100644 --- a/app/views/repositories/_branch.html.haml +++ b/app/views/repositories/_branch.html.haml @@ -1,3 +1,5 @@ +- commit = Commit.new(branch.commit) +- commit = CommitDecorator.decorate(commit) %tr %td = link_to project_commits_path(@project, :ref => branch.name) do @@ -5,14 +7,14 @@ - if branch.name == @project.root_ref %span.label default %td - = link_to project_commit_path(@project, :id => branch.commit.id) do - %code= branch.commit.id.to_s[0..10] + = link_to project_commit_path(@project, :id => commit.id) do + %code= commit.short_id - = image_tag gravatar_icon(Commit.new(branch.commit).author_email), :class => "", :width => 16 - = truncate(Commit.new(branch.commit).safe_message, :length => 40) + = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 + = truncate(commit.title, :length => 40) %td %span.update-author.right - = time_ago_in_words(branch.commit.committed_date) + = time_ago_in_words(commit.committed_date) ago %td - if can? current_user, :download_code, @project diff --git a/app/views/repositories/_feed.html.haml b/app/views/repositories/_feed.html.haml index 07343272..a9a11819 100644 --- a/app/views/repositories/_feed.html.haml +++ b/app/views/repositories/_feed.html.haml @@ -1,4 +1,5 @@ - commit = update +- commit = CommitDecorator.new(commit) %tr %td = link_to project_commits_path(@project, :ref => commit.head.name) do @@ -10,9 +11,9 @@ %td %div = link_to project_commits_path(@project, commit.id) do - %code= commit.id.to_s[0..10] + %code= commit.short_id = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 - = truncate(commit.safe_message, :length => 40) + = truncate(commit.title, :length => 40) %td %span.right.cgray = time_ago_in_words(commit.committed_date) diff --git a/app/views/repositories/tags.html.haml b/app/views/repositories/tags.html.haml index 5e5cca31..d09c40e1 100644 --- a/app/views/repositories/tags.html.haml +++ b/app/views/repositories/tags.html.haml @@ -9,14 +9,15 @@ %th - @tags.each do |tag| - commit = Commit.new(tag.commit) + - commit = CommitDecorator.decorate(commit) %tr %td %strong= link_to tag.name, project_commits_path(@project, :ref => tag.name), :class => "" %td = link_to project_commit_path(@project, commit.id) do - %code= commit.id.to_s[0..10] + %code= commit.short_id = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 - = truncate(commit.safe_message, :length => 40) + = truncate(commit.title, :length => 40) %td %span.update-author.right = time_ago_in_words(commit.committed_date) From f9877c529eb6864dbf4b21ef6ddd2ab48159f1b3 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 22 Jul 2012 13:08:32 +0200 Subject: [PATCH 3/3] Update specs --- spec/requests/commits_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/requests/commits_spec.rb b/spec/requests/commits_spec.rb index 00b69379..0418697e 100644 --- a/spec/requests/commits_spec.rb +++ b/spec/requests/commits_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "Commits" do let(:project) { Factory :project } - let!(:commit) { project.commit } + let!(:commit) { CommitDecorator.decorate(project.commit) } before do login_as :user project.add_access(@user, :read) @@ -22,8 +22,8 @@ describe "Commits" do end it "should list commits" do - page.should have_content(commit.message) - page.should have_content(commit.id.to_s[0..5]) + page.should have_content(commit.description) + page.should have_content(commit.short_id) end it "should render atom feed" do @@ -32,7 +32,7 @@ describe "Commits" do page.response_headers['Content-Type'].should have_content("application/atom+xml") page.body.should have_selector("title", :text => "Recent commits to #{project.name}") page.body.should have_selector("author email", :text => commit.author_email) - page.body.should have_selector("entry summary", :text => commit.message) + page.body.should have_selector("entry summary", :text => commit.description) end it "should render atom feed via private token" do @@ -42,7 +42,7 @@ describe "Commits" do page.response_headers['Content-Type'].should have_content("application/atom+xml") page.body.should have_selector("title", :text => "Recent commits to #{project.name}") page.body.should have_selector("author email", :text => commit.author_email) - page.body.should have_selector("entry summary", :text => commit.message) + page.body.should have_selector("entry summary", :text => commit.description) end end