webhook for issue

This commit is contained in:
chenjing
2023-04-06 17:00:43 +08:00
committed by yystopf
parent 91dfc94a7b
commit 769c8a0194
6 changed files with 201 additions and 5 deletions
+65 -2
View File
@@ -10,7 +10,7 @@ class TouchWebhookJob < ApplicationJob
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
@webhook_task = Webhook::EventClient.new(webhook, issue, sender,"issues","issues").do_request
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
end
when 'IssueUpdate'
@@ -20,7 +20,70 @@ class TouchWebhookJob < ApplicationJob
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
@webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "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::EventClient.new(webhook, issue, sender, "issues", "issue_assign",{assigner_ids: assigner_ids}).do_request
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
end
when 'IssueLable'
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::EventClient.new(webhook, issue, sender, "issues", "issue_label",{issue_tag_ids: issue_tag_ids}).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?
changes = {
id: comment.id,
user: comment.user.to_builder.target!,
body: comment.notes,
created_on: comment.created_on,
updated_on: comment.updated_on,
}
issue.project.webhooks.each do |webhook|
next unless webhook.events["events"]["issue_comment"]
@webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issue_comment", "issue_comment",changes.stringify_keys).do_request
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
end
when 'PullRequestComment'
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?
changes = {
id: comment.id,
user: comment.user.to_builder.target!,
body: comment.notes,
created_on: comment.created_on,
updated_on: comment.updated_on,
}
issue.project.webhooks.each do |webhook|
next unless webhook.events["events"]["pull_request_comment"]
@webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issue_comment", "pull_request_comment",changes.stringify_keys).do_request
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
end
end