mirror of
https://github.com/dolphin-emu/redmine_webhook.git
synced 2026-01-31 01:15:19 +01:00
Added: model wrapper
This commit is contained in:
11
Gemfile.lock
Normal file
11
Gemfile.lock
Normal file
@@ -0,0 +1,11 @@
|
||||
GEM
|
||||
specs:
|
||||
faraday (0.8.8)
|
||||
multipart-post (~> 1.2.0)
|
||||
multipart-post (1.2.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
faraday
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'redmine_webhook/projects_helper_patch'
|
||||
require 'redmine_webhook/issue_wrapper'
|
||||
require 'redmine_webhook/webhook_listener'
|
||||
|
||||
module RedmineWebhook
|
||||
|
||||
27
lib/redmine_webhook/issue_wrapper.rb
Normal file
27
lib/redmine_webhook/issue_wrapper.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user