76 lines
3.5 KiB
Ruby
76 lines
3.5 KiB
Ruby
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::IssueClient.new(webhook, issue, sender,"issues",).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::IssueClient.new(webhook, issue, sender, "issues", changes.stringify_keys).do_request
|
|
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
|
end
|
|
|
|
when 'IssueAssign'
|
|
issue_id, sender_id, assigner_ids = 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?
|
|
issue.project.webhooks.each do |webhook|
|
|
next unless webhook.events["events"]["issue_assign"]
|
|
_, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_assign",{assigner_ids: assigner_ids}.stringify_keys).do_request
|
|
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
|
end
|
|
|
|
when 'IssueLabel'
|
|
issue_id, sender_id, issue_tag_ids = 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?
|
|
issue.project.webhooks.each do |webhook|
|
|
next unless webhook.events["events"]["issue_label"]
|
|
_, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_label",{issue_tag_ids: issue_tag_ids}.stringify_keys).do_request
|
|
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
|
end
|
|
|
|
when 'IssueComment'
|
|
issue_id, sender_id, comment_id = args[0], args[1], args[2]
|
|
issue = Issue.find_by_id issue_id
|
|
comment = issue.comment_journals.find_by_id comment_id
|
|
sender = User.find_by_id sender_id
|
|
return if issue.nil? || sender.nil? || comment.nil?
|
|
|
|
issue.project.webhooks.each do |webhook|
|
|
next unless webhook.events["events"]["issue_comment"]
|
|
_, _, @webhook_task = Webhook::IssueCommentClient.new(webhook, issue, comment, sender, "issue_comment").do_request
|
|
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
|
end
|
|
|
|
when 'PullRequestComment'
|
|
pull_id, sender_id, comment_id = args[0], args[1], args[2]
|
|
pull = PullRequest.find_by_id pull_id
|
|
comment = pull.issue.comment_journals.find_by_id comment_id
|
|
sender = User.find_by_id sender_id
|
|
return if pull.nil? || sender.nil? || comment.nil?
|
|
|
|
pull.project.webhooks.each do |webhook|
|
|
next unless webhook.events["events"]["pull_request_comment"]
|
|
_, _, @webhook_task = Webhook::PullCommentClient.new(webhook, pull, comment, sender, "pull_request_comment").do_request
|
|
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
|
end
|
|
end
|
|
end
|
|
end |