diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index a4d802e09..097bfc5c4 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -27,6 +27,7 @@ class PullRequestsController < ApplicationController @all_branches = PullRequests::BranchesService.new(@user, @project).call @is_fork = @project.forked_from_project_id.present? @projects_names = [{ + project_user_login: @user.try(:login), project_name: "#{@user.try(:show_real_name)}/#{@repository.try(:identifier)}", project_id: @project.id }] @@ -34,6 +35,7 @@ class PullRequestsController < ApplicationController fork_project = @project.fork_project if @is_fork if fork_project.present? @merge_projects.push({ + project_user_login: fork_project.owner.try(:login), project_name: "#{fork_project.owner.try(:show_real_name)}/#{fork_project.repository.try(:identifier)}", project_id: fork_project.id }) @@ -57,8 +59,16 @@ class PullRequestsController < ApplicationController merge_params pull_issue = Issue.new(@issue_params) if pull_issue.save! - local_requests = PullRequest.new(@local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: pull_issue.id)) + pr_params = { + user_id: current_user.try(:id), + project_id: @project.id, + issue_id: pull_issue.id, + fork_project_id: params[:fork_project_id], + is_original: params[:is_original] + } + local_requests = PullRequest.new(@local_params.merge(pr_params)) if local_requests.save + @requests_params.merge!(head: "#{params[:merge_user_login]}:#{params[:head]}") if local_requests.is_original && params[:merge_user_login] gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @project.owner, @repository.try(:identifier), @requests_params).call if gitea_request && local_requests.update_attributes(gpid: gitea_request["number"]) if params[:issue_tag_ids].present? @@ -94,9 +104,9 @@ class PullRequestsController < ApplicationController end def edit - @fork_project_user = @project&.fork_project&.owner.try(:show_real_name) + @fork_project_user_name = @project&.fork_project&.owner.try(:show_real_name) + @fork_project_user = @project&.fork_project&.owner.try(:login) @fork_project_identifier = @project&.fork_project&.repository.try(:identifier) - end def update @@ -118,7 +128,7 @@ class PullRequestsController < ApplicationController if @issue.update_attributes(@issue_params) if @pull_request.update_attributes(@local_params.compact) - gitea_request = Gitea::PullRequest::UpdateService.new(current_user, @repository.try(:identifier), @requests_params, @pull_request.try(:gpid)).call + gitea_request = Gitea::PullRequest::UpdateService.new(@project.owner, @repository.try(:identifier), @requests_params, @pull_request.try(:gpid)).call if gitea_request if params[:issue_tag_ids].present? params[:issue_tag_ids].each do |tag| @@ -200,12 +210,13 @@ class PullRequestsController < ApplicationController def check_can_merge target_head = params[:head] #源分支 target_base = params[:base] #目标分支 + is_original = params[:is_original] if target_head.blank? || target_base.blank? normal_status(-2, "请选择分支") - elsif target_head === target_base + elsif target_head === target_base && !is_original normal_status(-2, "分支内容相同,无需创建合并请求") else - can_merge = @project&.pull_requests.where(user_id: current_user&.id, head: target_head, base: target_base, status: 0) + can_merge = @project&.pull_requests.where(user_id: current_user&.id, head: target_head, base: target_base, status: 0, is_original: is_original, fork_project_id: params[:fork_project_id]) if can_merge.present? render json: { status: -2, @@ -256,9 +267,7 @@ class PullRequestsController < ApplicationController assignee: current_user.try(:login), assignees: ["#{params[:assigned_login].to_s}"], labels: params[:issue_tag_ids], - due_date: Time.now, - fork_project_id: params[:fork_project_id], - is_original: params[:is_original] + due_date: Time.now }) @issue_params = { author_id: current_user.id, diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 7445cc518..d752bb859 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -3,8 +3,13 @@ class PullRequest < ApplicationRecord belongs_to :issue belongs_to :user belongs_to :project, :counter_cache => true + # belongs_to :fork_project, foreign_key: :fork_project_id has_many :pull_request_assigns, foreign_key: :pull_request_id has_many :pull_request_tags, foreign_key: :pull_request_id has_many :project_trends, as: :trend, dependent: :destroy has_many :attachments, as: :container, dependent: :destroy + + def fork_project + Project.find_by(id: self.fork_project_id) + end end diff --git a/app/views/pull_requests/edit.json.jbuilder b/app/views/pull_requests/edit.json.jbuilder index aad5c26b0..2e91aa530 100644 --- a/app/views/pull_requests/edit.json.jbuilder +++ b/app/views/pull_requests/edit.json.jbuilder @@ -1,9 +1,11 @@ json.partial! "commons/success" # json.partial! "pull_requests/merge_item" +json.fork_project_user_name @fork_project_user_name json.fork_project_user @fork_project_user json.fork_project_identifier @fork_project_identifier json.project_author @project.owner.try(:show_real_name) json.project_name @project.repository.try(:identifier) +json.project_login @project.owner.try(:login) json.extract! @pull_request, :id, :title, :body, :milestone,:head,:base,:is_original json.extract! @issue, :assigned_to_id, :fixed_version_id, :priority_id -json.issue_tag_ids @issue.issue_tags_value.split(",") +json.issue_tag_ids @issue&.issue_tags_value&.split(",") diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index 5b46c77e3..c36bfe1da 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -7,6 +7,7 @@ json.search_count @issues_size json.limit @limit json.user_admin_or_member @user_admin_or_member json.project_name @project.name +json.project_author_name @project.owner.try(:login) json.issues do json.array! @issues.to_a do |issue| @@ -17,9 +18,10 @@ json.issues do json.pull_request_base pr.base json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open") json.is_original pr.is_original - json.fork_project_id pr.fork_project_id - json.pull_request_user pr.user.try(:show_real_name) + json.fork_project_id pr&.fork_project_id + json.fork_project_user pr&.fork_project&.owner.try(:login) + json.id issue.id json.name issue.subject json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on) diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index a294b91c3..0c497d6c7 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -5,11 +5,12 @@ json.pr_time time_from_now(@pull_request.updated_at) json.pull_request do json.extract! @pull_request, :id,:base, :head, :status,:fork_project_id, :is_original json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open") - json.pull_request_user @pull_request.user.try(:show_real_name) + json.fork_project_user @pull_request&.fork_project&.owner.try(:login) end json.issue do json.extract! @issue, :id,:subject,:description,:is_private, :branch_name + json.project_author_name @project.owner.try(:login) json.user_permission @user_permission json.closed_on @issue.closed_on.present? ? format_time(@issue.closed_on) : "" json.created_at format_time(@issue.created_on)