2015-04-27 02:42:29 -04:00
|
|
|
require 'addressable/uri'
|
|
|
|
|
2013-06-23 12:47:22 -04:00
|
|
|
class Projects::CompareController < Projects::ApplicationController
|
2016-03-03 12:38:44 -05:00
|
|
|
include DiffHelper
|
|
|
|
|
2012-09-20 15:20:48 -04:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2016-02-01 18:43:51 -05:00
|
|
|
before_action :assign_ref_vars, only: [:index, :show]
|
|
|
|
before_action :merge_request, only: [:index, :show]
|
2012-09-20 15:20:48 -04:00
|
|
|
|
2012-09-25 23:10:50 -04:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
2012-09-20 15:20:48 -04:00
|
|
|
def show
|
2016-03-03 12:38:44 -05:00
|
|
|
compare = CompareService.new.
|
2016-02-01 18:43:51 -05:00
|
|
|
execute(@project, @head_ref, @project, @base_ref, diff_options)
|
2014-07-29 05:33:51 -04:00
|
|
|
|
2016-03-03 12:38:44 -05:00
|
|
|
if compare
|
|
|
|
@commits = Commit.decorate(compare.commits, @project)
|
2016-02-01 18:43:51 -05:00
|
|
|
@commit = @project.commit(@head_ref)
|
|
|
|
@base_commit = @project.merge_base_commit(@base_ref, @head_ref)
|
2016-03-03 12:38:44 -05:00
|
|
|
@diffs = compare.diffs(diff_options)
|
2016-01-20 12:44:27 -05:00
|
|
|
@diff_refs = [@base_commit, @commit]
|
2016-05-13 15:53:04 -04:00
|
|
|
@diff_notes_disabled = true
|
2016-05-10 18:41:46 -04:00
|
|
|
@grouped_diff_notes = {}
|
2015-09-18 15:02:01 -04:00
|
|
|
end
|
2012-09-20 15:20:48 -04:00
|
|
|
end
|
2012-09-25 23:10:50 -04:00
|
|
|
|
|
|
|
def create
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_compare_path(@project.namespace, @project,
|
|
|
|
params[:from], params[:to])
|
2012-09-25 23:10:50 -04:00
|
|
|
end
|
2016-02-01 18:43:51 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def assign_ref_vars
|
|
|
|
@base_ref = Addressable::URI.unescape(params[:from])
|
|
|
|
@ref = @head_ref = Addressable::URI.unescape(params[:to])
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
@merge_request ||= @project.merge_requests.opened.
|
|
|
|
find_by(source_project: @project, source_branch: @head_ref, target_branch: @base_ref)
|
|
|
|
end
|
2012-09-20 15:20:48 -04:00
|
|
|
end
|