From 1727435aa69c1a8dd064291e620490d55c4fb1a6 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 11:58:31 +0800 Subject: [PATCH] add pull request state --- app/models/organization.rb | 2 +- app/models/pull_request.rb | 3 ++- app/models/user_cla.rb | 13 +++++++++++++ app/services/pull_requests/send_journal_service.rb | 4 +++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 5c3ce6d2b..cd533d32d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -109,7 +109,7 @@ class Organization < Owner def is_sign?(user_id) 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 def cla_sign_email(user_id) diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index e46777951..0142f27f6 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -24,10 +24,11 @@ # class PullRequest < ApplicationRecord - #status 0 默认未合并, 1表示合并, 2表示请求拒绝(或已关闭) + #status 0 默认未合并, 1表示合并, 2表示请求拒绝(或已关闭) ,3 表示未签署CLA OPEN = 0 MERGED = 1 CLOSED = 2 + NEEDCLA = 3 belongs_to :issue belongs_to :user diff --git a/app/models/user_cla.rb b/app/models/user_cla.rb index 005533ce7..cd3cea8a8 100644 --- a/app/models/user_cla.rb +++ b/app/models/user_cla.rb @@ -26,6 +26,10 @@ class UserCla < ApplicationRecord cla.fresh_count end + before_save do + fresh_pull_request + end + def self.build(params,user_id) self.create!(user_id: user_id, cla_id: params[:cla_id], @@ -35,4 +39,13 @@ class UserCla < ApplicationRecord ) 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 diff --git a/app/services/pull_requests/send_journal_service.rb b/app/services/pull_requests/send_journal_service.rb index 67cc6ca89..816b13f11 100644 --- a/app/services/pull_requests/send_journal_service.rb +++ b/app/services/pull_requests/send_journal_service.rb @@ -2,7 +2,8 @@ class PullRequests::SendJournalService < ApplicationService def initialize(project, pull_request,current_user) @project = project - @issue = pull_request + @pull_request = pull_request + @issue = pull_request.issue @current_user = current_user @org = project.owner end @@ -23,6 +24,7 @@ class PullRequests::SendJournalService < ApplicationService } journal = Journal.new journal_params if journal.save + @pull_request.update_attributes(status: 3) 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 end