Change Create PullRequest

dev_local_lzdx
sylor_huang@126.com 4 years ago
parent 00dc4905a3
commit 08054652e0

@ -95,39 +95,45 @@ class PullRequestsController < ApplicationController
source_branch = params[:source_branch]
target_branch = params[:target_branch]
target_project_id = params[:target_project_id]
@fork_pr_message = false
begin
# 如果分支有改动
if compare_pull_request(source_branch, target_project_id, target_branch)
# 如果传送了目标项目ID即向fork源项目发送请求
# if params[:forked_project_id] && params[:source_project] == "forked_project_name"
pro = Project.find(@project.forked_from_project_id)
pro = Project.find(@project.forked_from_project_id) unless @project.forked_from_project_id.nil?
if !params[:target_project_id].blank? && params[:target_project_id].to_i != @project.id
target_project_id = params[:forked_project_id].to_i
request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch, :target_project_id => target_project_id)
@request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch, :target_project_id => target_project_id)
@fork_project_name = Project.find(params[:target_project_id]).try(:name)
@fork_pr_message = true if @fork_project_name
# 向管理员发送消息
# send_message_to_manager(params[:target_project_id].to_i, request.id, 1)
pq = PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id, :title => title)
pq = PullRequest.create!(:pull_request_id => @request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id, :title => title, :gpid => @project.gpid)
pro.managers.each do |manage|
Tiding.create(:user_id => manage.user_id, :trigger_user_id => User.current.id, :container_id => pq.id, :container_type => "PullRequest", :status => 0, :parent_container_id => @project.forked_from_project_id, :parent_container_type => "Project" ,:belong_container_id => @project.id, :belong_container_type => "Project", :viewed => 0, :tiding_type => "Apply")
end
else
@project_member = Member.where(:project_id => @project.id)
request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch)
@request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch)
# 发送消息
# send_message_to_manager(@project.id, request.id, 1)
# 创建Trustie数据
pq = PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id, :title => title)
pq = PullRequest.create!(:pull_request_id => @request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id, :title => title, :gpid => @project.gpid)
@fork_pr_message = true if pq
pro.managers.each do |manage|
Tiding.create(:user_id => manage.user_id, :trigger_user_id => User.current.id, :container_id => pq.id, :container_type => "PullRequest", :status => 0, :parent_container_id => @project.forked_from_project_id, :parent_container_type => "Project" ,:belong_container_id => @project.id, :belong_container_type => "Project", :viewed => 0, :tiding_type => "Apply")
end
respond_to do |format|
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
end
# redirect_to project_pull_request_path(request.id, :project_id => @project.id)
end
respond_to do |format|
format.js
# format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
end
else
tip = 1
# render :new
# redirect_to new_project_pull_request_path(:show_tip => tip)
respond_to do |format|
format.js{redirect_to new_project_pull_request_path(:show_tip => tip)}
end
@ -139,7 +145,8 @@ class PullRequestsController < ApplicationController
rescue Gitlab::Error::NotFound => e
@message = l(:label_pull_request_notfound)
rescue Exception => e
puts e
@message = e
# puts e
end
end
@ -147,21 +154,23 @@ class PullRequestsController < ApplicationController
# 判断源分支和目标分支是否有改动
# status 为true 表示有改动; false:便是没有改动
def compare_pull_request source_branch, target_project, target_branch
user_name_source = @project.owner.try(:login)
identifier = @repository.identifier.downcase
git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git'
target_lastest_commit_id = @g.commits(@project.gpid, ref_name: target_branch).first.try(:id)
if target_project
forked_source_project = Project.find(target_project)
user_name_target = forked_source_project.owner.try(:login)
git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git'
git_sourse_commit_id = @g.commits(@project.gpid, :ref_name => source_branch).first.try(:id)
git_target_commit_id = @g.commits(forked_source_project.gpid, :ref_name => target_branch).first.try(:id)
# user_name_target = forked_source_project.owner.try(:login)
# git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git'
# git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch)
# git_target_commit_id = @g.get_branch_commit_id(forked_source_project.gpid, git_target_tree, target_branch)
source_latest_commit_id = @g.commits(forked_source_project.gpid, ref_name: source_branch).first.try(:id)
else
git_sourse_commit_id = @g.commits(@project.gpid, :ref_name => source_branch).first.try(:id)
git_target_commit_id = @g.commits(@project.gpid, :ref_name => target_branch).first.try(:id)
# git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch)
# git_target_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, target_branch)
source_latest_commit_id = @g.commits(@project.gpid, ref_name: source_branch).first.try(:id)
end
git_sourse_commit_id.to_s != git_target_commit_id.to_s
# status = (git_sourse_commit_id.try(:commit_id) == git_target_commit_id.try(:commit_id) ? false : true)
target_lastest_commit_id != source_latest_commit_id
end
# @project_menu_type 为了控制base顶部导航

@ -1 +1,9 @@
$("#create_pull_request_error").html('<%= escape_javascript(render :partial => "pull_requests/error_message") %>');
<% if @fork_pr_message %>
window.location.href = "<%= project_pull_request_path(@project.id, @request.id) %>";
$("#create_pull_request_error").html('<div class="flash notice">您的Pull Request请求已成功发送至源项目<%= @fork_project_name %></div>');
<% else %>
$("#create_pull_request_error").html('<div class="flash error"><%= @message %></div>');
<% end %>

Loading…
Cancel
Save