pull request 使用优化
This commit is contained in:
parent
f87d1ce3bd
commit
6584cd88f1
|
@ -47,10 +47,11 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# 主要取源项目和目标项目分支及标识(用户名/版本库名)
|
# 主要取源项目和目标项目分支及标识(用户名/版本库名)
|
||||||
|
# @tip 为空的时候表明发送的pr请求有改动,为1的时候源分支和目标分支没有改动,则不能成功创建
|
||||||
def new
|
def new
|
||||||
# project_menu_type 为了控制base顶部导航
|
# project_menu_type 为了控制base顶部导航
|
||||||
@project_menu_type = 6
|
@project_menu_type = 6
|
||||||
|
@tip = params[:show_tip]
|
||||||
identifier = get_rep_identifier_by_project @project
|
identifier = get_rep_identifier_by_project @project
|
||||||
@source_project_name = "#{get_user_name(@project.user_id)}/#{identifier}"
|
@source_project_name = "#{get_user_name(@project.user_id)}/#{identifier}"
|
||||||
@source_rev = @g.branches(@project.gpid).map{|b| b.name}
|
@source_rev = @g.branches(@project.gpid).map{|b| b.name}
|
||||||
|
@ -102,9 +103,9 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@tip = 1
|
tip = 1
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js{redirect_to new_project_pull_request_path}
|
format.js{redirect_to new_project_pull_request_path(:show_tip => tip)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -120,25 +121,16 @@ class PullRequestsController < ApplicationController
|
||||||
identifier = @repository.identifier.downcase
|
identifier = @repository.identifier.downcase
|
||||||
git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git'
|
git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git'
|
||||||
if target_project
|
if target_project
|
||||||
user_name_target = Project.find(target_project).owner.try(:login)
|
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_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git'
|
||||||
# git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git'
|
|
||||||
# remote 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_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch)
|
||||||
git_target_commit_id = @g.get_branch_commit_id(user_name_source.gpid, git_target_tree, target_branch)
|
git_target_commit_id = @g.get_branch_commit_id(forked_source_project.gpid, git_target_tree, target_branch)
|
||||||
|
|
||||||
##############
|
|
||||||
# git_sourse_commit_id = `git #{git_source_tree} log #{source_branch} --pretty=oneline -1`
|
|
||||||
# git_target_commit_id = `git #{git_target_tree} log #{target_branch} --pretty=oneline -1`
|
|
||||||
# git_target_commit_id = `--git rev-parse #{target_branch}`
|
|
||||||
# 员项目的源分支和目标项目的目标分支的commit_id如果相同则没有改动
|
|
||||||
status = git_sourse_commit_id == git_target_commit_id ? false : true
|
|
||||||
else
|
else
|
||||||
reuslt = `git #{git_source_tree} log --pretty=oneline #{source_branch} ^#{target_branch}`
|
git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch)
|
||||||
status = result.blank? ? false : true
|
git_target_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, target_branch)
|
||||||
end
|
end
|
||||||
status
|
status = (git_sourse_commit_id.try(:commit_id) == git_target_commit_id.try(:commit_id) ? false : true)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @project_menu_type 为了控制base顶部导航
|
# @project_menu_type 为了控制base顶部导航
|
||||||
|
|
|
@ -67,41 +67,41 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function regex_branch()
|
// function regex_branch()
|
||||||
{
|
// {
|
||||||
var source_branch = $.trim($("#source_branch").val());
|
// var source_branch = $.trim($("#source_branch").val());
|
||||||
var target_branch = $.trim($("#pull_request_branch").val());
|
// var target_branch = $.trim($("#pull_request_branch").val());
|
||||||
var target_project = $.trim($("#target_project_id").children().attr("name"));
|
// var target_project = $.trim($("#target_project_id").children().attr("name"));
|
||||||
var target_forked_project = $.trim($("#pull_request_project_hidden").text());
|
// var target_forked_project = $.trim($("#pull_request_project_hidden").text());
|
||||||
if(target_project == target_forked_project && source_branch == target_branch)
|
// if(target_project == target_forked_project && source_branch == target_branch)
|
||||||
{
|
// {
|
||||||
$("#pull_request_branch_error").show();
|
// $("#pull_request_branch_error").show();
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
$("#pull_request_branch_error").hide();
|
// $("#pull_request_branch_error").hide();
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function compare_can_create(){
|
// function compare_can_create(){
|
||||||
var compare_result = $.trim($("#pull_request_compare_result").text());
|
// var compare_result = $.trim($("#pull_request_compare_result").text());
|
||||||
alert(compare_result);
|
// alert(compare_result);
|
||||||
if(compare_result == 1){
|
// if(compare_result == 1){
|
||||||
alert(compare_result);
|
// alert(compare_result);
|
||||||
$("#pull_request_branch_error").show();
|
// $("#pull_request_branch_error").show();
|
||||||
return false;
|
// return false;
|
||||||
}else{
|
// }else{
|
||||||
$("#pull_request_branch_error").hide();
|
// $("#pull_request_branch_error").hide();
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//提交pull request
|
//提交pull request
|
||||||
function pull_request_commit()
|
function pull_request_commit()
|
||||||
{
|
{
|
||||||
if(compare_can_create() && regex_branch() && regex_pr_name())
|
if(regex_pr_name())
|
||||||
{
|
{
|
||||||
$("#pull_request_form").submit();
|
$("#pull_request_form").submit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ class Gitlab::Client
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_branch_commit_id(project, git_tree, ref_name)
|
def get_branch_commit_id(project, git_tree, ref_name)
|
||||||
post("/projects/#{project}/repository/get_branch_commit_id?git_tree=#{git_tree}&ref_name=#{ref_name}")
|
get("/projects/#{project}/repository/get_branch_commit_id?git_tree=#{git_tree}&ref_name=#{ref_name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue