Merge pull request #193 from abf/rosa-build:fix_creating_autocomments_from_commit

fix creating autolinks from commits
This commit is contained in:
avokhmin 2013-06-20 12:16:44 +04:00
commit 5d53b40262
2 changed files with 6 additions and 7 deletions

View File

@ -96,17 +96,18 @@ class ActivityFeedObserver < ActiveRecord::Observer
last_commits, commits = [[record.newrev, record.message]], []
else
commits = record.project.repo.commits_between(record.oldrev, record.newrev)
last_commits = commits.last(3).collect { |commit| [commit.sha, commit.message] }
all_commits = commits.collect { |commit| [commit.sha, commit.message] }
last_commits = all_commits.last(3).reverse
end
kind = 'git_new_push_notification'
options = {:project_id => record.project.id, :project_name => record.project.name, :last_commits => last_commits.reverse,
options = {:project_id => record.project.id, :project_name => record.project.name, :last_commits => last_commits,
:branch_name => branch_name, :change_type => change_type, :project_owner => record.project.owner.uname}
if commits.count > 3
commits = commits[0...-3]
options.merge!({:other_commits_count => commits.count, :other_commits => "#{commits[0].sha[0..9]}...#{commits[-1].sha[0..9]}"})
end
Comment.create_link_on_issues_from_item(record, last_commits) if last_commits.count > 0
Comment.create_link_on_issues_from_item(record, all_commits) if all_commits.count > 0
end
options.merge!({:user_id => record.user.id, :user_name => record.user.name, :user_email => record.user.email}) if record.user

View File

@ -160,13 +160,11 @@ class Comment < ActiveRecord::Base
next unless issue
# dont create link to the same issue
next if opts[:created_from_issue_id] == issue.id
opts = {:created_from_commit_hash => element[0].hex} if item.is_a?(GitHook)
# dont create duplicate link to issue
next if Comment.find_existing_automatic_comment issue, opts
if item.is_a?(GitHook)
opts = {:created_from_commit_hash => element[0].hex}
# dont create link to outdated commit
next if !item.project.repo.commit(element[0])
end
next if item.is_a?(GitHook) && !item.project.repo.commit(element[0])
comment = linker.comments.new :body => 'automatic comment'
comment.commentable, comment.project, comment.automatic = issue, issue.project, true
comment.data = {:from_project_id => item.project.id}