debian-mirror-gitlab/app/helpers/compare_helper.rb

46 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module CompareHelper
2021-04-17 20:07:23 +05:30
def create_mr_button?(from: params[:from], to: params[:to], source_project: @project, target_project: @target_project)
2015-09-11 14:41:01 +05:30
from.present? &&
to.present? &&
from != to &&
2021-04-17 20:07:23 +05:30
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)
2014-09-02 18:07:02 +05:30
end
2021-04-17 20:07:23 +05:30
def create_mr_path(from: params[:from], to: params[:to], source_project: @project, target_project: @target_project)
2017-09-10 17:25:29 +05:30
project_new_merge_request_path(
2021-04-17 20:07:23 +05:30
target_project,
2015-04-26 12:48:37 +05:30
merge_request: {
2021-04-17 20:07:23 +05:30
source_project_id: source_project.id,
2015-09-11 14:41:01 +05:30
source_branch: to,
2021-04-17 20:07:23 +05:30
target_project_id: target_project.id,
2015-09-11 14:41:01 +05:30
target_branch: from
2015-04-26 12:48:37 +05:30
}
)
2014-09-02 18:07:02 +05:30
end
2021-04-17 20:07:23 +05:30
def target_projects(source_project)
MergeRequestTargetProjectFinder
.new(current_user: current_user, source_project: source_project, project_feature: :repository)
.execute(include_routes: true)
end
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-10-27 15:23:28 +05:30
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-04-17 20:07:23 +05:30
end
end
2014-09-02 18:07:02 +05:30
end