45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
class Webhook::IssueCommentClient
|
|
|
|
include Webhook::Client
|
|
|
|
attr_accessor :webhook, :issue, :journal, :sender, :event, :action_type, :comment_json
|
|
|
|
def initialize(webhook, issue, journal, sender, event, action_type, comment_json={})
|
|
@webhook = webhook
|
|
@issue = issue.reload
|
|
@journal = journal.reload
|
|
@sender = sender.reload
|
|
@event = event
|
|
@action_type = action_type
|
|
@comment_json = comment_json
|
|
|
|
# 构建client参数
|
|
super({
|
|
uuid: SecureRandom.uuid,
|
|
event: @event,
|
|
webhook: @webhook,
|
|
payload_content: payload_content
|
|
})
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def payload_content
|
|
payload_content = {
|
|
"action": @action_type,
|
|
"issue": JSON.parse(@issue.to_builder.target!),
|
|
"journal": @journal.present? ? JSON.parse(@journal.to_builder.target!) : @comment_json,
|
|
"project": JSON.parse(@issue.project.to_builder.target!),
|
|
"sender": JSON.parse(@sender.to_builder.target!),
|
|
"is_pull": false
|
|
}
|
|
|
|
payload_content.merge!({
|
|
"changes": @comment_json,
|
|
}) if @action_type == "edited"
|
|
|
|
payload_content
|
|
end
|
|
end |