Merge branch 'develop' into dai_ao

Conflicts:
	app/controllers/pull_requests_controller.rb
This commit is contained in:
huang 2016-11-30 09:42:29 +08:00
commit 6725d122f8
8 changed files with 108 additions and 30 deletions

View File

@ -50,10 +50,10 @@ gem 'elasticsearch-model'
gem 'elasticsearch-rails'
#rails 3.2.22.2 bug
gem "test-unit", "~>3.0"
# gem "test-unit", "~>3.0"
### profile
gem 'oneapm_rpm'
# gem 'oneapm_rpm'
group :development do
gem 'grape-swagger'

View File

@ -1,15 +1,19 @@
# encoding: utf-8
# 如果你对改模块任何功能不清楚,请不要随便改
# @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, :compare_pull_request]
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, :compare_pull_request]
before_filter :member_allowed, :only => [:new, :create]
before_filter :manager_allowed, :only => [:accept_pull_request]
layout "base_projects"
include PullRequestsHelper
include ApplicationHelper
require 'ostruct'
# 返回json格式
def index
# project_menu_type 为了控制base顶部导航
@ -117,8 +121,14 @@ class PullRequestsController < ApplicationController
format.js{redirect_to new_project_pull_request_path(:show_tip => tip)}
end
end
rescue Gitlab::Error::Forbidden => e
@message = l(:label_pull_request_forbidden)
rescue Gitlab::Error::Conflict => e
@message = e.message
@message = l(:label_pull_request_conflic)
rescue Gitlab::Error::NotFound => e
@message = l(:label_pull_request_notfound)
rescue Exception => e
puts e
end
end
@ -278,23 +288,57 @@ class PullRequestsController < ApplicationController
# id (required) - The ID of a project
# merge_request_id (required) - The ID of MR
def pull_request_changes
begin
@type = params[:type]
@changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes)
logger.info("###############################{@changes}")
diff = ActiveSupport::JSON.decode(@changes).first
diff = OpenStruct.new(diff)
diff_file = Trustie::Gitlab::Diff::File.new(diff)
logger.info("##############################")
output = ''
diff_file.diff_lines.each_with_index do |line, index|
type = line.type
last_line = line.new_pos
line_old = line.old_pos.to_s
if type == 'match'
## 表示没有修改,两个都要显示行号
output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n"
else
old_line = type == 'new' ? ' '*4: line_old
new_line = type == 'old' ? ' '*4: last_line
output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n"
end
end
@changes_count = @changes.count
@limit = 10
@is_remote = true
@count = @changes_count
@pages = Paginator.new @count, @limit, params['page'] || 1
@offset ||= @pages.offset
@changes = paginateHelper @changes, 10
rescue Exception => e
@message = e.message
end
private
# post 相关操作权限控制
# 项目管理员可操作
def manager_allowed
unless is_project_manager?(User.current.id, @project.id)
return render_403
end
end
# 项目成员可操作
def member_allowed
unless User.current.member_of?(@project)
return render_403
end
end
private
def send_message user_id, project_id, pull_request_id
ForgeMessage.create(:user_id => user_id, :project_id => project_id,
:forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true)

View File

@ -49,6 +49,7 @@ class RepositoriesController < ApplicationController
helper :repositories
include RepositoriesHelper
helper :project_score
require 'ostruct'
#@root_path = RepositoriesHelper::ROOT_PATH
# require 'net/ssh'
@ -582,6 +583,26 @@ update
@project_menu_type = 5
@commit_diff = @g.commit_diff(@project.gpid, params[:changeset])
diff = @commit_diff.first
diff = OpenStruct.new(diff)
logger.info("######################{diff}")
@diff_file = Trustie::Gitlab::Diff::File.new(diff)
# diff_file.diff_lines.each_with_index do |line, index|
# type = line.type
# last_line = line.new_pos
# line_old = line.old_pos.to_s
#
#
# if type == 'match'
# ## 表示没有修改,两个都要显示行号
# output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n"
# else
# old_line = type == 'new' ? ' '*4: line_old
# new_line = type == 'old' ? ' '*4: last_line
# output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n"
# end
# end
@commit_details = @g.commit(@project.gpid, params[:changeset])
render :layout => 'base_projects'
end

View File

@ -19,6 +19,11 @@ module PullRequestsHelper
PullRequest.where(:pull_request_id => pull_request_id).first
end
# 通过gitlab项目id获取Trustie项目的用户名
def find_gitlab_project gitlab_project_id
Project.find_by_gpid(gitlab_project_id).owner.try(:show_name)
end
def get_state state
case state
when "open","reopened"

View File

@ -18,23 +18,25 @@
<div class="autoscroll">
<table class="filecontent syntaxhl" style="width:100%;" >
<tbody>
<% line_num = diff_line_num(change['diff']) %>
<% diff_content = diff_content(change['diff']) %>
<% syntax_highlight_lines('new_path', Redmine::CodesetUtil.to_utf8_by_setting(diff_content)).each do |line| %>
<tr>
<th class="line-num" id="L<%= line_num %>" style="vertical-align: top;">
<a href="#L<%= line_num %>" style="padding-top: 0px;"><%= line_num %></a>
</th>
<% if line[0,1] == "-" %>
<td class="line-code diff_out"><pre style="white-space:pre;"><%= line.html_safe %></pre></td>
<% elsif line[0,1] == "+" %>
<td class="line-code diff_in"><pre style="white-space:pre;"><%= line.html_safe %></pre></td>
<% else%>
<td class="line-code"><pre style="white-space:pre;"><%= line.html_safe %></pre></td>
<% end %>
</tr>
<% line_num += 1 %>
<% diff = ActiveSupport::JSON.decode(change['diff']).first %>
<% diff = OpenStruct.new(diff) %>
<% diff_file = Trustie::Gitlab::Diff::File.new(diff) %>
<% diff_file.diff_lines.each_with_index do |line, index| %>
<% type = line.type %>
<% last_line = line.new_pos %>
<% line_old = line.old_pos.to_s %>
<% if type == 'match' %>
<!--表示没有修改,两个都要显示行号-->
<% output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n" %>
<% else %>
<% old_line = type == 'new' ? ' '*4: line_old %>
<% new_line = type == 'old' ? ' '*4: last_line %>
<% output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n" %>
<% end %>
<% end %>
<%# line_num = diff_line_num(change['diff']) %>
<%# diff_content = diff_content(change['diff']) %>
</tbody>
</table>
</div>

View File

@ -14,10 +14,8 @@
<div class="c_grey clear mt5">
<p class="fl">由 <%= link_to get_user_by_login_and(request.author.try(:username)).try(:show_name), user_path(get_user_by_login_and(request.author.try(:username))), :class => "linkBlue2" %> 创建于<%= time_tag(request.created_at) %>前</p>
<span class="fl ml10"><%= time_tag(request.updated_at) %>前更新</span>
<p class="fr"><%= @project.name+"/"+request.source_branch %><span class="c_grey02 ml10 mr10">合并到</span><%= request.target_branch %></p>
<p class="fr"><%= find_gitlab_project(request.source_project_id)+"/"+request.source_branch %><span class="c_grey02 ml10 mr10">合并到</span><%= find_gitlab_project(request.target_project_id)+"/"+request.target_branch %></p>
</div>
</div>
<% end %>
<% end %>

View File

@ -16,8 +16,12 @@
<!--<li><a href="javascript:void()" class="linkGrey3" id="changed-files">app/views/users/_user_homework_detail.html.erb</a> </li>-->
<!--</ol>-->
<!--</div>-->
<%= @diff_file.diff_lines %>
<% @diff_file.diff_lines.each_with_index do |line, index| %>
<% @commit_diff.each do |cd| %>
<%= type = ldine.type %>
<%= last_line = line.new_pos %>
<%= line_old = line.old_pos.to_s %>
<div class="showing-changes-row fontGrey2">
<a href="javascript:void(0);" class="linkGrey3" id="changed-files">
<img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= cd.new_path %>

View File

@ -507,3 +507,7 @@ zh:
label_done_ratio_endding: 已完成
label_done_ratio_doing: 未完成
label_pull_request_conflic: 您创建的Pull Request尚未被管理员接受或者关闭不能重新创建
label_pull_request_forbidden: 您没有权限进行该操作
label_pull_request_notfound: 您操作的页面不存在或者已被删除