当问题状态更改为特定状态时,如何在 redmine 中设置自动添加评论

How to set up automatic adding of a comment in redmine when the issue status changes to a specific one

我正在使用 Redmine 3.4.6,我需要让它在问题状态更改为特定状态时添加评论。我发现它可以通过在保存挂钩后编辑控制器问题来实现,但是我找不到任何如何编写控制器挂钩的好例子。我是 Ruby 和编码的初学者,所以我请别人解释我必须做些什么才能让它工作。 Issue

我的代码:

module RedmineAutocomments
  module Hooks
    class RedmineAutocommentsHook < Redmine::Hook::ViewListener
      def controller_issues_edit_after_save(context={})
        issue = context[:issue]
        trackers = ["Tracker1", "Tracker2", "Tracker3"]
        if trackers.include? @issue.tracker
          if @issue.status == "Ready for handout"
            @comment = Comment.new
            @comment = 'Some comment need to be added'
            @news.comments << @comment
          end
        end
      end
    end
  end
end

事实证明一切都不是很困难:

module RedmineAutocomments
  module Hooks
    class RedmineAutocommentsHook < Redmine::Hook::ViewListener
      def controller_issues_edit_after_save(context={})
        @issue = context[:issue]
        case @issue.project.id
        when 9
          case @issue.tracker.id
          when 13, 14, 20
            case @issue.status.id
            when 26
              @issue.notes = MESSAGE
              @issue.save
            end
          end
        end
      end
    end
  end
end