pull reqeust相关
This commit is contained in:
parent
386b41d08e
commit
00d12fdeb3
|
@ -85,15 +85,10 @@ class PullRequestsController < ApplicationController
|
|||
description = params[:description]
|
||||
source_branch = params[:source_branch]
|
||||
target_branch = params[:target_branch]
|
||||
target_project_id = params[:target_project_id]
|
||||
begin
|
||||
# 如果分支没有改动
|
||||
if compare_pull_request(source_branch, target_project, target_branch).blank?
|
||||
@no_updates = 1
|
||||
respond_to do |format|
|
||||
format.html{new_project_pull_request_path()}
|
||||
end
|
||||
else
|
||||
@no_updates = 0
|
||||
# 如果分支有改动
|
||||
if compare_pull_request(source_branch, target_project_id, target_branch)
|
||||
# 如果传送了目标项目ID即向fork源项目发送请求
|
||||
if params[:forked_project_id] && params[:source_project] == "forked_project_name"
|
||||
target_project_id = params[:forked_project_id].to_i
|
||||
|
@ -106,6 +101,11 @@ class PullRequestsController < ApplicationController
|
|||
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
|
||||
end
|
||||
end
|
||||
else
|
||||
@tip = 1
|
||||
respond_to do |format|
|
||||
format.js{redirect_to new_project_pull_request_path}
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
@message = e.message
|
||||
|
@ -114,20 +114,31 @@ class PullRequestsController < ApplicationController
|
|||
|
||||
# Compare branch for MR
|
||||
# 判断源分支和目标分支是否有改动
|
||||
# status 为true 表示有改动; false:便是没有改动
|
||||
def compare_pull_request source_branch, target_project, target_branch
|
||||
user_source_name = @project.owner.try(:login)
|
||||
user_name_source = @project.owner.try(:login)
|
||||
identifier = @repository.identifier.downcase
|
||||
git_source_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git'
|
||||
git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git'
|
||||
if target_project
|
||||
git_target_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git'
|
||||
else
|
||||
user_name_target = Project.find(target_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
|
||||
else
|
||||
reuslt = `git #{git_source_tree} log --pretty=oneline #{source_branch} ^#{target_branch}`
|
||||
status = result.blank? ? false : true
|
||||
end
|
||||
# def compare_pull_request
|
||||
user_name = @project.owner.try(:login)
|
||||
identifier = @repository.identifier.downcase
|
||||
git_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git'
|
||||
status = `git #{git_tree} log --pretty=oneline #{source_branch} ^#{target_branch}`
|
||||
status
|
||||
end
|
||||
|
||||
# @project_menu_type 为了控制base顶部导航
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<% if @forked_project.nil? %>
|
||||
<%= select_tag :branch, options_for_select(@source_rev), :id => "pull_request_branch", :name => "target_branch", :value => "target_branch",:class => "fl PullReques_minselect ml5" %>
|
||||
<% else %>
|
||||
<select onchange="choice_branch(this.value, document.getElementById('pull_request_branch'), <%= @source_rev %>, <%= @forked_rev %>);" id="pull_request_project" name="pull_request_project" value="pull_request_project" class="fl PullReques_minselect">
|
||||
<select onchange="choice_branch(this.value, document.getElementById('pull_request_branch'), <%= @source_rev %>, <%= @forked_rev %>);" id="target_project_id" name="target_project_id" value="target_project_id" class="fl PullReques_minselect">
|
||||
<option id="source_project_name" name="<%= @project.id %>" value="<%= @project.id %>" ><%= @source_project_name %></option>
|
||||
<option id="target_project_name" name="<%= @forked_project.id %>" value="<%= @forked_project.id %>" ><%= @forked_project_name %></option>
|
||||
</select>
|
||||
|
@ -21,11 +21,13 @@
|
|||
<option value="<%= rev %>"><%= rev %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
<%= hidden_field_tag 'target_project_id', '' %>
|
||||
<% end %>
|
||||
<p id="pull_request_project_hidden" style="display: none"><%= @forked_project.nil? ? "" : @project.id %></p>
|
||||
<p id="pull_request_compare_result" style="display: none"><%= @no_updates %></p>
|
||||
</li>
|
||||
<div id="pull_request_branch_tip">
|
||||
<%= render :partial => "tip" %>
|
||||
</div>
|
||||
<div class="alert alert-blue mb10" id ="pull_request_branch_error" style="display: none">
|
||||
<span class="c_orange">您选择的源分支和目标分支为似乎没有差异,请将新改动提交至源分支或者切换到其它目标分支</span>
|
||||
</div>
|
||||
|
@ -69,7 +71,7 @@
|
|||
{
|
||||
var source_branch = $.trim($("#source_branch").val());
|
||||
var target_branch = $.trim($("#pull_request_branch").val());
|
||||
var target_project = $.trim($("#pull_request_project").children().attr("name"));
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<% if @tip %>
|
||||
<div class="alert alert-blue mb10">
|
||||
<span class="c_orange">您选择的源分支和目标分支为似乎没有差异,请将新改动提交至源分支或者切换到其它目标分支</span>
|
||||
</div>
|
||||
<% end %>
|
|
@ -0,0 +1 @@
|
|||
$("#pull_request_branch_tip").html('<%= escape_javascript(render :partial => "pull_requests/tip") %>');
|
|
@ -86,6 +86,11 @@ class Gitlab::Client
|
|||
get("/projects/#{project}/repository/user_static", :query => options)
|
||||
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}")
|
||||
end
|
||||
|
||||
|
||||
# Gets a specific commit identified by the commit hash or name of a branch or tag.
|
||||
#
|
||||
# @example
|
||||
|
|
Loading…
Reference in New Issue