Browse Source

update pr model and webhook

pull/342/head
chenjing yystopf 3 years ago
parent
commit
39c2166c12
2 changed files with 24 additions and 5 deletions
  1. +2
    -2
      app/jobs/touch_webhook_job.rb
  2. +22
    -3
      app/models/pull_request.rb

+ 2
- 2
app/jobs/touch_webhook_job.rb View File

@@ -60,8 +60,8 @@ class TouchWebhookJob < ApplicationJob
end

when 'PullRequestComment'
pull_id, sender_id, comment_id = args[0], args[1], args[2]
pull = PullRequest.find_by_id pull_id
issue_id, sender_id, comment_id = args[0], args[1], args[2]
pull = Issue.find_by_id(issue_id).try(:pull_request)
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?


+ 22
- 3
app/models/pull_request.rb View File

@@ -119,16 +119,35 @@ class PullRequest < ApplicationRecord
end

def to_builder
Jbuilder.new do |pull|
Jbuilder.new do |pull|
pull.(self, :id, :gitea_number, :title, :body, :base, :head, :is_original, :comments_count)
pull.created_at self.created_at.strftime("%Y-%m-%d %H:%M")
pull.updated_at self.updated_at.strftime("%Y-%m-%d %H:%M")
pull.user self.user.to_builder
if self.fork_project.present?
pull.fork_project self.fork_project.to_builder
else
pull.fork_project nil
end
pull.created_at self.created_at.strftime("%Y-%m-%d %H:%M")
pull.updated_at self.updated_at.strftime("%Y-%m-%d %H:%M")
pull.status self.pr_status
pull.url self.pr_url
end
end

def pr_url
return nil if self.project.nil?
"#{Rails.application.config_for(:configuration)['platform_url']}/#{self.project.owner.login}/#{self.project.name}/pulls/#{self.id}"
end

def pr_status
case status
when 0
"OPEN"
when 1
"MERGED"
when 2
"CLOSED"
end
end

end

Loading…
Cancel
Save