Pointers for my first plugin
Added by Brett Patterson over 14 years ago
I'm just looking for some pointers (articles, tutorials, or general tips) for creating a plugin which uses this redmine hook: model_changeset_scan_commit_for_issue_ids_pre_issue_update
I'm trying to modify the ticket that's "fixed" on a repository commit to change the author. I already have the working code that I can use if I patch the core to do what I want. So now I'm trying to pull it out into a plugin (per Eric's suggestion).
So I think I'm on the right, track, but if anyone can help me out, I'd appreciate it.
init.rb
require 'redmine'
require 'dispatcher'
Dispatcher.to_prepare :redmine_reassign_original_author do
require_dependency 'issue'
unless Issue.included_modules.include? RedmineReassignOriginalAuthor::IssuePatch
Issue.send(:include, RedmineReassignOriginalAuthor::IssuePatch)
end
end
Redmine::Plugin.register :redmine_reassign_original_author do
name 'Reassign to Original Author'
author 'Brett Patterson'
description 'Adds extra functionality to the "fixes" keyword to reassign that issue to its original author'
version '0.0.1'
requires_redmine :version_or_higher => '1.0.2'
end
lib/redmine_reassign_original_author/issue_patch.rb
module RedmineReassignOriginalAuthor
module IssuePatch
def self.included(base)
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
model_changeset_scan_commit_for_issue_ids_pre_issue_update :reassign_to_original_author
end
end
module ClassMethods
end
module InstanceMethods
def reassign_to_original_author
ReassignOriginalAuthorIssue.reassign_author(self)
end
end
end
end
app/models/reassign_original_author_issue.rb
class ReassignOriginalAuthorIssue < ActiveRecord::Base
def self.reassign_author(issue)
return true if issue.nil?
end
end
I know I have probably a bunch of missteps in there, but some direction would be great. Thanks!
Replies (1)
RE: Pointers for my first plugin
-
Added by Eric Davis over 14 years ago
Brett Patterson:
It's a good start. One thing that isn't correct though is that you are patching the Issue model and not using the Redmine hook. Patching is only needed for adding or changing how core classes work, hooking is used to extend Redmine at specific hooks (it's confusing, I know). Since there already is a hook (model_changeset_scan_commit_for_issue_ids_pre_issue_update
), you don't need to patch it.
Read through Hooks a bit and pay attention to the "Controller-and-Model-hooks" section. I'll update that page with some more examples in a minute.
Eric Davis