summaryrefslogtreecommitdiffstats
path: root/app/models/changeset.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-02-06 20:02:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-02-06 20:02:30 +0000
commitc80c1e1eada561326d36f2c0d115eb9ea76d16dd (patch)
tree026052bf5aabd9568ddbe3424ff2988c500a6a09 /app/models/changeset.rb
parent943ba3e34fed6d82f79a737e043c408746ab392a (diff)
downloadredmine-c80c1e1eada561326d36f2c0d115eb9ea76d16dd.tar.gz
redmine-c80c1e1eada561326d36f2c0d115eb9ea76d16dd.zip
Create a journal and send an email when an issue is closed by commit (#609).
The redmine user is found using the committer username or email. Otherwise, the journal is created with anonymous user. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1126 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/changeset.rb')
-rw-r--r--app/models/changeset.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 1b79104c4..3703ab927 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -48,6 +48,7 @@ class Changeset < ActiveRecord::Base
def after_create
scan_comment_for_issue_ids
end
+ require 'pp'
def scan_comment_for_issue_ids
return if comments.blank?
@@ -79,11 +80,14 @@ class Changeset < ActiveRecord::Base
# update status of issues
logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
target_issues.each do |issue|
- # don't change the status is the issue is already closed
+ # don't change the status is the issue is closed
next if issue.status.is_closed?
+ user = committer_user || User.anonymous
+ journal = issue.init_journal(user, l(:text_status_changed_by_changeset, "r#{self.revision}"))
issue.status = fix_status
issue.done_ratio = done_ratio if done_ratio
issue.save
+ Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
end
end
referenced_issues += target_issues
@@ -92,6 +96,16 @@ class Changeset < ActiveRecord::Base
self.issues = referenced_issues.uniq
end
+ # Returns the Redmine User corresponding to the committer
+ def committer_user
+ if committer && committer.strip =~ /^([^<]+)(<(.*)>)?$/
+ username, email = $1.strip, $3
+ u = User.find_by_login(username)
+ u ||= User.find_by_mail(email) unless email.blank?
+ u
+ end
+ end
+
# Returns the previous changeset
def previous
@previous ||= Changeset.find(:first, :conditions => ['revision < ? AND repository_id = ?', self.revision, self.repository_id], :order => 'revision DESC')