diff --git a/app/models/comment.rb b/app/models/comment.rb index 88913e613..8386e45c3 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -22,9 +22,7 @@ class Comment < ActiveRecord::Base attr_accessible :body, :data def commentable - # raise commentable_id.inspect - # raise commentable_id.to_s(16).inspect - commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super # TODO leading zero problem + commit_comment? ? project.repo.commit(Comment.hex_to_commit_hash commentable_id) : super # TODO leading zero problem end def commentable=(c) @@ -185,6 +183,11 @@ class Comment < ActiveRecord::Base end end + def self.hex_to_commit_hash hex + t = hex.to_s(16) + '0'*(40-t.length) << t + end + protected def subscribe_on_reply diff --git a/app/presenters/git_presenters/commit_as_message_presenter.rb b/app/presenters/git_presenters/commit_as_message_presenter.rb index a982e46c8..b44f31478 100644 --- a/app/presenters/git_presenters/commit_as_message_presenter.rb +++ b/app/presenters/git_presenters/commit_as_message_presenter.rb @@ -14,7 +14,7 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter else opts[:project] end - commit = commit || @project.repo.commit(comment.created_from_commit_hash.to_s(16)) if @project + commit = commit || @project.repo.commit(Comment.hex_to_commit_hash comment.created_from_commit_hash) if @project if @project && commit @committer = User.where(:email => commit.committer.email).first || commit.committer @@ -23,7 +23,7 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter @commit_message = commit.message else @committer = t('layout.commits.unknown_committer') - @commit_hash = comment.created_from_commit_hash.to_s(16) + @commit_hash = Comment.hex_to_commit_hash comment.created_from_commit_hash @committed_date = @authored_date = comment.created_at @commit_message = t('layout.commits.deleted') end