Ability to define commit keywords per tracker (#7590).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12208 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2013-10-13 07:37:49 +00:00
parent b8aa4da28a
commit b6cb7aa8e3
9 changed files with 115 additions and 73 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ class SettingsController < ApplicationController
@guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
@commit_update_keywords = Setting.commit_update_keywords.dup
@commit_update_keywords[''] = {} if @commit_update_keywords.blank?
@commit_update_keywords << {} if @commit_update_keywords.blank?
Redmine::Themes.rescan
end
+7 -5
View File
@@ -118,7 +118,7 @@ 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_update_by_keyword.keys
fix_keywords = Setting.commit_update_keywords_array.map {|r| r['keywords']}.flatten.compact
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
@@ -215,16 +215,18 @@ class Changeset < ActiveRecord::Base
# 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
# don't change the status is the issue is closed
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.assign_attributes updates.slice(*Issue.attribute_names)
rule = Setting.commit_update_keywords_array.detect do |rule|
rule['keywords'].include?(action) && (rule['if_tracker_id'].blank? || rule['if_tracker_id'] == issue.tracker_id.to_s)
end
if rule
issue.assign_attributes rule.slice(*Issue.attribute_names)
end
Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
{ :changeset => self, :issue => issue, :action => action })
unless issue.save
+24 -24
View File
@@ -154,18 +154,18 @@ END_SRC
# 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"}}
# # => [{'keywords => 'fixes', 'status_id' => "3"}, {'keywords => 'closes', 'status_id' => "5", 'done_ratio' => "100"}]
def self.commit_update_keywords_from_params(params)
s = {}
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|
s << attributes.inject({}) {|h, a|
value = params[a][i].to_s
h[a.to_s] = value if value.present?
h
}
}.merge('keywords' => keywords)
end
end
s
@@ -177,39 +177,39 @@ END_SRC
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
def self.commit_update_keywords_array
a = []
if commit_update_keywords.is_a?(Array)
commit_update_keywords.each do |rule|
next unless rule.is_a?(Hash)
rule = rule.dup
rule.delete_if {|k, v| v.blank?}
keywords = rule['keywords'].to_s.downcase.split(",").map(&:strip).reject(&:blank?)
next if keywords.empty?
a << rule.merge('keywords' => keywords)
end
end
h
a
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
ActiveSupport::Deprecation.warn "Setting.commit_fix_keywords is deprecated and will be removed in Redmine 3"
if commit_update_keywords.is_a?(Array)
commit_update_keywords.first && commit_update_keywords.first['keywords']
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']
ActiveSupport::Deprecation.warn "Setting.commit_fix_status_id is deprecated and will be removed in Redmine 3"
if commit_update_keywords.is_a?(Array)
commit_update_keywords.first && commit_update_keywords.first['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']
ActiveSupport::Deprecation.warn "Setting.commit_fix_done_ratio is deprecated and will be removed in Redmine 3"
if commit_update_keywords.is_a?(Array)
commit_update_keywords.first && commit_update_keywords.first['done_ratio']
end
end
+7 -4
View File
@@ -80,6 +80,7 @@
<table class="list" id="commit-keywords">
<thead>
<tr>
<th><%= l(:label_tracker) %></th>
<th><%= l(:setting_commit_fix_keywords) %></th>
<th><%= l(:label_applied_status) %></th>
<th><%= l(:field_done_ratio) %></th>
@@ -87,15 +88,17 @@
</tr>
</thead>
<tbody>
<% @commit_update_keywords.each do |keywords, updates| %>
<% @commit_update_keywords.each do |rule| %>
<tr class="commit-keywords">
<td><%= text_field_tag "settings[commit_update_keywords][keywords][]", keywords, :size => 30 %></td>
<td><%= select_tag "settings[commit_update_keywords][status_id][]", options_for_select([["", 0]] + IssueStatus.sorted.all.collect{|status| [status.name, status.id.to_s]}, updates['status_id']) %></td>
<td><%= select_tag "settings[commit_update_keywords][done_ratio][]", options_for_select([["", ""]] + (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, updates['done_ratio']) %></td>
<td><%= select_tag "settings[commit_update_keywords][if_tracker_id][]", options_for_select([[l(:label_all), ""]] + Tracker.sorted.all.map {|t| [t.name, t.id.to_s]}, rule['if_tracker_id']) %></td>
<td><%= text_field_tag "settings[commit_update_keywords][keywords][]", rule['keywords'], :size => 30 %></td>
<td><%= select_tag "settings[commit_update_keywords][status_id][]", options_for_select([["", 0]] + IssueStatus.sorted.all.collect{|status| [status.name, status.id.to_s]}, rule['status_id']) %></td>
<td><%= select_tag "settings[commit_update_keywords][done_ratio][]", options_for_select([["", ""]] + (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, rule['done_ratio']) %></td>
<td class="buttons"><%= link_to image_tag('delete.png'), '#', :class => 'delete-commit-keywords' %></td>
</tr>
<% end %>
<tr>
<td></td>
<td><em class="info"><%= l(:text_comma_separated) %></em></td>
<td></td>
<td></td>