Как организовать автоматическое добавление комментария к запросу Redmine при изменении статуса на определённый

Я использую Redmine 3.4.6, мне нужно чтобы при изменении статуса Issue на определённый - добавлялся комментарий. Я выяснил, что такое можно провернуть с помощью хука controller issues edit after save hook, но я не смог найти пример такого хука. Я новичок в 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

Ответы (1 шт):

Автор решения: Zondrillo

Всё оказалось не очень сложно:

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
→ Ссылка