2015-09-11 14:41:01 +05:30
|
|
|
require 'addressable/uri'
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Projects::CompareController < Projects::ApplicationController
|
2016-06-02 11:05:42 +05:30
|
|
|
include DiffHelper
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Authorize
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :assign_ref_vars, only: [:index, :show]
|
|
|
|
before_action :merge_request, only: [:index, :show]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-06-02 11:05:42 +05:30
|
|
|
compare = CompareService.new.
|
2016-04-02 18:10:28 +05:30
|
|
|
execute(@project, @head_ref, @project, @base_ref, diff_options)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
if compare
|
|
|
|
@commits = Commit.decorate(compare.commits, @project)
|
2016-04-02 18:10:28 +05:30
|
|
|
@commit = @project.commit(@head_ref)
|
|
|
|
@base_commit = @project.merge_base_commit(@base_ref, @head_ref)
|
2016-06-02 11:05:42 +05:30
|
|
|
@diffs = compare.diffs(diff_options)
|
2016-01-29 22:53:50 +05:30
|
|
|
@diff_refs = [@base_commit, @commit]
|
2016-06-02 11:05:42 +05:30
|
|
|
@diff_notes_disabled = true
|
|
|
|
@grouped_diff_notes = {}
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to namespace_project_compare_path(@project.namespace, @project,
|
|
|
|
params[:from], params[:to])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|