Support for multiple issue update keywords/rules in commit messages (#4911).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12197 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
+8
-13
@@ -118,21 +118,21 @@ class Changeset < ActiveRecord::Base
|
||||
ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
|
||||
ref_keywords_any = ref_keywords.delete('*')
|
||||
# keywords used to fix issues
|
||||
fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
|
||||
fix_keywords = Setting.commit_update_by_keyword.keys
|
||||
|
||||
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
|
||||
|
||||
referenced_issues = []
|
||||
|
||||
comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
|
||||
action, refs = match[2], match[3]
|
||||
action, refs = match[2].to_s.downcase, match[3]
|
||||
next unless action.present? || ref_keywords_any
|
||||
|
||||
refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
|
||||
issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
|
||||
if issue
|
||||
referenced_issues << issue
|
||||
fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
|
||||
fix_issue(issue, action) if fix_keywords.include?(action)
|
||||
log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
|
||||
end
|
||||
end
|
||||
@@ -210,12 +210,10 @@ class Changeset < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def fix_issue(issue)
|
||||
status = IssueStatus.find_by_id(Setting.commit_fix_status_id.to_i)
|
||||
if status.nil?
|
||||
logger.warn("No status matches commit_fix_status_id setting (#{Setting.commit_fix_status_id})") if logger
|
||||
return issue
|
||||
end
|
||||
# Updates the +issue+ according to +action+
|
||||
def fix_issue(issue, action)
|
||||
updates = Setting.commit_update_by_keyword[action]
|
||||
return unless updates.is_a?(Hash)
|
||||
|
||||
# the issue may have been updated by the closure of another one (eg. duplicate)
|
||||
issue.reload
|
||||
@@ -223,10 +221,7 @@ class Changeset < ActiveRecord::Base
|
||||
return if issue.status && issue.status.is_closed?
|
||||
|
||||
journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, text_tag(issue.project)))
|
||||
issue.status = status
|
||||
unless Setting.commit_fix_done_ratio.blank?
|
||||
issue.done_ratio = Setting.commit_fix_done_ratio.to_i
|
||||
end
|
||||
issue.assign_attributes updates.slice(*Issue.attribute_names)
|
||||
Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
|
||||
{ :changeset => self, :issue => issue })
|
||||
unless issue.save
|
||||
|
||||
+73
-1
@@ -132,15 +132,87 @@ class Setting < ActiveRecord::Base
|
||||
def self.#{name}=(value)
|
||||
self[:#{name}] = value
|
||||
end
|
||||
END_SRC
|
||||
END_SRC
|
||||
class_eval src, __FILE__, __LINE__
|
||||
end
|
||||
|
||||
# Sets a setting value from params
|
||||
def self.set_from_params(name, params)
|
||||
params = params.dup
|
||||
params.delete_if {|v| v.blank? } if params.is_a?(Array)
|
||||
|
||||
m = "#{name}_from_params"
|
||||
if respond_to? m
|
||||
self[name.to_sym] = send m, params
|
||||
else
|
||||
self[name.to_sym] = params
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a hash suitable for commit_update_keywords setting
|
||||
#
|
||||
# Example:
|
||||
# params = {:keywords => ['fixes', 'closes'], :status_id => ["3", "5"], :done_ratio => ["", "100"]}
|
||||
# Setting.commit_update_keywords_from_params(params)
|
||||
# # => {'fixes' => {'status_id' => "3"}, 'closes' => {'status_id' => "5", 'done_ratio' => "100"}}
|
||||
def self.commit_update_keywords_from_params(params)
|
||||
s = {}
|
||||
if params.is_a?(Hash) && params.key?(:keywords) && params.values.all? {|v| v.is_a? Array}
|
||||
attributes = params.except(:keywords).keys
|
||||
params[:keywords].each_with_index do |keywords, i|
|
||||
next if keywords.blank?
|
||||
s[keywords] = attributes.inject({}) {|h, a|
|
||||
value = params[a][i].to_s
|
||||
h[a.to_s] = value if value.present?
|
||||
h
|
||||
}
|
||||
end
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
# Helper that returns an array based on per_page_options setting
|
||||
def self.per_page_options_array
|
||||
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
|
||||
end
|
||||
|
||||
# Helper that returns a Hash with single update keywords as keys
|
||||
def self.commit_update_by_keyword
|
||||
h = {}
|
||||
if commit_update_keywords.is_a?(Hash)
|
||||
commit_update_keywords.each do |keywords, attribute_updates|
|
||||
next unless attribute_updates.is_a?(Hash)
|
||||
attribute_updates = attribute_updates.dup
|
||||
attribute_updates.delete_if {|k, v| v.blank?}
|
||||
keywords.to_s.split(",").map(&:strip).reject(&:blank?).each do |keyword|
|
||||
h[keyword.downcase] = attribute_updates
|
||||
end
|
||||
end
|
||||
end
|
||||
h
|
||||
end
|
||||
|
||||
def self.commit_fix_keywords
|
||||
ActiveSupport::Deprecation.warn "Setting.commit_fix_keywords is deprecated and will be removed in Redmine 3"
|
||||
if commit_update_keywords.is_a?(Hash)
|
||||
commit_update_keywords.keys.first
|
||||
end
|
||||
end
|
||||
|
||||
def self.commit_fix_status_id
|
||||
ActiveSupport::Deprecation.warn "Setting.commit_fix_status_id is deprecated and will be removed in Redmine 3"
|
||||
if commit_update_keywords.is_a?(Hash)
|
||||
commit_update_keywords[commit_fix_keywords]['status_id']
|
||||
end
|
||||
end
|
||||
|
||||
def self.commit_fix_done_ratio
|
||||
ActiveSupport::Deprecation.warn "Setting.commit_fix_done_ratio is deprecated and will be removed in Redmine 3"
|
||||
if commit_update_keywords.is_a?(Hash)
|
||||
commit_update_keywords[commit_fix_keywords]['done_ratio']
|
||||
end
|
||||
end
|
||||
|
||||
def self.openid?
|
||||
Object.const_defined?(:OpenID) && self[:openid].to_i > 0
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user