diff --git a/app/views/layouts/_body_bottom.html.erb b/app/views/layouts/_body_bottom.html.erb index 4b5f391..307b9de 100644 --- a/app/views/layouts/_body_bottom.html.erb +++ b/app/views/layouts/_body_bottom.html.erb @@ -1,7 +1,7 @@ <% if controller_name == 'wiki' && action_name == 'history' -%> <% end -%> - diff --git a/init.rb b/init.rb index c41347b..c7816a0 100644 --- a/init.rb +++ b/init.rb @@ -3,12 +3,13 @@ Redmine::Plugin.register :redmine_issue_wiki_journal do name 'Redmine Issue Wiki Journal' author 'Katsuya Hidaka' - description 'Redmine plugin for referencing and fixing issues in comment of wiki updates.' + description 'Redmine plugin for referencing and fixing issues in comment of wiki updates.' version '0.10.0' url 'https://github.com/hidakatsuya/redmine_issue_wiki_journal' author_url 'https://github.com/hidakatsuya' - # Requires Redmine 3.3.x or higher - requires_redmine '3.3' + # Redmine 6.0.0以降に対応 + requires_redmine '6.0.0' end -require 'issue_wiki_journal' +require File.expand_path('../lib/issue_wiki_journal/application_hooks', __FILE__) +require File.expand_path('../lib/issue_wiki_journal/wiki_controller_hooks', __FILE__) diff --git a/lib/issue_wiki_journal.rb b/lib/issue_wiki_journal.rb index 7147945..68e99b3 100644 --- a/lib/issue_wiki_journal.rb +++ b/lib/issue_wiki_journal.rb @@ -1,17 +1,15 @@ require 'pathname' module IssueWikiJournal - def self.root - @root ||= Pathname.new(File.expand_path('../../', __FILE__)) - end - - def self.version - Redmine::Plugin.find(:roots).version + class WikiChangeset + def self.root + @root ||= Pathname.new(File.expand_path('../../', __FILE__)) + end + + def self.version + Redmine::Plugin.find(:redmine_issue_wiki_journal).version + end end end -# Load libraries require_relative 'issue_wiki_journal/wiki_changeset' - -# Load hooks -Dir[IssueWikiJournal.root.join('app/hooks/**/*_hooks.rb')].each {|f| require f } diff --git a/app/hooks/application_hooks.rb b/lib/issue_wiki_journal/application_hooks.rb similarity index 62% rename from app/hooks/application_hooks.rb rename to lib/issue_wiki_journal/application_hooks.rb index 965cd38..620a7d5 100644 --- a/app/hooks/application_hooks.rb +++ b/lib/issue_wiki_journal/application_hooks.rb @@ -1,5 +1,7 @@ +# /ApplicationHookshome/redmine/plugins/redmine_issue_wiki_journal/app/hooks/application_hooks.rb module IssueWikiJournal class ApplicationHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_body_bottom, partial: 'layouts/body_bottom' end end + diff --git a/lib/issue_wiki_journal/wiki_changeset.rb b/lib/issue_wiki_journal/wiki_changeset.rb index 99b32ae..a2d8f44 100644 --- a/lib/issue_wiki_journal/wiki_changeset.rb +++ b/lib/issue_wiki_journal/wiki_changeset.rb @@ -21,21 +21,20 @@ def apply_to_related_issues! attr_reader :comments, :user, :project def fix_keywords - @fix_keywords ||= if ::Redmine::VERSION.to_s < '2.4' - Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) - else - Setting.commit_update_keywords_array.map {|r| r['keywords']}.flatten.compact - end + @fix_keywords ||= if Redmine::VERSION.to_s < '2.4' + Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) + else + Setting.commit_update_keywords_array.map { |r| r['keywords'] }.flatten.compact + end end - # same as Changeset#scan_comment_for_issue_ids def scan_comment_for_issue_ids return if comments.blank? ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip) ref_keywords_any = ref_keywords.delete('*') - kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") + kw_regexp = (ref_keywords + fix_keywords).collect { |kw| Regexp.escape(kw) }.join("|") 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] @@ -54,14 +53,15 @@ def scan_comment_for_issue_ids # Finds an issue that can be referenced by the commit message def find_referenced_issue_by_id(id) return nil if id.blank? - issue = Issue.find_by_id(id.to_i) + issue = Issue.find_by(id: id.to_i) + if Setting.commit_cross_project_ref? # all issues can be referenced/fixed elsif issue # issue that belong to the repository project, a subproject or a parent project only unless issue.project && - (project == issue.project || project.is_ancestor_of?(issue.project) || - project.is_descendant_of?(issue.project)) + (project == issue.project || project.is_ancestor_of?(issue.project) || + project.is_descendant_of?(issue.project)) issue = nil end end @@ -72,9 +72,8 @@ def fix_issue(issue, action) if fix_keywords.include?(action) issue.reload - # less than 2.4 if Redmine::VERSION.to_s < '2.4' - status = IssueStatus.find_by_id(Setting.commit_fix_status_id.to_i) + 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 @@ -85,7 +84,6 @@ def fix_issue(issue, action) unless Setting.commit_fix_done_ratio.blank? issue.done_ratio = Setting.commit_fix_done_ratio.to_i end - # greater than 2.4 or equal else rule = Setting.commit_update_keywords_array.detect do |rule| rule['keywords'].include?(action) && @@ -106,13 +104,13 @@ def fix_issue(issue, action) def log_time(issue, hours) time_entry = TimeEntry.new( - :user => user, - :hours => hours, - :issue => issue, - :spent_on => commit_date, - :comments => l(:text_time_logged_by_changeset, :value => text_tag(issue.project), - :locale => Setting.default_language) - ) + user: user, + hours: hours, + issue: issue, + spent_on: commit_date, + comments: l(:text_time_logged_by_changeset, value: text_tag(issue.project), + locale: Setting.default_language) + ) time_entry.activity = log_time_activity unless log_time_activity.nil? unless time_entry.save @@ -123,7 +121,7 @@ def log_time(issue, hours) def log_time_activity if Setting.commit_logtime_activity_id.to_i > 0 - TimeEntryActivity.find_by_id(Setting.commit_logtime_activity_id.to_i) + TimeEntryActivity.find_by(id: Setting.commit_logtime_activity_id.to_i) end end @@ -134,15 +132,15 @@ def commit_date def message(fix = false) version = @page.content.version version_path = if version > 1 - helpers.url_for action: 'diff', controller: 'wiki', - project_id: @project.identifier, id: @page.title, - version: version, version_from: version - 1, - only_path: true - else - helpers.url_for action: 'show', controller: 'wiki', - project_id: @project.identifier, id: @page.title, - version: version, only_path: true - end + helpers.url_for(action: 'diff', controller: 'wiki', + project_id: @project.identifier, id: @page.title, + version: version, version_from: version - 1, + only_path: true) + else + helpers.url_for(action: 'show', controller: 'wiki', + project_id: @project.identifier, id: @page.title, + version: version, only_path: true) + end @message ||= l('issue_wiki_journal.text_status_changed_by_wiki_changeset', page: "#{@project.identifier}:#{@page.title}", version: %Q!"#{version}":#{version_path}!) + ":\n\n" + @@ -158,4 +156,3 @@ def logger end end end - diff --git a/app/hooks/wiki_controller_hooks.rb b/lib/issue_wiki_journal/wiki_controller_hooks.rb similarity index 78% rename from app/hooks/wiki_controller_hooks.rb rename to lib/issue_wiki_journal/wiki_controller_hooks.rb index 6a6889f..69f6312 100644 --- a/app/hooks/wiki_controller_hooks.rb +++ b/lib/issue_wiki_journal/wiki_controller_hooks.rb @@ -1,7 +1,7 @@ module IssueWikiJournal class WikiControllerHooks < Redmine::Hook::ViewListener - def controller_wiki_edit_after_save(args = {}) - page, params = args.values_at :page, :params + def controller_wiki_edit_after_save(context = {}) + page, params = context[:page], context[:params] if page_content_changed?(page, params[:content][:version]) changeset = WikiChangeset.new(page) @@ -16,4 +16,3 @@ def page_content_changed?(new_page, old_page_version) end end end -