Commit da4f0f14 authored by George Tsiolis's avatar George Tsiolis

Move merge requests EE helper methods

parent 4cefac10
module MergeRequestsHelper module MergeRequestsHelper
prepend EE::MergeRequestsHelper
def new_mr_path_from_push_event(event) def new_mr_path_from_push_event(event)
target_project = event.project.default_merge_request_target target_project = event.project.default_merge_request_target
project_new_merge_request_path( project_new_merge_request_path(
...@@ -59,46 +61,6 @@ module MergeRequestsHelper ...@@ -59,46 +61,6 @@ module MergeRequestsHelper
) )
end end
def render_items_list(items, separator = "and")
items_cnt = items.size
case items_cnt
when 1
items.first
when 2
"#{items.first} #{separator} #{items.last}"
else
last_item = items.pop
"#{items.join(", ")} #{separator} #{last_item}"
end
end
# This may be able to be removed with associated specs
def render_require_section(merge_request)
str = if merge_request.approvals_left == 1
"Requires one more approval"
else
"Requires #{merge_request.approvals_left} more approvals"
end
if merge_request.approvers_left.any?
more_approvals = merge_request.approvals_left - merge_request.approvers_left.count
approvers_names = merge_request.approvers_left.map(&:name)
str <<
if more_approvals > 0
" (from #{render_items_list(approvers_names + ["#{more_approvals} more"])})"
elsif more_approvals < 0
" (from #{render_items_list(approvers_names, "or")})"
else
" (from #{render_items_list(approvers_names)})"
end
end
str
end
def format_mr_branch_names(merge_request) def format_mr_branch_names(merge_request)
source_path = merge_request.source_project_path source_path = merge_request.source_project_path
target_path = merge_request.target_project_path target_path = merge_request.target_project_path
......
module EE
module MergeRequestsHelper
def render_items_list(items, separator = "and")
items_cnt = items.size
case items_cnt
when 1
items.first
when 2
"#{items.first} #{separator} #{items.last}"
else
last_item = items.pop
"#{items.join(", ")} #{separator} #{last_item}"
end
end
# This may be able to be removed with associated specs
def render_require_section(merge_request)
str = if merge_request.approvals_left == 1
"Requires one more approval"
else
"Requires #{merge_request.approvals_left} more approvals"
end
if merge_request.approvers_left.any?
more_approvals = merge_request.approvals_left - merge_request.approvers_left.count
approvers_names = merge_request.approvers_left.map(&:name)
str <<
if more_approvals > 0
" (from #{render_items_list(approvers_names + ["#{more_approvals} more"])})"
elsif more_approvals < 0
" (from #{render_items_list(approvers_names, "or")})"
else
" (from #{render_items_list(approvers_names)})"
end
end
str
end
end
end
---
title: Move merge requests EE helper methods
merge_request: 6461
author: George Tsiolis
type: other
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment