forked from Gitlink/forgeplus
Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
commit
8c6d773dcd
|
@ -27,6 +27,7 @@ class PullRequestsController < ApplicationController
|
||||||
@all_branches = PullRequests::BranchesService.new(@user, @project).call
|
@all_branches = PullRequests::BranchesService.new(@user, @project).call
|
||||||
@is_fork = @project.forked_from_project_id.present?
|
@is_fork = @project.forked_from_project_id.present?
|
||||||
@projects_names = [{
|
@projects_names = [{
|
||||||
|
project_user_login: @user.try(:login),
|
||||||
project_name: "#{@user.try(:show_real_name)}/#{@repository.try(:identifier)}",
|
project_name: "#{@user.try(:show_real_name)}/#{@repository.try(:identifier)}",
|
||||||
project_id: @project.id
|
project_id: @project.id
|
||||||
}]
|
}]
|
||||||
|
@ -34,6 +35,7 @@ class PullRequestsController < ApplicationController
|
||||||
fork_project = @project.fork_project if @is_fork
|
fork_project = @project.fork_project if @is_fork
|
||||||
if fork_project.present?
|
if fork_project.present?
|
||||||
@merge_projects.push({
|
@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_name: "#{fork_project.owner.try(:show_real_name)}/#{fork_project.repository.try(:identifier)}",
|
||||||
project_id: fork_project.id
|
project_id: fork_project.id
|
||||||
})
|
})
|
||||||
|
@ -57,8 +59,16 @@ class PullRequestsController < ApplicationController
|
||||||
merge_params
|
merge_params
|
||||||
pull_issue = Issue.new(@issue_params)
|
pull_issue = Issue.new(@issue_params)
|
||||||
if pull_issue.save!
|
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
|
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
|
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 gitea_request && local_requests.update_attributes(gpid: gitea_request["number"])
|
||||||
if params[:issue_tag_ids].present?
|
if params[:issue_tag_ids].present?
|
||||||
|
@ -94,9 +104,9 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
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)
|
@fork_project_identifier = @project&.fork_project&.repository.try(:identifier)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@ -118,7 +128,7 @@ class PullRequestsController < ApplicationController
|
||||||
|
|
||||||
if @issue.update_attributes(@issue_params)
|
if @issue.update_attributes(@issue_params)
|
||||||
if @pull_request.update_attributes(@local_params.compact)
|
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 gitea_request
|
||||||
if params[:issue_tag_ids].present?
|
if params[:issue_tag_ids].present?
|
||||||
params[:issue_tag_ids].each do |tag|
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
@ -200,12 +210,13 @@ class PullRequestsController < ApplicationController
|
||||||
def check_can_merge
|
def check_can_merge
|
||||||
target_head = params[:head] #源分支
|
target_head = params[:head] #源分支
|
||||||
target_base = params[:base] #目标分支
|
target_base = params[:base] #目标分支
|
||||||
|
is_original = params[:is_original]
|
||||||
if target_head.blank? || target_base.blank?
|
if target_head.blank? || target_base.blank?
|
||||||
normal_status(-2, "请选择分支")
|
normal_status(-2, "请选择分支")
|
||||||
elsif target_head === target_base
|
elsif target_head === target_base && !is_original
|
||||||
normal_status(-2, "分支内容相同,无需创建合并请求")
|
normal_status(-2, "分支内容相同,无需创建合并请求")
|
||||||
else
|
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?
|
if can_merge.present?
|
||||||
render json: {
|
render json: {
|
||||||
status: -2,
|
status: -2,
|
||||||
|
@ -256,9 +267,7 @@ class PullRequestsController < ApplicationController
|
||||||
assignee: current_user.try(:login),
|
assignee: current_user.try(:login),
|
||||||
assignees: ["#{params[:assigned_login].to_s}"],
|
assignees: ["#{params[:assigned_login].to_s}"],
|
||||||
labels: params[:issue_tag_ids],
|
labels: params[:issue_tag_ids],
|
||||||
due_date: Time.now,
|
due_date: Time.now
|
||||||
fork_project_id: params[:fork_project_id],
|
|
||||||
is_original: params[:is_original]
|
|
||||||
})
|
})
|
||||||
@issue_params = {
|
@issue_params = {
|
||||||
author_id: current_user.id,
|
author_id: current_user.id,
|
||||||
|
|
|
@ -3,8 +3,13 @@ class PullRequest < ApplicationRecord
|
||||||
belongs_to :issue
|
belongs_to :issue
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :project, :counter_cache => true
|
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_assigns, foreign_key: :pull_request_id
|
||||||
has_many :pull_request_tags, 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 :project_trends, as: :trend, dependent: :destroy
|
||||||
has_many :attachments, as: :container, dependent: :destroy
|
has_many :attachments, as: :container, dependent: :destroy
|
||||||
|
|
||||||
|
def fork_project
|
||||||
|
Project.find_by(id: self.fork_project_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
json.partial! "commons/success"
|
json.partial! "commons/success"
|
||||||
# json.partial! "pull_requests/merge_item"
|
# 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_user @fork_project_user
|
||||||
json.fork_project_identifier @fork_project_identifier
|
json.fork_project_identifier @fork_project_identifier
|
||||||
json.project_author @project.owner.try(:show_real_name)
|
json.project_author @project.owner.try(:show_real_name)
|
||||||
json.project_name @project.repository.try(:identifier)
|
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! @pull_request, :id, :title, :body, :milestone,:head,:base,:is_original
|
||||||
json.extract! @issue, :assigned_to_id, :fixed_version_id, :priority_id
|
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(",")
|
||||||
|
|
|
@ -7,6 +7,7 @@ json.search_count @issues_size
|
||||||
json.limit @limit
|
json.limit @limit
|
||||||
json.user_admin_or_member @user_admin_or_member
|
json.user_admin_or_member @user_admin_or_member
|
||||||
json.project_name @project.name
|
json.project_name @project.name
|
||||||
|
json.project_author_name @project.owner.try(:login)
|
||||||
|
|
||||||
json.issues do
|
json.issues do
|
||||||
json.array! @issues.to_a do |issue|
|
json.array! @issues.to_a do |issue|
|
||||||
|
@ -17,9 +18,10 @@ json.issues do
|
||||||
json.pull_request_base pr.base
|
json.pull_request_base pr.base
|
||||||
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
|
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
|
||||||
json.is_original pr.is_original
|
json.is_original pr.is_original
|
||||||
json.fork_project_id pr.fork_project_id
|
json.fork_project_id pr&.fork_project_id
|
||||||
json.pull_request_user pr.user.try(:show_real_name)
|
json.fork_project_user pr&.fork_project&.owner.try(:login)
|
||||||
|
|
||||||
|
|
||||||
json.id issue.id
|
json.id issue.id
|
||||||
json.name issue.subject
|
json.name issue.subject
|
||||||
json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on)
|
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.pull_request do
|
||||||
json.extract! @pull_request, :id,:base, :head, :status,:fork_project_id, :is_original
|
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_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
|
end
|
||||||
|
|
||||||
json.issue do
|
json.issue do
|
||||||
json.extract! @issue, :id,:subject,:description,:is_private, :branch_name
|
json.extract! @issue, :id,:subject,:description,:is_private, :branch_name
|
||||||
|
json.project_author_name @project.owner.try(:login)
|
||||||
json.user_permission @user_permission
|
json.user_permission @user_permission
|
||||||
json.closed_on @issue.closed_on.present? ? format_time(@issue.closed_on) : ""
|
json.closed_on @issue.closed_on.present? ? format_time(@issue.closed_on) : ""
|
||||||
json.created_at format_time(@issue.created_on)
|
json.created_at format_time(@issue.created_on)
|
||||||
|
|
Loading…
Reference in New Issue