[#19] some fixes to issue link

This commit is contained in:
Alexander Machehin 2013-03-26 23:51:32 +06:00
parent 8d5cad3ee1
commit e6e6b50aa6
4 changed files with 22 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.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.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"