From 6dda125a1cb6b350708dd74437fdfaa0ebd33f83 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 17 Jul 2024 14:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=89=E5=90=88=E5=B9=B6=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 9 +++++++++ app/views/api/v1/projects/branches/index.json.jbuilder | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 04aa1bce..ba0cab97 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -462,6 +462,15 @@ class Project < ApplicationRecord EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false end + def has_pull_request(branch_name) + return true if self.pull_requests.opening.where(head: branch_name).present? || self.pull_requests.opening.where(base: branch_name).present? + if self.forked_from_project_id.present? + return true if self.fork_project.pull_requests.opening.where(head: branch_name).present? || self.fork_project.pull_requests.opening.where(base: branch_name).present? + end + + return false + end + def self.mindspore_contributors cache_result = $redis_cache.get("ProjectMindsporeContributors") if cache_result.nil? diff --git a/app/views/api/v1/projects/branches/index.json.jbuilder b/app/views/api/v1/projects/branches/index.json.jbuilder index 80b3e4d0..ec854669 100644 --- a/app/views/api/v1/projects/branches/index.json.jbuilder +++ b/app/views/api/v1/projects/branches/index.json.jbuilder @@ -1,5 +1,5 @@ json.total_count @result_object[:total_data].to_i json.branches @result_object[:data].each do |branch| json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: branch, default_branch: @result_object[:default_branch] - + json.has_pull_request @project.has_pull_request(branch['name']) end \ No newline at end of file