Merge branch 'dev_newproject' of https://git.trustie.net/jacknudt/trustieforge into dev_newproject
This commit is contained in:
commit
440e73ea99
|
@ -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
|
||||
|
@ -84,17 +85,26 @@ class PullRequestsController < ApplicationController
|
|||
description = params[:description]
|
||||
source_branch = params[:source_branch]
|
||||
target_branch = params[:target_branch]
|
||||
target_project_id = params[:target_project_id]
|
||||
begin
|
||||
# 如果传送了目标项目ID,则PR请求发至目标项目
|
||||
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)
|
||||
@fork_project_name = Project.find(@project.forked_from_project_id).try(:name)
|
||||
@fork_pr_message = true if @fork_project_name
|
||||
# 如果分支有改动
|
||||
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
|
||||
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(@project.forked_from_project_id).try(:name)
|
||||
@fork_pr_message = true if @fork_project_name
|
||||
else
|
||||
request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch)
|
||||
respond_to do |format|
|
||||
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
|
||||
end
|
||||
end
|
||||
else
|
||||
request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch)
|
||||
@tip = 1
|
||||
respond_to do |format|
|
||||
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
|
||||
format.js{redirect_to new_project_pull_request_path}
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
|
@ -102,8 +112,40 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# Compare branch for MR
|
||||
# 判断源分支和目标分支是否有改动
|
||||
# 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'
|
||||
if target_project
|
||||
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
|
||||
status
|
||||
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 +308,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,9 +12,9 @@
|
|||
<% 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="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>
|
||||
<select name="target_branch" id="pull_request_branch" class = "fl PullReques_minselect ml5" >
|
||||
<% @source_rev.each do |rev| %>
|
||||
|
@ -23,7 +23,11 @@
|
|||
</select>
|
||||
<% 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>
|
||||
|
@ -67,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)
|
||||
{
|
||||
|
@ -81,10 +85,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();
|
||||
}
|
||||
|
|
|
@ -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") %>');
|
|
@ -1,7 +1,7 @@
|
|||
<% member = Member.where("user_id = #{@user.id} and project_id = #{project.id}").first %>
|
||||
<% if User.current == @user %>
|
||||
<% if member %>
|
||||
<%= link_to "", cancel_or_collect_user_path(@user, :project => project.id), :class => "#{member.is_collect == 1 ? 'icons_project_favorite mt3' : 'icons_project_star mt3'}",:target => '_blank', :remote => true, :title => "#{member.is_collect == 1 ? '点击将其从个人主页的班级列表中移除' : '点击将其添加至个人主页的班级列表中'}" %>
|
||||
<%= link_to "", cancel_or_collect_user_path(@user, :project => project.id), :class => "#{member.is_collect == 1 ? 'icons_project_favorite mt3' : 'icons_project_star mt3'}",:target => '_blank', :remote => true, :title => "#{member.is_collect == 1 ? '点击将其从个人主页的项目列表中移除' : '点击将其添加至个人主页的项目列表中'}" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% if member %>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<li class="f14"><strong>项目消息</strong></li>
|
||||
<li><%= link_to "项目任务", user_message_path(User.current, :type => 'issue'), :class => "homepageTypePTask postTypeGrey" %></li>
|
||||
<li><%= link_to "项目讨论", user_message_path(User.current, :type => 'forge_message'), :class => "homepagePostTypeForum postTypeGrey" %></li>
|
||||
<li><%= link_to "项目新闻", user_message_path(User.current, :type => 'forge_news'), :class => "homepageTypePNews postTypeGrey" %></li>
|
||||
<!--<li><%#= link_to "项目新闻", user_message_path(User.current, :type => 'forge_news'), :class => "homepageTypePNews postTypeGrey" %></li>-->
|
||||
<li><%= link_to "加入项目", user_message_path(User.current, :type => 'apply'), :class => "homepageTypeUApply postTypeGrey" %></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
@ -164,25 +164,6 @@
|
|||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if ma.forge_message_type == "News" %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl">
|
||||
<a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.forge_message.author), :width => "30", :height => "30"), user_path(ma.forge_message.author), :target => '_blank' %></a>
|
||||
</li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<%=link_to ma.forge_message.author, user_path(ma.forge_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
|
||||
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布了新闻:</span>
|
||||
</li>
|
||||
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
||||
<%= link_to ("#{ma.forge_message.title.html_safe}"), {:controller => 'news', :action => 'show', :id => ma.forge_message.id},
|
||||
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
|
||||
<!--:onmouseover => "message_titile_show($(this),event)",-->
|
||||
<!--:onmouseout => "message_titile_hide($(this))" %>-->
|
||||
</a>
|
||||
</li>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if ma.forge_message_type == "Comment" %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.forge_message.author), :width => "30", :height => "30"), user_path(ma.forge_message.author), :target => '_blank' %></a></li>
|
||||
|
|
|
@ -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