mirror of
https://github.com/dolphin-emu/redmine_webhook.git
synced 2026-01-31 01:15:19 +01:00
Added: journal wrapper
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.swp
|
||||
BIN
lib/redmine_webhook/.issue_wrapper.rb.swp
Normal file
BIN
lib/redmine_webhook/.issue_wrapper.rb.swp
Normal file
Binary file not shown.
@@ -19,11 +19,11 @@ class RedmineWebhook::IssueWrapper
|
||||
:estimated_hours => @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
|
||||
|
||||
15
lib/redmine_webhook/journal_detail_wrapper.rb
Normal file
15
lib/redmine_webhook/journal_detail_wrapper.rb
Normal file
@@ -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
|
||||
16
lib/redmine_webhook/journal_wrapper.rb
Normal file
16
lib/redmine_webhook/journal_wrapper.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user