[#19] some fixes to issue link
This commit is contained in:
parent
8d5cad3ee1
commit
e6e6b50aa6
|
@ -151,20 +151,23 @@ class Comment < ActiveRecord::Base
|
||||||
project_name = Regexp.last_match[2].presence || item.project.name
|
project_name = Regexp.last_match[2].presence || item.project.name
|
||||||
serial_id = Regexp.last_match[3]
|
serial_id = Regexp.last_match[3]
|
||||||
project = Project.find_by_owner_and_name(owner_uname.chomp('/'), project_name)
|
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 project
|
||||||
next unless Ability.new(item.user).can? :read, project
|
next unless Ability.new(item.user).can? :read, project
|
||||||
issue = project.issues.where(:serial_id => serial_id).first
|
issue = project.issues.where(:serial_id => serial_id).first
|
||||||
next unless issue
|
next unless issue
|
||||||
next if issue == item.try(:commentable) # dont create link to the same 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 = linker.comments.new :body => 'automatic comment'
|
||||||
comment.commentable, comment.project, comment.automatic = issue, project, true
|
comment.commentable, comment.project, comment.automatic = issue, project, true
|
||||||
if item.is_a? Comment
|
if item.is_a? Comment
|
||||||
comment.data = {:issue_serial_id => item.commentable.serial_id, :comment_id => item.id}
|
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
|
elsif item.is_a? GitHook
|
||||||
repo_commit = git_hook.project.repo.commit element[0]
|
repo_commit = git_hook.project.repo.commit element[0]
|
||||||
next unless repo_commit
|
next unless repo_commit
|
||||||
comment.data = {:commit_hash => commit[0]}
|
comment.data = {commit_hash => commit[0]}
|
||||||
end
|
end
|
||||||
comment.data.merge! :from_project_id => item.project.id
|
comment.data.merge! :from_project_id => item.project.id
|
||||||
comment.save
|
comment.save
|
||||||
|
|
|
@ -14,7 +14,7 @@ class CommentPresenter < ApplicationPresenter
|
||||||
else
|
else
|
||||||
issue = Issue.where(:project_id => comment.data[:from_project_id], :serial_id => comment.data[:issue_serial_id]).first
|
issue = Issue.where(:project_id => comment.data[:from_project_id], :serial_id => comment.data[:issue_serial_id]).first
|
||||||
@referenced_issue = issue.pull_request || issue
|
@referenced_issue = issue.pull_request || issue
|
||||||
if issue
|
if issue && Comment.exists?(comment.data[:comment_id])
|
||||||
title = if issue == opts[:commentable]
|
title = if issue == opts[:commentable]
|
||||||
"#{issue.serial_id}"
|
"#{issue.serial_id}"
|
||||||
elsif issue.project.owner == opts[:commentable].project.owner
|
elsif issue.project.owner == opts[:commentable].project.owner
|
||||||
|
|
|
@ -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
|
11
db/schema.rb
11
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# 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|
|
create_table "activity_feeds", :force => true do |t|
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
|
@ -151,15 +151,20 @@ ActiveRecord::Schema.define(:version => 20130319172358) do
|
||||||
t.text "body"
|
t.text "body"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_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.integer "project_id"
|
||||||
t.text "data"
|
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
|
end
|
||||||
|
|
||||||
add_index "comments", ["automatic"], :name => "index_comments_on_automatic"
|
add_index "comments", ["automatic"], :name => "index_comments_on_automatic"
|
||||||
add_index "comments", ["commentable_id"], :name => "index_comments_on_commentable_id"
|
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", ["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|
|
create_table "event_logs", :force => true do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
|
|
Loading…
Reference in New Issue