2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-09-12 13:15:10 -04:00
|
|
|
module CompareHelper
|
2021-02-22 10:10:48 -05:00
|
|
|
def create_mr_button?(from: params[:from], to: params[:to], source_project: @project, target_project: @target_project)
|
2015-05-09 17:51:50 -04:00
|
|
|
from.present? &&
|
2015-05-09 16:26:25 -04:00
|
|
|
to.present? &&
|
|
|
|
from != to &&
|
2021-02-22 10:10:48 -05:00
|
|
|
can?(current_user, :create_merge_request_from, source_project) &&
|
|
|
|
can?(current_user, :create_merge_request_in, target_project) &&
|
|
|
|
target_project.repository.branch_exists?(from) &&
|
|
|
|
source_project.repository.branch_exists?(to)
|
2013-09-12 13:15:10 -04:00
|
|
|
end
|
|
|
|
|
2021-02-22 10:10:48 -05:00
|
|
|
def create_mr_path(from: params[:from], to: params[:to], source_project: @project, target_project: @target_project)
|
2017-06-29 13:06:35 -04:00
|
|
|
project_new_merge_request_path(
|
2021-02-22 10:10:48 -05:00
|
|
|
target_project,
|
2015-01-24 13:02:58 -05:00
|
|
|
merge_request: {
|
2021-02-22 10:10:48 -05:00
|
|
|
source_project_id: source_project.id,
|
2018-11-07 08:32:20 -05:00
|
|
|
source_branch: to,
|
2021-02-22 10:10:48 -05:00
|
|
|
target_project_id: target_project.id,
|
2015-05-09 16:26:25 -04:00
|
|
|
target_branch: from
|
2015-01-24 13:02:58 -05:00
|
|
|
}
|
|
|
|
)
|
2013-09-12 13:15:10 -04:00
|
|
|
end
|
2021-02-22 10:10:48 -05:00
|
|
|
|
|
|
|
def target_projects(source_project)
|
|
|
|
MergeRequestTargetProjectFinder
|
|
|
|
.new(current_user: current_user, source_project: source_project, project_feature: :repository)
|
|
|
|
.execute(include_routes: true)
|
|
|
|
end
|
2021-02-24 16:11:16 -05:00
|
|
|
|
|
|
|
def project_compare_selector_data(project, merge_request, params)
|
|
|
|
{
|
|
|
|
project_compare_index_path: project_compare_index_path(project),
|
|
|
|
refs_project_path: refs_project_path(project),
|
|
|
|
params_from: params[:from],
|
|
|
|
params_to: params[:to],
|
|
|
|
project_merge_request_path: merge_request.present? ? project_merge_request_path(project, merge_request) : '',
|
|
|
|
create_mr_path: create_mr_button? ? create_mr_path : ''
|
|
|
|
}.tap do |data|
|
2021-08-09 02:10:01 -04:00
|
|
|
data[:project_to] = { id: project.id, name: project.full_path }.to_json
|
|
|
|
data[:projects_from] = target_projects(project).map { |project| { id: project.id, name: project.full_path } }.to_json
|
2021-02-24 16:11:16 -05:00
|
|
|
end
|
|
|
|
end
|
2013-09-12 13:15:10 -04:00
|
|
|
end
|