ruby - 当问题状态更改为特定状态时,如何在 redmine 中设置自动添加评论
问题描述
我正在使用 Redmine 3.4.6,当问题状态更改为特定状态时,我需要添加评论。我发现它可以通过保存钩子后的控制器问题编辑来实现,但我找不到任何如何编写控制器钩子的好例子。我是 Ruby 和编码的初学者,所以我请人解释我必须做些什么才能使它工作。 问题
我的代码:
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
推荐阅读
- google-apps-script - 有没有办法使用一个工作表作为数据库来创建基于日期的代码?
- flutter - 将 MediaItem 列表转换为 ConcatenatingAudioSource 错误:“ConcatenatingAudioSource”实例
- pine-script - 每天在同一时间开仓并设置每日止损 (pinesript - tradingview)
- c# - C# .Net Core Mongodb 驱动程序返回名称值对而不是实际的 json
- c# - 斐波那契数的二维数组。算法中的错误 (IndexOutOfRangeException)。如何解决?
- compiler-errors - EBNF 表示法的编译器层次结构
- r - 以 pdf 格式保存 R plot_ly 图
- ubuntu - 安装新版本前无法建立“./usr/bin/ssh”的备份链接 不允许操作
- asp.net-core - 为大量数据库运行迁移的最佳 Ef 核心策略?
- php - 从 Wordpress 中的关系字段显示和排序帖子(Pods 和事件日历)