debian-mirror-gitlab/app/controllers/projects/compare_controller.rb

65 lines
1.7 KiB
Ruby
Raw Normal View History

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-08-24 12:49:21 +05:30
include DiffForPath
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-08-24 12:49:21 +05:30
before_action :define_ref_vars, only: [:index, :show, :diff_for_path]
before_action :define_diff_vars, only: [:show, :diff_for_path]
2016-04-02 18:10:28 +05:30
before_action :merge_request, only: [:index, :show]
2014-09-02 18:07:02 +05:30
def index
end
def show
2016-08-24 12:49:21 +05:30
end
2014-09-02 18:07:02 +05:30
2016-08-24 12:49:21 +05:30
def diff_for_path
return render_404 unless @compare
render_diff_for_path(@diffs, @diff_refs, @project)
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
2016-08-24 12:49:21 +05:30
def define_ref_vars
@start_ref = Addressable::URI.unescape(params[:from])
2016-04-02 18:10:28 +05:30
@ref = @head_ref = Addressable::URI.unescape(params[:to])
end
2016-08-24 12:49:21 +05:30
def define_diff_vars
@compare = CompareService.new.execute(@project, @head_ref, @project, @start_ref)
if @compare
@commits = Commit.decorate(@compare.commits, @project)
@start_commit = @project.commit(@start_ref)
@commit = @project.commit(@head_ref)
@base_commit = @project.merge_base_commit(@start_ref, @head_ref)
@diffs = @compare.diffs(diff_options)
@diff_refs = Gitlab::Diff::DiffRefs.new(
base_sha: @base_commit.try(:sha),
start_sha: @start_commit.try(:sha),
head_sha: @commit.try(:sha)
)
@diff_notes_disabled = true
@grouped_diff_notes = {}
end
end
2016-04-02 18:10:28 +05:30
def merge_request
@merge_request ||= @project.merge_requests.opened.
2016-08-24 12:49:21 +05:30
find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
2016-04-02 18:10:28 +05:30
end
2014-09-02 18:07:02 +05:30
end