Commit message parser:

* Fixed: Error when parsing a commit message with duplicate issue identifiers
* Strip referencing and fixing keywords

git-svn-id: http://redmine.rubyforge.org/svn/trunk@861 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-10-22 16:52:36 +00:00
parent cedca57620
commit b30b6717a2
3 changed files with 9 additions and 8 deletions

View File

@ -52,19 +52,17 @@ class Changeset < ActiveRecord::Base
def scan_comment_for_issue_ids def scan_comment_for_issue_ids
return if comments.blank? return if comments.blank?
# keywords used to reference issues # keywords used to reference issues
ref_keywords = Setting.commit_ref_keywords.downcase.split(",") ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
# keywords used to fix issues # keywords used to fix issues
fix_keywords = Setting.commit_fix_keywords.downcase.split(",") fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
# status and optional done ratio applied # status and optional done ratio applied
fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id) fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw.strip)}.join("|") kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
return if kw_regexp.blank? return if kw_regexp.blank?
# remove any associated issues referenced_issues = []
self.issues.clear
comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match| comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
action = match[0] action = match[0]
target_issue_ids = match[1].scan(/\d+/) target_issue_ids = match[1].scan(/\d+/)
@ -80,7 +78,8 @@ class Changeset < ActiveRecord::Base
issue.save issue.save
end end
end end
self.issues << target_issues referenced_issues += target_issues
end end
self.issues = referenced_issues.uniq
end end
end end

View File

@ -12,7 +12,7 @@ changesets_002:
committed_on: 2007-04-12 15:14:44 +02:00 committed_on: 2007-04-12 15:14:44 +02:00
revision: 2 revision: 2
id: 101 id: 101
comments: 'This commit fixes #1, #2 and references #3' comments: 'This commit fixes #1, #2 and references #1 & #3'
repository_id: 10 repository_id: 10
committer: dlopper committer: dlopper
changesets_003: changesets_003:

View File

@ -40,6 +40,8 @@ class RepositoryTest < Test::Unit::TestCase
# choosing a status to apply to fix issues # choosing a status to apply to fix issues
Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
Setting.commit_fix_done_ratio = "90" Setting.commit_fix_done_ratio = "90"
Setting.commit_ref_keywords = 'refs , references, IssueID'
Setting.commit_fix_keywords = 'fixes , closes'
# make sure issue 1 is not already closed # make sure issue 1 is not already closed
assert !Issue.find(1).status.is_closed? assert !Issue.find(1).status.is_closed?