pull request 使用优化

This commit is contained in:
huang 2016-11-18 16:08:50 +08:00
parent f87d1ce3bd
commit 6584cd88f1
3 changed files with 41 additions and 49 deletions

View File

@ -47,10 +47,11 @@ class PullRequestsController < ApplicationController
end
# 主要取源项目和目标项目分支及标识(用户名/版本库名)
# @tip 为空的时候表明发送的pr请求有改动为1的时候源分支和目标分支没有改动则不能成功创建
def new
# project_menu_type 为了控制base顶部导航
@project_menu_type = 6
@tip = params[:show_tip]
identifier = get_rep_identifier_by_project @project
@source_project_name = "#{get_user_name(@project.user_id)}/#{identifier}"
@source_rev = @g.branches(@project.gpid).map{|b| b.name}
@ -102,9 +103,9 @@ class PullRequestsController < ApplicationController
end
end
else
@tip = 1
tip = 1
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
rescue Exception => e
@ -120,25 +121,16 @@ class PullRequestsController < ApplicationController
identifier = @repository.identifier.downcase
git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git'
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'
# 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_target_commit_id = @g.get_branch_commit_id(user_name_source.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
git_target_commit_id = @g.get_branch_commit_id(forked_source_project.gpid, git_target_tree, target_branch)
else
reuslt = `git #{git_source_tree} log --pretty=oneline #{source_branch} ^#{target_branch}`
status = result.blank? ? false : true
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)
end
status
status = (git_sourse_commit_id.try(:commit_id) == git_target_commit_id.try(:commit_id) ? false : true)
end
# @project_menu_type 为了控制base顶部导航

View File

@ -67,41 +67,41 @@
}
}
function regex_branch()
{
var source_branch = $.trim($("#source_branch").val());
var target_branch = $.trim($("#pull_request_branch").val());
var target_project = $.trim($("#target_project_id").children().attr("name"));
var target_forked_project = $.trim($("#pull_request_project_hidden").text());
if(target_project == target_forked_project && source_branch == target_branch)
{
$("#pull_request_branch_error").show();
return false;
}
else
{
$("#pull_request_branch_error").hide();
return true;
}
}
// function regex_branch()
// {
// var source_branch = $.trim($("#source_branch").val());
// var target_branch = $.trim($("#pull_request_branch").val());
// var target_project = $.trim($("#target_project_id").children().attr("name"));
// var target_forked_project = $.trim($("#pull_request_project_hidden").text());
// if(target_project == target_forked_project && source_branch == target_branch)
// {
// $("#pull_request_branch_error").show();
// return false;
// }
// else
// {
// $("#pull_request_branch_error").hide();
// return true;
// }
// }
function compare_can_create(){
var compare_result = $.trim($("#pull_request_compare_result").text());
alert(compare_result);
if(compare_result == 1){
alert(compare_result);
$("#pull_request_branch_error").show();
return false;
}else{
$("#pull_request_branch_error").hide();
return true;
}
}
// function compare_can_create(){
// var compare_result = $.trim($("#pull_request_compare_result").text());
// alert(compare_result);
// if(compare_result == 1){
// alert(compare_result);
// $("#pull_request_branch_error").show();
// return false;
// }else{
// $("#pull_request_branch_error").hide();
// return true;
// }
// }
//提交pull request
function pull_request_commit()
{
if(compare_can_create() && regex_branch() && regex_pr_name())
if(regex_pr_name())
{
$("#pull_request_form").submit();
}

View File

@ -87,7 +87,7 @@ class Gitlab::Client
end
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