pull requst优化
This commit is contained in:
parent
987b5ba6db
commit
386b41d08e
|
@ -1,9 +1,10 @@
|
|||
|
||||
# 如果你对改模块任何功能不清楚,请不要随便改
|
||||
# @Hjqreturn
|
||||
class PullRequestsController < ApplicationController
|
||||
before_filter :authorize_logged
|
||||
before_filter :find_project_and_repository
|
||||
before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new,
|
||||
:update_pull_request, :pull_request_comments, :create_pull_request_comment]
|
||||
:update_pull_request, :pull_request_comments, :create_pull_request_comment, :compare_pull_request]
|
||||
|
||||
layout "base_projects"
|
||||
include PullRequestsHelper
|
||||
|
@ -85,7 +86,15 @@ class PullRequestsController < ApplicationController
|
|||
source_branch = params[:source_branch]
|
||||
target_branch = params[:target_branch]
|
||||
begin
|
||||
# 如果传送了目标项目ID,则PR请求发至目标项目
|
||||
# 如果分支没有改动
|
||||
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
|
||||
# 如果传送了目标项目ID即向fork源项目发送请求
|
||||
if params[:forked_project_id] && params[:source_project] == "forked_project_name"
|
||||
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)
|
||||
|
@ -97,13 +106,35 @@ class PullRequestsController < ApplicationController
|
|||
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
@message = e.message
|
||||
end
|
||||
end
|
||||
|
||||
# Compare branch for MR
|
||||
# 判断源分支和目标分支是否有改动
|
||||
def compare_pull_request source_branch, target_project, target_branch
|
||||
user_source_name = @project.owner.try(:login)
|
||||
identifier = @repository.identifier.downcase
|
||||
git_source_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git'
|
||||
if target_project
|
||||
git_target_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git'
|
||||
else
|
||||
|
||||
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}`
|
||||
end
|
||||
|
||||
# @project_menu_type 为了控制base顶部导航
|
||||
# merge_when_succeeds
|
||||
def show
|
||||
# project_menu_type 为了控制base顶部导航
|
||||
# compare_pull_request source_project, source_branch, target_project, target_branch
|
||||
# compare_pull_request
|
||||
@project_menu_type = 6
|
||||
@type = params[:type]
|
||||
@request = @g.merge_request(@project.gpid, params[:id])
|
||||
|
@ -266,7 +297,7 @@ class PullRequestsController < ApplicationController
|
|||
def find_project_and_repository
|
||||
@project = Project.find(params[:project_id])
|
||||
render_404 if @project.gpid.blank?
|
||||
@repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab")
|
||||
@repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab").first
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
|
|
@ -6,10 +6,10 @@ class QualityAnalysisController < ApplicationController
|
|||
layout "base_projects"
|
||||
include ApplicationHelper
|
||||
include QualityAnalysisHelper
|
||||
# require 'jenkins_api_client'
|
||||
# require 'nokogiri'
|
||||
# require 'json'
|
||||
# require 'open-uri'
|
||||
require 'jenkins_api_client'
|
||||
require 'nokogiri'
|
||||
require 'json'
|
||||
require 'open-uri'
|
||||
|
||||
def show
|
||||
|
||||
|
|
|
@ -931,7 +931,10 @@ module ApplicationHelper
|
|||
def allow_pull_request project
|
||||
return 0 if project.gpid.nil?
|
||||
g = Gitlab.client
|
||||
count = g.user_static(project.gpid, :rev => "master").count
|
||||
# 之所以这样比较是为了解决gitlab本身的bug
|
||||
commit_count = g.project(project.gpid).try(:commit_count).to_i
|
||||
git_commit_cout = g.user_static(project.gpid, :rev => "master").count
|
||||
count = commit_count > git_commit_cout ? commit_count : git_commit_cout
|
||||
count
|
||||
end
|
||||
|
||||
|
|
|
@ -12,17 +12,19 @@
|
|||
<% 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="source_project" value="source_project" class="fl PullReques_minselect">
|
||||
<option name="<%= @project.id %>" value="source_project_name" ><%= @source_project_name %></option>
|
||||
<option name="<%= @forked_project.id %>" value="forked_project_name" ><%= @forked_project_name %></option>
|
||||
<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">
|
||||
<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>
|
||||
<select name="target_branch" id="pull_request_branch" class = "fl PullReques_minselect ml5" >
|
||||
<% @source_rev.each do |rev| %>
|
||||
<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 class="alert alert-blue mb10" id ="pull_request_branch_error" style="display: none">
|
||||
<span class="c_orange">您选择的源分支和目标分支为似乎没有差异,请将新改动提交至源分支或者切换到其它目标分支</span>
|
||||
|
@ -81,10 +83,23 @@
|
|||
}
|
||||
}
|
||||
|
||||
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(regex_branch() && regex_pr_name())
|
||||
if(compare_can_create() && regex_branch() && regex_pr_name())
|
||||
{
|
||||
$("#pull_request_form").submit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue