新增:评论丰富更新删除操作,issue事件粒度更细

This commit is contained in:
2023-04-11 11:52:03 +08:00
parent 7f0989f69d
commit afa1cdf842
10 changed files with 50 additions and 26 deletions

View File

@@ -2,14 +2,16 @@ class Webhook::IssueCommentClient
include Webhook::Client
attr_accessor :webhook, :issue, :journal, :sender, :event
attr_accessor :webhook, :issue, :journal, :sender, :event, :action_type, :comment_json
def initialize(webhook, issue, journal, sender, event)
def initialize(webhook, issue, journal, sender, event, action_type, comment_json={})
@webhook = webhook
@issue = issue
@journal = journal
@sender = sender
@event = event
@action_type = action_type
@comment_json = comment_json
# 构建client参数
super({
@@ -25,13 +27,19 @@ class Webhook::IssueCommentClient
private
def payload_content
{
"action": "created",
payload_content = {
"action": @action_type,
"issue": JSON.parse(@issue.to_builder.target!),
"journal": JSON.parse(@journal.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

View File

@@ -1,15 +1,16 @@
class Webhook::PullCommentClient
include Webhook::Client
attr_accessor :webhook, :pull, :journal, :sender, :event
attr_accessor :webhook, :pull, :journal, :sender, :event, :action_type, :comment_json
def initialize(webhook, pull, journal, sender, event)
def initialize(webhook, pull, journal, sender, event, action_type='created', comment_json={})
@webhook = webhook
@pull = pull
@journal = journal
@sender = sender
@event = event
@action_type = action_type
@comment_json = comment_json
# 构建client参数
super({
uuid: SecureRandom.uuid,
@@ -22,15 +23,21 @@ class Webhook::PullCommentClient
private
def payload_content
{
"action": "created",
payload_content = {
"action": @action_type,
"number": @pull.gitea_number,
"pull_request": JSON.parse(@pull.to_builder.target!),
"comment": JSON.parse(@journal.to_builder.target!),
"comment": @journal.present? ? JSON.parse(@journal.to_builder.target!) : @comment_json,
"project": JSON.parse(@pull.project.to_builder.target!),
"sender": JSON.parse(@sender.to_builder.target!),
"is_pull": true
}
payload_content.merge!({
"changes": @comment_json
}) if @action_type == "edited"
payload_content
end
end