diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..593bb24 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,11 @@ +GEM + specs: + faraday (0.8.8) + multipart-post (~> 1.2.0) + multipart-post (1.2.0) + +PLATFORMS + ruby + +DEPENDENCIES + faraday diff --git a/lib/redmine_webhook.rb b/lib/redmine_webhook.rb index 6aa44c0..c2e7b50 100644 --- a/lib/redmine_webhook.rb +++ b/lib/redmine_webhook.rb @@ -1,4 +1,5 @@ require 'redmine_webhook/projects_helper_patch' +require 'redmine_webhook/issue_wrapper' require 'redmine_webhook/webhook_listener' module RedmineWebhook diff --git a/lib/redmine_webhook/issue_wrapper.rb b/lib/redmine_webhook/issue_wrapper.rb new file mode 100644 index 0000000..9d72295 --- /dev/null +++ b/lib/redmine_webhook/issue_wrapper.rb @@ -0,0 +1,27 @@ +class RedmineWebhook::IssueWrapper + def initialize(issue) + @issue = issue + end + + def to_json + { + :action => "create", + :issue => { + :id => @issue.id, + :subject => @issue.subject, + :description => @issue.description, + :created_on => @issue.created_on, + :updated_on => @issue.updated_on, + :closed_on => @issue.closed_on, + :root_id => @issue.root_id, + :parent_id => @issue.parent_id, + :done_ratio => @issue.done_ratio, + :start_date => @issue.start_date, + :due_date => @issue.due_date, + :estimated_hours => @issue.estimated_hours, + :is_private => @issue.is_private, + :lock_version => @issue.lock_version + } + }.to_json + end +end diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index 1d9e679..6e7a55d 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -4,7 +4,7 @@ class RedmineWebhook::WebhookListener < Redmine::Hook::Listener project = issue.project webhook = Webhook.where(:project_id => project.project.id).first return unless webhook - post(webhook, issue_create_payload(issue)) + post(webhook, RedmineWebhook::IssueWrapper.new(issue).to_json) end def controller_issues_edit_after_save(context = {}) @@ -17,23 +17,6 @@ class RedmineWebhook::WebhookListener < Redmine::Hook::Listener end private - def issue_create_payload(issue) - {:payload => issue}.to_json(issues_to_json_option) - end - - def issues_to_json_option - { - :include => [ - {:project => {:only => [:id, :identifier, :name, :description, :homepage, :created_on, :updated_at]}}, - {:status => {:only => [:id, :name]}}, - {:tracker => {:only => [:id, :name]}}, - {:priority => {:only => [:id, :name]}}, - {:author => {:only => [:login, :mail, :firstname, :lastname, :identity_url]}}, - {:assigned_to => {:only => [:login, :mail, :firstname, :lastname, :identity_url]}} - ] - } - end - def journal_create_payload(journal) {:payload => journal}.to_json(journal_to_json_option) end