mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-02 19:30:48 +08:00
新增:触发webhook的job
This commit is contained in:
28
app/jobs/touch_webhook_job.rb
Normal file
28
app/jobs/touch_webhook_job.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class TouchWebhookJob < ApplicationJob
|
||||
queue_as :webhook
|
||||
|
||||
def perform(source, *args)
|
||||
case source
|
||||
when 'IssueCreate'
|
||||
issue_id, sender_id = args[0], args[1]
|
||||
issue = Issue.find_by_id issue_id
|
||||
sender = User.find_by_id sender_id
|
||||
return if issue.nil? || sender.nil?
|
||||
issue.project.webhooks.each do |webhook|
|
||||
next unless webhook.events["events"]["issues"]
|
||||
@webhook_task = Webhook::IssueCreateClient.new(webhook, issue, sender).do_request
|
||||
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
||||
end
|
||||
when 'IssueUpdate'
|
||||
issue_id, sender_id, changes = args[0], args[1], args[2]
|
||||
issue = Issue.find_by_id issue_id
|
||||
sender = User.find_by_id sender_id
|
||||
return if issue.nil? || sender.nil? || !changes.is_a?(Hash)
|
||||
issue.project.webhooks.each do |webhook|
|
||||
next unless webhook.events["events"]["issues"]
|
||||
@webhook_task = Webhook::IssueUpdateClient.new(webhook, issue, sender, changes.stringify_keys).do_request
|
||||
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user