新增:触发webhook的job

This commit is contained in:
2023-03-30 10:19:50 +08:00
parent 17279c56f4
commit b4672929dc
6 changed files with 94 additions and 0 deletions

View 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