From c80c1e1eada561326d36f2c0d115eb9ea76d16dd Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 6 Feb 2008 20:02:30 +0000 Subject: [PATCH] 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 --- app/models/changeset.rb | 16 +++++++++++++++- lang/bg.yml | 1 + lang/cs.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fi.yml | 1 + lang/fr.yml | 1 + lang/he.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/ko.yml | 1 + lang/lt.yml | 1 + lang/nl.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 1 + lang/ru.yml | 1 + lang/sr.yml | 1 + lang/sv.yml | 1 + lang/zh-tw.yml | 1 + lang/zh.yml | 1 + test/unit/repository_test.rb | 33 +++++++++++++++++++++++++++++---- 24 files changed, 66 insertions(+), 5 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') diff --git a/lang/bg.yml b/lang/bg.yml index b783df592..6fb1cf6de 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -566,3 +566,4 @@ label_general: Основни label_repository_plural: Хранилища label_associated_revisions: Асоциирани ревизии setting_user_format: Потребителски формат +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/cs.yml b/lang/cs.yml index cec7d2a31..894568f20 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -566,3 +566,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/de.yml b/lang/de.yml index a2222af83..668c4333c 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -566,3 +566,4 @@ default_activity_development: Entwicklung enumeration_issue_priorities: Ticket-Prioritäten enumeration_doc_categories: Dokumentenkategorien enumeration_activities: Aktivitäten (Zeiterfassung) +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/en.yml b/lang/en.yml index 8c54e1c79..c056c6ce5 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -540,6 +540,7 @@ text_issue_category_reassign_to: Reassign issues to this category text_user_mail_option: "For unselected projects, you will only receive notifications about things you watch or you're involved in (eg. issues you're the author or assignee)." text_no_configuration_data: "Roles, trackers, issue statuses and workflow have not been configured yet.\nIt is highly recommended to load the default configuration. You will be able to modify it once loaded." text_load_default_configuration: Load the default configuration +text_status_changed_by_changeset: Applied in changeset %s. default_role_manager: Manager default_role_developper: Developer diff --git a/lang/es.yml b/lang/es.yml index f8cd9e300..b80d82178 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -569,3 +569,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/fi.yml b/lang/fi.yml index cf04b23b4..3e297932d 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -570,3 +570,4 @@ enumeration_doc_categories: Dokumentin luokat enumeration_activities: Aktiviteetit (ajan seuranta) label_associated_revisions: Liittyvät versiot setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/fr.yml b/lang/fr.yml index 7df8ec622..ac615f03c 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -541,6 +541,7 @@ text_issue_category_reassign_to: Réaffecter les demandes à cette catégorie text_user_mail_option: "Pour les projets non sélectionnés, vous recevrez seulement des notifications pour ce que vous surveillez ou à quoi vous participez (exemple: demandes dont vous êtes l'auteur ou la personne assignée)." text_no_configuration_data: "Les rôles, trackers, statuts et le workflow ne sont pas encore paramétrés.\nIl est vivement recommandé de charger le paramétrage par defaut. Vous pourrez le modifier une fois chargé." text_load_default_configuration: Charger le paramétrage par défaut +text_status_changed_by_changeset: Appliqué par commit %s. default_role_manager: Manager default_role_developper: Développeur diff --git a/lang/he.yml b/lang/he.yml index 7f26341b8..4063d2fcd 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -566,3 +566,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/it.yml b/lang/it.yml index 7b27a54cb..216a1ada4 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -566,3 +566,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/ja.yml b/lang/ja.yml index 0b3926a23..7607b21de 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -567,3 +567,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/ko.yml b/lang/ko.yml index b9b9542fc..31ac5bf9f 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -566,3 +566,4 @@ label_general: 일반 label_repository_plural: 저장소들 label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/lt.yml b/lang/lt.yml index 6f2965353..3aa86702a 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -567,3 +567,4 @@ label_repository_plural: Saugiklos error_can_t_load_default_data: "Numatytoji konfiguracija negali būti užkrauta: %s" label_associated_revisions: susijusios revizijos setting_user_format: Vartotojo atvaizdavimo formatas +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/nl.yml b/lang/nl.yml index c2d692706..c54273873 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -567,3 +567,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/pl.yml b/lang/pl.yml index 0f99628af..e3fc957b4 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -566,3 +566,4 @@ label_general: Ogólne label_repository_plural: Repozytoria label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 3c6fd1265..ce68c5bac 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -566,3 +566,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/pt.yml b/lang/pt.yml index 3b5647d53..246705599 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -566,3 +566,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/ro.yml b/lang/ro.yml index 2fed755ac..97bb794dd 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -566,3 +566,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/ru.yml b/lang/ru.yml index 44b1664cf..1358b648d 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -567,3 +567,4 @@ default_activity_development: Разработка enumeration_issue_priorities: Приоритеты задач enumeration_doc_categories: Категории документов enumeration_activities: Действия (учет времени) +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/sr.yml b/lang/sr.yml index 3132beeec..e6a268004 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -567,3 +567,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/sv.yml b/lang/sv.yml index b8a9a3a11..da03bf0ba 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -567,3 +567,4 @@ label_general: General label_repository_plural: Repositories label_associated_revisions: Associated revisions setting_user_format: Users display format +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 94631b86d..833e98b00 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -566,3 +566,4 @@ default_activity_development: 開發 enumeration_issue_priorities: 項目重要性 enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (time tracking) +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/lang/zh.yml b/lang/zh.yml index 70ee8b137..cdaeeaa04 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -569,3 +569,4 @@ label_general: 一般 label_repository_plural: 源代码库 label_associated_revisions: 相关的版本 setting_user_format: 用户显示格式 +text_status_changed_by_changeset: Applied in changeset %s. diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 5e0432c60..21fb00b80 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -18,7 +18,16 @@ require File.dirname(__FILE__) + '/../test_helper' class RepositoryTest < Test::Unit::TestCase - fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes + fixtures :projects, + :trackers, + :projects_trackers, + :repositories, + :issues, + :issue_statuses, + :changesets, + :changes, + :users, + :enumerations def setup @repository = Project.find(1).repository @@ -42,19 +51,35 @@ class RepositoryTest < Test::Unit::TestCase Setting.commit_fix_done_ratio = "90" Setting.commit_ref_keywords = 'refs , references, IssueID' Setting.commit_fix_keywords = 'fixes , closes' - + Setting.default_language = 'en' + ActionMailer::Base.deliveries.clear + # make sure issue 1 is not already closed - assert !Issue.find(1).status.is_closed? + fixed_issue = Issue.find(1) + assert !fixed_issue.status.is_closed? + old_status = fixed_issue.status Repository.scan_changesets_for_issue_ids assert_equal [101, 102], Issue.find(3).changeset_ids # fixed issues - fixed_issue = Issue.find(1) + fixed_issue.reload assert fixed_issue.status.is_closed? assert_equal 90, fixed_issue.done_ratio assert_equal [101], fixed_issue.changeset_ids + # issue change + journal = fixed_issue.journals.find(:first, :order => 'created_on desc') + assert_equal User.find_by_login('dlopper'), journal.user + assert_equal 'Applied in changeset r2.', journal.notes + + # 2 email notifications + assert_equal 2, ActionMailer::Base.deliveries.size + mail = ActionMailer::Base.deliveries.first + assert_kind_of TMail::Mail, mail + assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") + assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}") + # ignoring commits referencing an issue of another project assert_equal [], Issue.find(4).changesets end -- 2.39.5