From 426892df1d3dd7ed582094ffdef4782ed7e1f791 Mon Sep 17 00:00:00 2001 From: suer Date: Wed, 19 Feb 2014 22:52:40 +0900 Subject: [PATCH] Added: journal wrapper --- .gitignore | 1 + lib/redmine_webhook/.issue_wrapper.rb.swp | Bin 0 -> 12288 bytes lib/redmine_webhook/issue_wrapper.rb | 10 +++++----- lib/redmine_webhook/journal_detail_wrapper.rb | 15 +++++++++++++++ lib/redmine_webhook/journal_wrapper.rb | 16 ++++++++++++++++ lib/redmine_webhook/webhook_listener.rb | 16 +++++++++++++--- 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 lib/redmine_webhook/.issue_wrapper.rb.swp create mode 100644 lib/redmine_webhook/journal_detail_wrapper.rb create mode 100644 lib/redmine_webhook/journal_wrapper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/lib/redmine_webhook/.issue_wrapper.rb.swp b/lib/redmine_webhook/.issue_wrapper.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..00710020e316c88d5dfaaba35a4a8b9018528ca2 GIT binary patch literal 12288 zcmeI2v5V9|6vp4Fjhv^VwGb8I4s`eQ1YzMsvAW`5@zldY!fa-A$IWHJ%;Xk5^jiM_ z!9uJpv=S^Wt^EsZw9&#!ECdT*lF4j#lf%MFd4X@U^X8i`nO`!+vNKq|wYDBy>Rbdo zjspC8dtjr#KRfv234qB&Uj5^d2*G1vOea>Y5g-CY zfCvx)B0vO)z&}WUae&+N0AEr0|NqtR|Bpui-lN{2UZY;2UZ9?#c2RdwE2w$Y=feQ+ zP|r~rY8`b3HHZ4J0PqsEgF1)$bO_)n>Kf`NUh_NZo4fv({2u5a0z`la5CI}U1c(3; zAOb|-?+J*6LlBgoLGTE_=SPoacBpi)dO5gWZpPg#_ulq;SBsuax6w8c*VmF(4fA @issue.estimated_hours, :is_private => @issue.is_private, :lock_version => @issue.lock_version, - :project => ProjectWrapper.new(@issue.project).to_hash, - :status => StatusWrapper.new(@issue.status).to_hash, - :tracker => TrackerWrapper.new(@issue.tracker).to_hash, - :priority => PriorityWrapper.new(@issue.priority).to_hash, - :author => AuthorWrapper.new(@issue.author).to_hash + :project => RedmineWebhook::ProjectWrapper.new(@issue.project).to_hash, + :status => RedmineWebhook::StatusWrapper.new(@issue.status).to_hash, + :tracker => RedmineWebhook::TrackerWrapper.new(@issue.tracker).to_hash, + :priority => RedmineWebhook::PriorityWrapper.new(@issue.priority).to_hash, + :author => RedmineWebhook::AuthorWrapper.new(@issue.author).to_hash } end end diff --git a/lib/redmine_webhook/journal_detail_wrapper.rb b/lib/redmine_webhook/journal_detail_wrapper.rb new file mode 100644 index 0000000..52b64b6 --- /dev/null +++ b/lib/redmine_webhook/journal_detail_wrapper.rb @@ -0,0 +1,15 @@ +class RedmineWebhook::JournalDetailWrapper + def initialize(journal_detail) + @journal_detail = journal_detail + end + + def to_hash + { + :id => @journal_detail.id, + :value => @journal_detail.value, + :old_value => @journal_detail.old_value, + :prop_key => @journal_detail.prop_key, + :property => @journal_detail.property + } + end +end diff --git a/lib/redmine_webhook/journal_wrapper.rb b/lib/redmine_webhook/journal_wrapper.rb new file mode 100644 index 0000000..c53c879 --- /dev/null +++ b/lib/redmine_webhook/journal_wrapper.rb @@ -0,0 +1,16 @@ +class RedmineWebhook::JournalWrapper + def initialize(journal) + @journal = journal + end + + def to_hash + { + :id => @journal.id, + :notes => @journal.notes, + :created_on => @journal.created_on, + :private_notes => @journal.private_notes, + :author => RedmineWebhook::AuthorWrapper.new(@journal.user).to_hash, + :details => @journal.details.map {|detail| RedmineWebhook::JournalDetailWrapper.new(detail).to_hash } + } + end +end diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index ea01f1e..a46b87f 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -9,11 +9,11 @@ class RedmineWebhook::WebhookListener < Redmine::Hook::Listener def controller_issues_edit_after_save(context = {}) journal = context[:journal] - journal.issue = context[:issue] - project = journal.issue.project + issue = context[:issue] + project = issue.project webhook = Webhook.where(:project_id => project.project.id).first return unless webhook - post(webhook, journal_create_payload(journal)) + post(webhook, journal_to_json(issue, journal)) end private @@ -26,6 +26,16 @@ class RedmineWebhook::WebhookListener < Redmine::Hook::Listener }.to_json end + def journal_to_json(issue, journal) + { + :payload => { + :action => 'updated', + :issue => RedmineWebhook::IssueWrapper.new(issue).to_hash, + :journal => RedmineWebhook::JournalWrapper.new(journal).to_hash + } + }.to_json + end + def journal_create_payload(journal) {:payload => journal}.to_json(journal_to_json_option) end