pull request 改动对比显示 代码封装

This commit is contained in:
daiao 2016-11-29 10:52:57 +08:00
parent ece69b9e7a
commit 7ea9f00054
4 changed files with 398 additions and 430 deletions

View File

@ -1,353 +1,331 @@
# encoding: utf-8 # encoding: utf-8
# 如果你对改模块任何功能不清楚,请不要随便改 # 如果你对改模块任何功能不清楚,请不要随便改
# @Hjqreturn # @Hjqreturn
class PullRequestsController < ApplicationController class PullRequestsController < ApplicationController
before_filter :authorize_logged before_filter :authorize_logged
before_filter :find_project_and_repository 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 :member_allowed, :only => [:new, :create]
before_filter :manager_allowed, :only => [:accept_pull_request] before_filter :manager_allowed, :only => [:accept_pull_request]
layout "base_projects" layout "base_projects"
include PullRequestsHelper include PullRequestsHelper
include ApplicationHelper include ApplicationHelper
require 'ostruct' require 'ostruct'
# 返回json格式 # 返回json格式
def index def index
# project_menu_type 为了控制base顶部导航 # project_menu_type 为了控制base顶部导航
@project_menu_type = 6 @project_menu_type = 6
# 不符合pullrequest条件的给出提示 # 不符合pullrequest条件的给出提示
@allow_to_pull_request = allow_pull_request(@project) > 0 @allow_to_pull_request = allow_pull_request(@project) > 0
type = params[:type] type = params[:type]
merge_requests = @g.merge_requests(@project.gpid) merge_requests = @g.merge_requests(@project.gpid)
merge_requests_count = merge_requests.count merge_requests_count = merge_requests.count
case type case type
when nil, "1" when nil, "1"
@requests = merge_requests.select{|request| request.state == "opened" || request.state == "reopened"} @requests = merge_requests.select{|request| request.state == "opened" || request.state == "reopened"}
# 更新统计数字 # 更新统计数字
project_score = @project.project_score.update_column(:pull_request_num, merge_requests_count) project_score = @project.project_score.update_column(:pull_request_num, merge_requests_count)
when "2" when "2"
@requests = merge_requests.select{|request| request.state == "merged"} @requests = merge_requests.select{|request| request.state == "merged"}
when "3" when "3"
@requests = merge_requests.select{|request| request.state == "closed"} @requests = merge_requests.select{|request| request.state == "closed"}
end end
@requests_opened_count = @requests.count @requests_opened_count = @requests.count
@requests_merged_count = merge_requests.select{|request| request.state == "merged"}.count @requests_merged_count = merge_requests.select{|request| request.state == "merged"}.count
@requests_closed_count = merge_requests.select{|request| request.state == "closed"}.count @requests_closed_count = merge_requests.select{|request| request.state == "closed"}.count
@limit = 10 @limit = 10
@is_remote = true @is_remote = true
@count = type_count(type, @requests_opened_count, @requests_merged_count, @requests_closed_count) @count = type_count(type, @requests_opened_count, @requests_merged_count, @requests_closed_count)
@pages = Paginator.new @count, @limit, params['page'] || 1 @pages = Paginator.new @count, @limit, params['page'] || 1
@offset ||= @pages.offset @offset ||= @pages.offset
@requests = paginateHelper @requests, 10 @requests = paginateHelper @requests, 10
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js
end end
end end
# 主要取源项目和目标项目分支及标识(用户名/版本库名) # 主要取源项目和目标项目分支及标识(用户名/版本库名)
# @tip 为空的时候表明发送的pr请求有改动为1的时候源分支和目标分支没有改动则不能成功创建 # @tip 为空的时候表明发送的pr请求有改动为1的时候源分支和目标分支没有改动则不能成功创建
def new def new
# project_menu_type 为了控制base顶部导航 # project_menu_type 为了控制base顶部导航
@project_menu_type = 6 @project_menu_type = 6
@tip = params[:show_tip] @tip = params[:show_tip]
identifier = get_rep_identifier_by_project @project identifier = get_rep_identifier_by_project @project
@source_project_name = "#{get_user_name(@project.user_id)}/#{identifier}" @source_project_name = "#{get_user_name(@project.user_id)}/#{identifier}"
@source_rev = @g.branches(@project.gpid).map{|b| b.name} @source_rev = @g.branches(@project.gpid).map{|b| b.name}
# 获取forked源项目信息 # 获取forked源项目信息
if @project.forked_from_project_id if @project.forked_from_project_id
@forked_project = Project.find(@project.forked_from_project_id) @forked_project = Project.find(@project.forked_from_project_id)
identifier = get_rep_identifier_by_project @forked_project identifier = get_rep_identifier_by_project @forked_project
@forked_project_name = "#{get_user_name(@forked_project.user_id)}/#{identifier}" @forked_project_name = "#{get_user_name(@forked_project.user_id)}/#{identifier}"
@forked_rev = @g.branches(@forked_project.gpid).map{|b| b.name} @forked_rev = @g.branches(@forked_project.gpid).map{|b| b.name}
end end
end end
# Creates a merge request. # Creates a merge request.
# If the operation is successful, 200 and the newly created merge request is returned. If an error occurs, an error number and a message explaining the reason is returned. # If the operation is successful, 200 and the newly created merge request is returned. If an error occurs, an error number and a message explaining the reason is returned.
# #
# @example # @example
# Gitlab.create_merge_request(5, 'New merge request', # Gitlab.create_merge_request(5, 'New merge request',
# :source_branch => 'source_branch', :target_branch => 'target_branch') # :source_branch => 'source_branch', :target_branch => 'target_branch')
# Gitlab.create_merge_request(5, 'New merge request', # Gitlab.create_merge_request(5, 'New merge request',
# :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42) # :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42)
# #
# @param [Integer] project The ID of a project. # @param [Integer] project The ID of a project.
# @param [String] title The title of a merge request. # @param [String] title The title of a merge request.
# @param [Hash] options A customizable set of options. # @param [Hash] options A customizable set of options.
# @option options [String] :source_branch (required) The source branch name. # @option options [String] :source_branch (required) The source branch name.
# @option options [String] :target_branch (required) The target branch name. # @option options [String] :target_branch (required) The target branch name.
# @option options [Integer] :assignee_id (optional) The ID of a user to assign merge request. # @option options [Integer] :assignee_id (optional) The ID of a user to assign merge request.
# @return [Gitlab::ObjectifiedHash] Information about created merge request. # @return [Gitlab::ObjectifiedHash] Information about created merge request.
def create def create
title = params[:title] title = params[:title]
description = params[:description] description = params[:description]
source_branch = params[:source_branch] source_branch = params[:source_branch]
target_branch = params[:target_branch] target_branch = params[:target_branch]
target_project_id = params[:target_project_id] target_project_id = params[:target_project_id]
begin begin
# 如果分支有改动 # 如果分支有改动
if compare_pull_request(source_branch, target_project_id, target_branch) if compare_pull_request(source_branch, target_project_id, target_branch)
# 如果传送了目标项目ID即向fork源项目发送请求 # 如果传送了目标项目ID即向fork源项目发送请求
# if params[:forked_project_id] && params[:source_project] == "forked_project_name" # if params[:forked_project_id] && params[:source_project] == "forked_project_name"
if !params[:target_project_id].blank? if !params[:target_project_id].blank?
target_project_id = params[:forked_project_id].to_i 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) 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(params[:target_project_id]).try(:name) @fork_project_name = Project.find(params[:target_project_id]).try(:name)
@fork_pr_message = true if @fork_project_name @fork_pr_message = true if @fork_project_name
else else
request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) 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| respond_to do |format|
format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)}
end end
end end
else else
tip = 1 tip = 1
respond_to do |format| respond_to do |format|
format.js{redirect_to new_project_pull_request_path(:show_tip => tip)} format.js{redirect_to new_project_pull_request_path(:show_tip => tip)}
end end
end end
rescue Gitlab::Error::Forbidden => e rescue Gitlab::Error::Forbidden => e
@message = l(:label_pull_request_forbidden) @message = l(:label_pull_request_forbidden)
rescue Gitlab::Error::Conflict => e rescue Gitlab::Error::Conflict => e
@message = l(:label_pull_request_conflic) @message = l(:label_pull_request_conflic)
rescue Gitlab::Error::NotFound => e rescue Gitlab::Error::NotFound => e
@message = l(:label_pull_request_notfound) @message = l(:label_pull_request_notfound)
rescue Exception => e rescue Exception => e
puts e puts e
end end
end end
# Compare branch for MR # Compare branch for MR
# 判断源分支和目标分支是否有改动 # 判断源分支和目标分支是否有改动
# status 为true 表示有改动; false:便是没有改动 # status 为true 表示有改动; false:便是没有改动
def compare_pull_request source_branch, target_project, target_branch def compare_pull_request source_branch, target_project, target_branch
user_name_source = @project.owner.try(:login) user_name_source = @project.owner.try(:login)
identifier = @repository.identifier.downcase identifier = @repository.identifier.downcase
git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git' git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git'
if target_project if target_project
forked_source_project = Project.find(target_project) forked_source_project = Project.find(target_project)
user_name_target = forked_source_project.owner.try(:login) 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'
git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch) 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(forked_source_project.gpid, git_target_tree, target_branch) git_target_commit_id = @g.get_branch_commit_id(forked_source_project.gpid, git_target_tree, target_branch)
else else
git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch) 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) git_target_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, target_branch)
end end
status = (git_sourse_commit_id.try(:commit_id) == git_target_commit_id.try(:commit_id) ? false : true) status = (git_sourse_commit_id.try(:commit_id) == git_target_commit_id.try(:commit_id) ? false : true)
end end
# @project_menu_type 为了控制base顶部导航 # @project_menu_type 为了控制base顶部导航
# merge_when_succeeds # merge_when_succeeds
def show def show
# compare_pull_request source_project, source_branch, target_project, target_branch # compare_pull_request source_project, source_branch, target_project, target_branch
# compare_pull_request # compare_pull_request
@project_menu_type = 6 @project_menu_type = 6
@type = params[:type] @type = params[:type]
@request = @g.merge_request(@project.gpid, params[:id]) @request = @g.merge_request(@project.gpid, params[:id])
@commits = @g.merge_request_commits(@project.gpid, params[:id].to_i) @commits = @g.merge_request_commits(@project.gpid, params[:id].to_i)
@commits_count = @commits.count @commits_count = @commits.count
# @commits_day = @commits.chunk # @commits_day = @commits.chunk
@changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes)
@changes_count = @changes.count @changes_count = @changes.count
@comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse @comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse
@comments_count = @comments.count @comments_count = @comments.count
@limit = 10 @limit = 10
@is_remote = true @is_remote = true
@count = @comments_count @count = @comments_count
@pages = Paginator.new @count, @limit, params['page'] || 1 @pages = Paginator.new @count, @limit, params['page'] || 1
@offset ||= @pages.offset @offset ||= @pages.offset
@comments = paginateHelper @comments, 10 @comments = paginateHelper @comments, 10
end end
# Accept a merge request. # Accept a merge request.
# If merge success you get 200 OK. # If merge success you get 200 OK.
# Accept a merge request. # Accept a merge request.
# #
# @example # @example
# Gitlab.accept_pull_rquest(5, 1) # Gitlab.accept_pull_rquest(5, 1)
# #
# @param [Integer] project The ID of a project. # @param [Integer] project The ID of a project.
# @param [Integer] id The ID of a merge request. # @param [Integer] id The ID of a merge request.
# @return [Gitlab::ObjectifiedHash] # @return [Gitlab::ObjectifiedHash]
def accept_pull_request def accept_pull_request
begin begin
status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid)
PullRequest.create(:pull_request_id => status.id, :user_id => User.current.id, :gpid => status.project_id) PullRequest.create(:pull_request_id => status.id, :user_id => User.current.id, :gpid => status.project_id)
respond_to do |format| respond_to do |format|
format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)}
end end
rescue Exception => e rescue Exception => e
@message = e.message @message = e.message
end end
end end
# Updates a merge request. # Updates a merge request.
# #
# @example # @example
# Gitlab.update_merge_request(5, 42, :title => 'New title') # Gitlab.update_merge_request(5, 42, :title => 'New title')
# #
# @param [Integer] project The ID of a project. # @param [Integer] project The ID of a project.
# @param [Integer] id The ID of a merge request. # @param [Integer] id The ID of a merge request.
# @param [Hash] options A customizable set of options. # @param [Hash] options A customizable set of options.
# @option options [String] :title The title of a merge request. # @option options [String] :title The title of a merge request.
# @option options [String] :source_branch The source branch name. # @option options [String] :source_branch The source branch name.
# @option options [String] :target_branch The target branch name. # @option options [String] :target_branch The target branch name.
# @option options [Integer] :assignee_id The ID of a user to assign merge request. # @option options [Integer] :assignee_id The ID of a user to assign merge request.
# @option options [String] :state_event New state (close|reopen|merge). # @option options [String] :state_event New state (close|reopen|merge).
# @return [Gitlab::ObjectifiedHash] Information about updated merge request. # @return [Gitlab::ObjectifiedHash] Information about updated merge request.
def update_pull_request def update_pull_request
begin begin
@g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state])
respond_to do |format| respond_to do |format|
format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)}
end end
rescue Exception => e rescue Exception => e
@message = e.message @message = e.message
end end
end end
# Creates a merge request. # Creates a merge request.
# #
# @example # @example
# Gitlab.create_merge_request(5, 'New merge request', # Gitlab.create_merge_request(5, 'New merge request',
# :source_branch => 'source_branch', :target_branch => 'target_branch') # :source_branch => 'source_branch', :target_branch => 'target_branch')
# Gitlab.create_merge_request(5, 'New merge request', # Gitlab.create_merge_request(5, 'New merge request',
# :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42) # :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42)
def create_pull_request_comment def create_pull_request_comment
content = params[:pull_request_comment] content = params[:pull_request_comment]
begin begin
@comments = @g.create_merge_request_comment(@project.gpid, params[:id], content, User.current.gid) @comments = @g.create_merge_request_comment(@project.gpid, params[:id], content, User.current.gid)
respond_to do |format| respond_to do |format|
format.js{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} format.js{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)}
end end
rescue Exception => e rescue Exception => e
@message = e.message @message = e.message
end end
end end
# Gets the comments on a merge request. # Gets the comments on a merge request.
# #
# @example # @example
# Gitlab.merge_request_comments(5, 1) # Gitlab.merge_request_comments(5, 1)
def pull_request_comments def pull_request_comments
begin begin
@comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse @comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse
@comments_count = @comments.count @comments_count = @comments.count
@limit = 10 @limit = 10
@is_remote = true @is_remote = true
@count = @comments_count @count = @comments_count
@pages = Paginator.new @count, @limit, params['page'] || 1 @pages = Paginator.new @count, @limit, params['page'] || 1
@offset ||= @pages.offset @offset ||= @pages.offset
@comments = paginateHelper @comments, 10 @comments = paginateHelper @comments, 10
rescue Exception => e rescue Exception => e
@message = e.message @message = e.message
end end
end end
# Get a list of merge request commits. # Get a list of merge request commits.
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# merge_request_id (required) - The ID of MR # merge_request_id (required) - The ID of MR
def pull_request_commits def pull_request_commits
begin begin
@type = params[:type] @type = params[:type]
@commits = @g.merge_request_commits(@project.gpid, params[:id]) @commits = @g.merge_request_commits(@project.gpid, params[:id])
@commits_count = @commits.count @commits_count = @commits.count
@limit = 10 @limit = 10
@is_remote = true @is_remote = true
@count = @commits_count @count = @commits_count
@pages = Paginator.new @count, @limit, params['page'] || 1 @pages = Paginator.new @count, @limit, params['page'] || 1
@offset ||= @pages.offset @offset ||= @pages.offset
@commits = paginateHelper @commits, 10 @commits = paginateHelper @commits, 10
rescue Exception => e rescue Exception => e
@message = e.message @message = e.message
end end
end end
# Shows information about the merge request including its files and changes. With GitLab 8.2 the return fields upvotes and downvotes are deprecated and always return 0. # Shows information about the merge request including its files and changes. With GitLab 8.2 the return fields upvotes and downvotes are deprecated and always return 0.
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# merge_request_id (required) - The ID of MR # merge_request_id (required) - The ID of MR
def pull_request_changes def pull_request_changes
@type = params[:type]
@type = params[:type] @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes)
@changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes)
logger.info("###############################{@changes}") @changes_count = @changes.count
diff = ActiveSupport::JSON.decode(@changes).first @limit = 10
diff = OpenStruct.new(diff) @is_remote = true
diff_file = Trustie::Gitlab::Diff::File.new(diff) @count = @changes_count
logger.info("##############################") @pages = Paginator.new @count, @limit, params['page'] || 1
output = '' @offset ||= @pages.offset
diff_file.diff_lines.each_with_index do |line, index| @changes = paginateHelper @changes, 10
type = line.type
last_line = line.new_pos end
line_old = line.old_pos.to_s
private
# post 相关操作权限控制
if type == 'match' # 项目管理员可操作
## 表示没有修改,两个都要显示行号 def manager_allowed
output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n" unless is_project_manager?(User.current.id, @project.id)
else return render_403
old_line = type == 'new' ? ' '*4: line_old end
new_line = type == 'old' ? ' '*4: last_line end
output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n"
end # 项目成员可操作
end def member_allowed
unless User.current.member_of?(@project)
@changes_count = @changes.count return render_403
end
@is_remote = true end
@count = @changes_count
@pages = Paginator.new @count, @limit, params['page'] || 1 def authorize_logged
@offset ||= @pages.offset if !User.current.logged?
@changes = paginateHelper @changes, 10 redirect_to signin_path
return
end end
end
private
# post 相关操作权限控制 def connect_gitlab
# 项目管理员可操作 @g = Gitlab.client
def manager_allowed end
unless is_project_manager?(User.current.id, @project.id)
return render_403 def find_project_and_repository
end @project = Project.find(params[:project_id])
end render_404 if @project.gpid.blank?
@repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab").first
# 项目成员可操作 rescue ActiveRecord::RecordNotFound
def member_allowed render_404
unless User.current.member_of?(@project) end
return render_403
end end
end
def authorize_logged
if !User.current.logged?
redirect_to signin_path
return
end
end
def connect_gitlab
@g = Gitlab.client
end
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").first
rescue ActiveRecord::RecordNotFound
render_404
end
end

View File

@ -1,53 +1,31 @@
<% if !@changes.blank? && @type == "3" %> <% if !@changes.blank? && @type == "3" %>
<div class="pullreques_change_box"> <div class="pullreques_change_box">
<div class="pullreques_pull_top clear"> <div class="pullreques_pull_top clear">
<p class="fl c_grey ml15">改动了<span class="fontBlue"> <%= @changes_count %></span> 个文件</p> <p class="fl c_grey ml15">改动了<span class="fontBlue"> <%= @changes_count %></span> 个文件</p>
</div> </div>
<ul class="pullreques_change_list"> <ul class="pullreques_change_list">
<% @changes.each do |change| %> <% @changes.each do |change| %>
<li><span class="fl ml15 mt12 <%= get_type_of_file(change) %>"></span><p class="pullreques_pull_txt ml5 fl"><%= change['new_path'] %></p></li> <li><span class="fl ml15 mt12 <%= get_type_of_file(change) %>"></span><p class="pullreques_pull_txt ml5 fl"><%= change['new_path'] %></p></li>
<% end %> <% end %>
</ul> </ul>
</div> </div>
<% @changes.each do |change| %> <% @changes.each do |change| %>
<div class="showing-changes-row fontGrey2"> <div class="showing-changes-row fontGrey2">
<a class="linkGrey3" id="changed-files"> <a class="linkGrey3" id="changed-files">
<img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= change['new_path'] %> <img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= change['new_path'] %>
</a> </a>
</div> </div>
<div class="autoscroll"> <div class="autoscroll">
<table class="filecontent syntaxhl" style="width:100%;" > <%= render 'repositories/change_diff', :local => {:change => change} %>
<tbody> </div>
<% diff = ActiveSupport::JSON.decode(change['diff']).first %> <% end %>
<% diff = OpenStruct.new(diff) %>
<% diff_file = Trustie::Gitlab::Diff::File.new(diff) %> <div style="text-align:center;">
<% diff_file.diff_lines.each_with_index do |line, index| %> <div class="pages" style="width:auto; display:inline-block;">
<% type = line.type %> <ul id="homework_pository_ref_pages">
<% last_line = line.new_pos %> <%= pagination_links_full @pages, @count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%>
<% line_old = line.old_pos.to_s %> </ul>
<% if type == 'match' %> <div class="cl"></div>
<!--表示没有修改,两个都要显示行号--> </div>
<% output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n" %> </div>
<% else %> <% end %>
<% 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>
<% end %>
<div style="text-align:center;">
<div class="pages" style="width:auto; display:inline-block;">
<ul id="homework_pository_ref_pages">
<%= pagination_links_full @pages, @count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%>
</ul>
<div class="cl"></div>
</div>
</div>
<% end %>

View File

@ -0,0 +1,27 @@
<% diff = ActiveSupport::JSON.decode(change.to_json) %>
<% 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.to_s %>
<% line_old = line.old_pos.to_s %>
<table>
<tbody>
<% if type == "match" %>
<tr>
<td class="old_line"><%= line_old.center(4) %></td>
<td class="new_line"><%= last_line.center(4) %></td>
<td class="line_content"><%= line.text %></td>
</tr>
<% else %>
<% old_line = type == 'new' ? ' '*4: line_old %>
<% new_line = type == 'old' ? ' '*4: last_line %>
<tr>
<td class="old_line"><%= old_line.to_s.center(4) %></td>
<td class="new_line"><%= new_line.to_s.center(4) %></td>
<td class="line_content"><%= line.text %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@ -9,29 +9,14 @@
</li> </li>
</div> </div>
<div class="showing-changes-project f14"><%= @commit_details.message %></div> <div class="showing-changes-project f14"><%= @commit_details.message %></div>
<% @diff_file.diff_lines.each_with_index do |line, index| %> <% @commit_diff.each do |commit_diff| %>
<%= line[0] %> <div class="showing-changes-row fontGrey2">
<% type = line.type %> <a href="javascript:void(0);" class="linkGrey3" id="changed-files">
<% last_line = line.new_pos.to_s %> <img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= commit_diff.new_path %>
<% line_old = line.old_pos.to_s %> </a>
<table> </div>
<tbody> <div class="autoscroll">
<% if type == "match" %> <%= render 'repositories/change_diff', :local => {:change => commit_diff} %>
<tr> </div>
<td class="old_line"><%= line_old.center(4) %></td>
<td class="new_line"><%= last_line.center(4) %></td>
<td class="line_content"><%= line.text %></td>
</tr>
<% else %>
<% old_line = type == 'new' ? ' '*4: line_old %>
<% new_line = type == 'old' ? ' '*4: last_line %>
<tr>
<td class="old_line"><%= old_line.to_s.center(4) %></td>
<td class="new_line"><%= new_line.to_s.center(4) %></td>
<td class="line_content"><%= line.text %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %> <% end %>
</div> </div>