更改:webhook更新返回结构体
This commit is contained in:
parent
f64afb8f55
commit
4bd60d458e
|
@ -27,7 +27,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController
|
|||
end
|
||||
|
||||
def destroy
|
||||
TouchWebhookJob.perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
if @journal.destroy!
|
||||
render_ok
|
||||
else
|
||||
|
|
|
@ -62,7 +62,7 @@ class JournalsController < ApplicationController
|
|||
|
||||
def destroy
|
||||
if @journal.destroy #如果有子评论,子评论删除吗?
|
||||
TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
Journal.children_journals(@journal.id).destroy_all
|
||||
normal_status(0, "评论删除成功")
|
||||
else
|
||||
|
|
|
@ -25,24 +25,24 @@ class TouchWebhookJob < ApplicationJob
|
|||
end
|
||||
|
||||
when 'IssueAssign'
|
||||
issue_id, sender_id, assigner_ids = args[0], args[1], args[2]
|
||||
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?
|
||||
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
|
||||
_, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_assign", changes.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_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?
|
||||
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
|
||||
_, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_label", changes.stringify_keys).do_request
|
||||
Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}"
|
||||
end
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ class Api::V1::Issues::CreateService < ApplicationService
|
|||
|
||||
# 触发webhook
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id)
|
||||
TouchWebhookJob.perform_later('IssueLabel', @created_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.blank?
|
||||
TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, current_user.id, assigner_ids) unless assigner_ids.blank?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank?
|
||||
unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁
|
||||
end
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService
|
|||
|
||||
# @信息发送
|
||||
AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank?
|
||||
TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.slice(:notes).stringify_keys)
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.slice(:notes).stringify_keys)
|
||||
|
||||
unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}")
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
|||
|
||||
attr_reader :project, :issue, :current_user
|
||||
attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description
|
||||
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login
|
||||
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids
|
||||
attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers
|
||||
|
||||
validates :project, :issue, :current_user, presence: true
|
||||
|
@ -24,6 +24,8 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
|||
@description = params[:description]
|
||||
@issue_tag_ids = params[:issue_tag_ids]
|
||||
@assigner_ids = params[:assigner_ids]
|
||||
@before_issue_tag_ids = issue.issue_tags.pluck(:id)
|
||||
@before_assigner_ids = issue.assigners.pluck(:id)
|
||||
@attachment_ids = params[:attachment_ids]
|
||||
@receivers_login = params[:receivers_login]
|
||||
@add_assigner_ids = []
|
||||
|
@ -78,9 +80,10 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
|||
end
|
||||
|
||||
# 触发webhook
|
||||
TouchWebhookJob.perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id))
|
||||
TouchWebhookJob.perform_later('IssueLabel', @updated_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.nil?
|
||||
TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, current_user.id, assigner_ids) unless assigner_ids.nil?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id))
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil?
|
||||
|
||||
unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}")
|
||||
|
||||
return @updated_issue
|
||||
|
|
|
@ -42,6 +42,30 @@ class Webhook::IssueClient
|
|||
"sender": JSON.parse(@sender.to_builder.target!)
|
||||
}
|
||||
else
|
||||
if @changes.has_key?("status_id")
|
||||
before_status = IssueStatus.find_by_id(@changes["status_id"][0])
|
||||
after_status = IssueStatus.find_by_id(@changes["status_id"][1])
|
||||
@changes["status"] = []
|
||||
@changes["status"].append(before_status.present? ? JSON.parse(before_status.to_builder.target!) : {})
|
||||
@changes["status"].append(after_status.present? ? JSON.parse(after_status.to_builder.target!) : {})
|
||||
@changes.delete("status_id")
|
||||
end
|
||||
if @changes.has_key?("fixed_version_id")
|
||||
before_milestone = Version.find_by_id(@changes["fixed_version_id"][0])
|
||||
after_milestone = Version.find_by_id(@changes["fixed_version_id"][1])
|
||||
@changes["milestone"] = []
|
||||
@changes["milestone"].append(before_milestone.present? ? JSON.parse(before_milestone.to_builder.target!) : {})
|
||||
@changes["milestone"].append(after_milestone.present? ? JSON.parse(after_milestone.to_builder.target!) : {})
|
||||
@changes.delete("fixed_version_id")
|
||||
end
|
||||
if @changes.has_key?("priority_id")
|
||||
before_priority = IssuePriority.find_by_id(@changes["priority_id"][0])
|
||||
after_priority = IssuePriority.find_by_id(@changes["priority_id"][1])
|
||||
@changes["priority"] = []
|
||||
@changes["priority"].append(before_priority.present? ? JSON.parse(before_priority.to_builder.target!) : {})
|
||||
@changes["priority"].append(after_priority.present? ? JSON.parse(after_priority.to_builder.target!) : {})
|
||||
@changes.delete("priority_id")
|
||||
end
|
||||
{
|
||||
"action": "edited",
|
||||
"number": @issue.project_issues_index,
|
||||
|
@ -54,8 +78,16 @@ class Webhook::IssueClient
|
|||
end
|
||||
|
||||
def issue_assign_payload_content
|
||||
if @changes.has_key?("assigner_ids")
|
||||
before_assigners = User.where(id: @changes["assigner_ids"][0])
|
||||
after_assigners = User.where(id: @changes["assigner_ids"][1])
|
||||
@changes["assigners"] = []
|
||||
@changes["assigners"].append(before_assigners.blank? ? [] : before_assigners.map{|a|JSON.parse(a.to_buidler.target!)})
|
||||
@changes["assigners"].append(after_assigners.blank? ? [] : after_assigners.map{|a|JSON.parse(a.to_builder.target!)})
|
||||
@changes.delete("assigner_ids")
|
||||
end
|
||||
{
|
||||
"action": @changes["assigner_ids"].blank? ? "unassigned" : "assigned",
|
||||
"action": @changes["assigners"].blank? ? "unassigned" : "assigned",
|
||||
"number": @issue.project_issues_index,
|
||||
"issue": JSON.parse(@issue.to_builder.target!),
|
||||
"project": JSON.parse(@issue.project.to_builder.target!),
|
||||
|
@ -64,8 +96,17 @@ class Webhook::IssueClient
|
|||
end
|
||||
|
||||
def issue_label_payload_content
|
||||
if @changes.has_key?("issue_tag_ids")
|
||||
before_issue_tags = IssueTag.where(id: @changes["issue_tag_ids"][0])
|
||||
after_issue_tags = IssueTag.where(id: @changes["issue_tag_ids"][1])
|
||||
@changes["issue_tags"] = []
|
||||
@changes["issue_tags"].append(before_issue_tags.blank? ? [] : before_issue_tags.map{|t|JSON.parse(t.to_builder.target!)})
|
||||
@changes["issue_tags"].append(after_issue_tags.blank? ? [] : after_issue_tags.map{|t|JSON.parse(t.to_builder.target!)})
|
||||
@changes.delete("issue_tag_ids")
|
||||
end
|
||||
{
|
||||
"action": @changes["issue_tag_ids"].blank? ? "label_cleared" : "label_updated",
|
||||
"action": @changes["issue_tags"].blank? ? "label_cleared" : "label_updated",
|
||||
"changes": @changes,
|
||||
"number": @issue.project_issues_index,
|
||||
"issue": JSON.parse(@issue.to_builder.target!),
|
||||
"project": JSON.parse(@issue.project.to_builder.target!),
|
||||
|
|
Loading…
Reference in New Issue