diff --git a/app/models/comment.rb b/app/models/comment.rb index d46d9198e..a1b30c760 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -151,20 +151,23 @@ class Comment < ActiveRecord::Base project_name = Regexp.last_match[2].presence || item.project.name serial_id = Regexp.last_match[3] project = Project.find_by_owner_and_name(owner_uname.chomp('/'), project_name) - #raise "hash = #{hash}; owner_uname = #{owner_uname}; project_name = #{project_name}; serial_id = #{serial_id}" + next unless project next unless Ability.new(item.user).can? :read, project issue = project.issues.where(:serial_id => serial_id).first next unless issue next if issue == item.try(:commentable) # dont create link to the same issue + # dont create duplicate link to issue + next if item.is_a? Comment && Comment.exists?(:automatic => true, :created_from_issue_id => item.commentable_id) comment = linker.comments.new :body => 'automatic comment' comment.commentable, comment.project, comment.automatic = issue, project, true if item.is_a? Comment comment.data = {:issue_serial_id => item.commentable.serial_id, :comment_id => item.id} + comment.created_from_issue_id = item.commentable_id elsif item.is_a? GitHook repo_commit = git_hook.project.repo.commit element[0] next unless repo_commit - comment.data = {:commit_hash => commit[0]} + comment.data = {commit_hash => commit[0]} end comment.data.merge! :from_project_id => item.project.id comment.save diff --git a/app/presenters/comment_presenter.rb b/app/presenters/comment_presenter.rb index f5d0b377c..58390d434 100644 --- a/app/presenters/comment_presenter.rb +++ b/app/presenters/comment_presenter.rb @@ -14,7 +14,7 @@ class CommentPresenter < ApplicationPresenter else issue = Issue.where(:project_id => comment.data[:from_project_id], :serial_id => comment.data[:issue_serial_id]).first @referenced_issue = issue.pull_request || issue - if issue + if issue && Comment.exists?(comment.data[:comment_id]) title = if issue == opts[:commentable] "#{issue.serial_id}" elsif issue.project.owner == opts[:commentable].project.owner diff --git a/db/migrate/20130326165628_add_add_info_to_comments.rb b/db/migrate/20130326165628_add_add_info_to_comments.rb new file mode 100644 index 000000000..a7821f461 --- /dev/null +++ b/db/migrate/20130326165628_add_add_info_to_comments.rb @@ -0,0 +1,8 @@ +class AddAddInfoToComments < ActiveRecord::Migration + def change + add_column :comments, :created_from_commit_hash, :decimal, :precision => 50, :scale => 0 + add_column :comments, :created_from_issue_id, :integer + + add_index :comments, :created_from_issue_id + end +end diff --git a/db/schema.rb b/db/schema.rb index db168e24f..b26fff00f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130319172358) do +ActiveRecord::Schema.define(:version => 20130326165628) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -151,15 +151,20 @@ ActiveRecord::Schema.define(:version => 20130319172358) do t.text "body" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false - t.decimal "commentable_id", :precision => 50, :scale => 0 + t.datetime "created_at" + t.datetime "updated_at" + t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" t.text "data" - t.boolean "automatic", :default => false + t.boolean "automatic", :default => false + t.decimal "created_from_commit_hash", :precision => 50, :scale => 0 + t.integer "created_from_issue_id" end add_index "comments", ["automatic"], :name => "index_comments_on_automatic" add_index "comments", ["commentable_id"], :name => "index_comments_on_commentable_id" add_index "comments", ["commentable_type"], :name => "index_comments_on_commentable_type" + add_index "comments", ["created_from_issue_id"], :name => "index_comments_on_created_from_issue_id" create_table "event_logs", :force => true do |t| t.integer "user_id"