diff --git a/README.md b/README.md index eeb9994..dd11164 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,13 @@ if one of the subtasks has a status 'In progress', the parent issue can also be `rake redmine:plugins:issue_status_change:change_issues_on_subtask_status RAILS_ENV=production` +### Change target version ### + +If the target version of the subtask is different than the target version of the parent task, update +the target version of the subtask + +`rake redmine:plugins:issue_status_change:change_target_version RAILS_ENV=production` + ## Configuration ## Status changes can be configured per tracker. For each tracker, you can set if the task should change the diff --git a/app/models/issue_status_changer.rb b/app/models/issue_status_changer.rb index efffac1..40fa532 100644 --- a/app/models/issue_status_changer.rb +++ b/app/models/issue_status_changer.rb @@ -45,9 +45,14 @@ def self.change_issues_on_subtask_status __change_issues_on_subtask_status() end + def self.change_target_version + __change_target_version() + end + def self.issue_change_state(state) settings = Setting['plugin_redmine_issue_status_changer'] || {} + # TODO: do not close issues that have related issues blocked by enabled_trackers = get_enabled_trackers(state) enabled_trackers.split(',').each { |tracker| if state == 'close' then @@ -62,8 +67,13 @@ def self.issue_change_state(state) protected_trackers = settings[:new_status]['protected_status'][tracker] || ['999'] protected_status = protected_trackers.join(",") + # TODO: Do not rely on SQL query any more Issue.where("done_ratio#{test}100 AND tracker_id=#{tracker} AND status_id IN (#{change_state}) AND status_id NOT IN (#{protected_status}) AND id IN (SELECT parent_id FROM issues)").each do |issue| i = Issue.find issue.id + if i.relations_to.where(:relation_type => 'blocks').count > 0 then + # TODO: add skipped issues to an array and process again. A later iteration might close the blocking issue + next + end new_status = IssueStatus.find get_next_state(i.tracker_id, state) puts i.id.to_s + " " + i.subject + ": " + (IssueStatus.find i.status_id).name + " --> " + new_status.name @@ -97,5 +107,37 @@ def self.__change_issues_on_subtask_status() end } end + + def self.__change_target_version() + settings = Setting['plugin_redmine_issue_status_changer'] || {} + enabled_trackers = settings['change_target_version'].keys.join(',') + + status_message = settings['status_message_target_version'] + + enabled_trackers.split(',').each { |tracker| + + Issue.joins(:status).joins('INNER JOIN `issues` AS parent ON parent.id=`issues`.parent_id').where(:tracker_id => 3).where('issue_statuses.is_closed=0').where('`issues`.fixed_version_id!=parent.fixed_version_id OR (parent.fixed_version_id IS NULL AND `issues`.fixed_version_id IS NOT NULL) OR (parent.fixed_version_id IS NOT NULL and `issues`.fixed_version_id IS NULL)').each do |issue| + i = Issue.find issue.id + + if i.fixed_version_id? then + current_version = Version.find(i.fixed_version_id).name + else + current_version = 'None' + end + + if i.parent.fixed_version_id? then + new_version = Version.find(i.parent.fixed_version_id).name + new_version_id = i.parent.fixed_version_id + else + new_version = 'None' + new_version_id = nil + end + + puts i.id.to_s + " " + i.subject + ": " + current_version + " --> " + new_version + i.init_journal(User.anonymous, status_message) + i.update_attribute :fixed_version_id, new_version_id + end + } + end end diff --git a/app/views/settings/_issue_status_change.html.erb b/app/views/settings/_issue_status_change.html.erb index 6cd028b..549577e 100755 --- a/app/views/settings/_issue_status_change.html.erb +++ b/app/views/settings/_issue_status_change.html.erb @@ -15,23 +15,32 @@ <% settings['new_status']['protected_status'] = Hash.new if settings['new_status']['protected_status'] == nil %> +<% settings['change_target_version'] = Hash.new if settings['change_target_version'] == nil %> + <% settings['status_message_closed'] = l(:status_message_closed) if settings['status_message_closed'] == nil %> <% settings['status_message_open'] = l(:status_message_open) if settings['status_message_open'] == nil %> <% settings['status_message_additional'] = l(:status_message_additional) if settings['status_message_additional'] == nil %> +<% settings['status_message_target_version'] = l(:status_message_target_version) if settings['status_message_target_version'] == nil %> + +<% puts @settings %>
<%= l(:status_message_legend) %>

- <%= text_field_tag "settings[status_message_closed]", settings[:status_message_closed] %> + <%= text_field_tag "settings[status_message_closed]", settings['status_message_closed'] %>

- <%= text_field_tag "settings[status_message_open]", settings[:status_message_open] %> + <%= text_field_tag "settings[status_message_open]", settings['status_message_open'] %> +

+

+ + <%= text_field_tag "settings[status_message_additional]", settings['status_message_additional'] %>

- <%= text_field_tag "settings[status_message_additional]", settings[:status_message_additional] %> + <%= text_field_tag "settings[status_message_target_version]", settings['status_message_target_version'] %>

@@ -42,29 +51,29 @@ <%= tracker.name %>

- <%= check_box_tag "settings[status_change][close][#{tracker.id}]", "1", @settings[:status_change]['close'][tracker.id.to_s] %> + <%= check_box_tag "settings[status_change][close][#{tracker.id}]", "1", @settings['status_change']['close'][tracker.id.to_s] %>

- <%= select_tag "settings[new_status][close][#{tracker.id}]", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 1).uniq.map {|s| [s.name, s.id]},@settings[:new_status]['close'][tracker.id.to_s]) %> + <%= select_tag "settings[new_status][close][#{tracker.id}]", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 1).uniq.map {|s| [s.name, s.id]},@settings['new_status']['close'][tracker.id.to_s]) %>

- <%= check_box_tag "settings[status_change][open][#{tracker.id}]", "1", @settings[:status_change]['open'][tracker.id.to_s] %> + <%= check_box_tag "settings[status_change][open][#{tracker.id}]", "1", @settings['status_change']['open'][tracker.id.to_s] %>

- <%= select_tag "settings[new_status][open][#{tracker.id}]", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 0).uniq.map {|s| [s.name, s.id]},@settings[:new_status]['open'][tracker.id.to_s]) %> + <%= select_tag "settings[new_status][open][#{tracker.id}]", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 0).uniq.map {|s| [s.name, s.id]},@settings['new_status']['open'][tracker.id.to_s]) %>

- <%= check_box_tag "settings[status_change][additional][#{tracker.id}]", "1", @settings[:status_change]['additional'][tracker.id.to_s] %> + <%= check_box_tag "settings[status_change][additional][#{tracker.id}]", "1", @settings['status_change']['additional'][tracker.id.to_s] %>
<%= l(:additional_status_change_description_1) %> - <%= select_tag "settings[new_status][additional_from][#{tracker.id}]", options_for_select(IssueStatus.all.map {|s| [s.name, s.id]},@settings[:new_status]['additional_from'][tracker.id.to_s]) %> + <%= select_tag "settings[new_status][additional_from][#{tracker.id}]", options_for_select(IssueStatus.all.map {|s| [s.name, s.id]},@settings['new_status']['additional_from'][tracker.id.to_s]) %> <%= l(:additional_status_change_description_2) %> - <%= select_tag "settings[new_status][additional_to][#{tracker.id}]", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}).uniq.map {|s| [s.name, s.id]},@settings[:new_status]['additional_to'][tracker.id.to_s]) %> + <%= select_tag "settings[new_status][additional_to][#{tracker.id}]", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}).uniq.map {|s| [s.name, s.id]},@settings['new_status']['additional_to'][tracker.id.to_s]) %>

@@ -72,9 +81,14 @@

- <%= select_tag "settings[new_status][protected_status][#{tracker.id}]", options_for_select(IssueStatus.all.map {|s| [s.name, s.id]},@settings[:new_status]['protected_status'][tracker.id.to_s]), :multiple => true %> + <%= select_tag "settings[new_status][protected_status][#{tracker.id}]", options_for_select(IssueStatus.all.map {|s| [s.name, s.id]},@settings['new_status']['protected_status'][tracker.id.to_s]), :multiple => true %>

+ +

+ + <%= check_box_tag "settings[change_target_version][#{tracker.id}]", "1", @settings['change_target_version'][tracker.id.to_s] %> +

<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index b04a017..8e50bd2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,9 +13,10 @@ en: status_message_label_additional: "Journal message for additional status change" status_message_additional: "Automatically changing status" status_message_legend: "Journal" - status_message_legend: "Journal" - status_message_legend: "Journal" + status_message_label_additional: "Journal message when target version is changed" + status_message_target_version: "Changing target version to version of parent task" additional_status_change_label: "Additional status change" additional_status_change_description_1: "If the status of one of the subtasks is" additional_status_change_description_2: "change parent issue to" - protected_status_label: "Protected statuses" \ No newline at end of file + protected_status_label: "Protected statuses" + change_fixed_version: "Set version to parent version" diff --git a/init.rb b/init.rb index 3b4c3bc..54914b1 100644 --- a/init.rb +++ b/init.rb @@ -4,14 +4,15 @@ name 'Redmine Issue Status Changer' author 'Daniel Vijge' description 'Automatically change status of issues based on status of subtasks' - version '0.0.2' + version '0.0.3' url 'https://github.com/eurailcom/redmine_issue_status_changer' author_url 'https://github.com/danielvijge' requires_redmine version_or_higher: '2.1.0' settings :default => { "change_status" => 1, - "new_status" => 1 + "new_status" => 1, + "change_target_version" => 1 }, :partial => 'settings/issue_status_change' settings[:default]["change_status"] = Hash.new @@ -24,5 +25,6 @@ settings[:default]["new_status"]["additional_from"] = Hash.new settings[:default]["new_status"]["additional_to"] = Hash.new settings[:default]["new_status"]["protected_status"] = Hash.new + settings[:default]["change_target_version"] = Hash.new end diff --git a/lib/tasks/change_target_version.rake b/lib/tasks/change_target_version.rake new file mode 100644 index 0000000..5633334 --- /dev/null +++ b/lib/tasks/change_target_version.rake @@ -0,0 +1,14 @@ +namespace :redmine do + namespace :plugins do + namespace :issue_status_change do + desc <<-END_DESC +Change the target version to the target version of the parent task + + rake redmine:plugins:issue_status_change:change_target_version RAILS_ENV=production + END_DESC + task change_target_version: :environment do |_t, _args| + IssueStatusChanger.change_target_version + end + end + end +end \ No newline at end of file