| @@ -100,8 +100,7 @@ class ProjectsController < ApplicationController | |||
| end | |||
| def simple | |||
| project = Project.includes(:owner).select(:id, :name, :identifier, :user_id).find params[:id] | |||
| project = Project.includes(:owner, :repository).select(:id, :name, :identifier, :user_id, :project_type).find params[:id] | |||
| json_response(project) | |||
| end | |||
| @@ -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 | |||
| @@ -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, | |||
| @@ -29,7 +29,17 @@ module ProjectsHelper | |||
| end | |||
| def json_response(project) | |||
| json = { | |||
| repo = project.repository | |||
| tmp_json = {} | |||
| unless project.common? | |||
| tmp_json = tmp_json.merge({ | |||
| mirror_status: repo.mirror_status, | |||
| mirror_num: repo.mirror_num, | |||
| first_sync: repo.first_sync? | |||
| }) | |||
| end | |||
| tmp_json = tmp_json.merge({ | |||
| identifier: project.identifier, | |||
| name: project.name, | |||
| id: project.id, | |||
| @@ -38,7 +48,7 @@ module ProjectsHelper | |||
| name: project.owner.real_name, | |||
| image_url: url_to_avatar(project.owner) | |||
| } | |||
| } | |||
| render json: json | |||
| }).compact | |||
| render json: tmp_json | |||
| end | |||
| end | |||
| @@ -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 | |||
| @@ -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(",") | |||
| @@ -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) | |||
| @@ -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) | |||