Skip to content

Commit

Permalink
Redmine 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kotashiratsuka committed Nov 24, 2024
1 parent 44d4b12 commit e5e3729
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 50 deletions.
3 changes: 1 addition & 2 deletions app/views/layouts/_body_bottom.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if controller_name == 'wiki' && action_name == 'history' -%>
<script>
(function() {
var issuePath = '<%=j issue_path(999) %>'.replace(/999$/, '');
var issuePath = '<%= j issue_path(999) %>'.replace(/999$/, '');
var re = /#(\d+)/;
var comment;

Expand All @@ -14,4 +14,3 @@
})();
</script>
<% end -%>

9 changes: 5 additions & 4 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
18 changes: 8 additions & 10 deletions lib/issue_wiki_journal.rb
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -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

59 changes: 28 additions & 31 deletions lib/issue_wiki_journal/wiki_changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) &&
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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" +
Expand All @@ -158,4 +156,3 @@ def logger
end
end
end

Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -16,4 +16,3 @@ def page_content_changed?(new_page, old_page_version)
end
end
end

0 comments on commit e5e3729

Please sign in to comment.