add pull request state

This commit is contained in:
chenjing 2023-06-16 11:58:31 +08:00
parent a04e0508d6
commit 1727435aa6
4 changed files with 19 additions and 3 deletions

View File

@ -109,7 +109,7 @@ class Organization < Owner
def is_sign?(user_id) def is_sign?(user_id)
return false if cla.nil? return false if cla.nil?
cla.user_clas.where(user_id: user_id).present? cla.user_clas.where(user_id: user_id, status: 1).present?
end end
def cla_sign_email(user_id) def cla_sign_email(user_id)

View File

@ -24,10 +24,11 @@
# #
class PullRequest < ApplicationRecord class PullRequest < ApplicationRecord
#status 0 默认未合并, 1表示合并, 2表示请求拒绝(或已关闭) #status 0 默认未合并, 1表示合并, 2表示请求拒绝(或已关闭) ,3 表示未签署CLA
OPEN = 0 OPEN = 0
MERGED = 1 MERGED = 1
CLOSED = 2 CLOSED = 2
NEEDCLA = 3
belongs_to :issue belongs_to :issue
belongs_to :user belongs_to :user

View File

@ -26,6 +26,10 @@ class UserCla < ApplicationRecord
cla.fresh_count cla.fresh_count
end end
before_save do
fresh_pull_request
end
def self.build(params,user_id) def self.build(params,user_id)
self.create!(user_id: user_id, self.create!(user_id: user_id,
cla_id: params[:cla_id], cla_id: params[:cla_id],
@ -35,4 +39,13 @@ class UserCla < ApplicationRecord
) )
end end
def fresh_pull_request
gitea_ids = Project.where(user_id: cla.user_id).pluck(:gpid)
if state == "signed"
PullRequest.where(user_id: user_id, gitea_id: gitea_ids, status:3).update_all(status:0)
else
PullRequest.where(user_id: user_id, gitea_id: gitea_ids, status:0).update_all(status:3)
end
end
end end

View File

@ -2,7 +2,8 @@ class PullRequests::SendJournalService < ApplicationService
def initialize(project, pull_request,current_user) def initialize(project, pull_request,current_user)
@project = project @project = project
@issue = pull_request @pull_request = pull_request
@issue = pull_request.issue
@current_user = current_user @current_user = current_user
@org = project.owner @org = project.owner
end end
@ -23,6 +24,7 @@ class PullRequests::SendJournalService < ApplicationService
} }
journal = Journal.new journal_params journal = Journal.new journal_params
if journal.save if journal.save
@pull_request.update_attributes(status: 3)
TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, sender_id, journal.id, 'created', {}) TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, sender_id, journal.id, 'created', {})
push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? && @project.use_blockchain push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? && @project.use_blockchain
end end