summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2016-12-14 00:30:38 -0600
committerAlfredo Sumaran <alfredo@gitlab.com>2016-12-21 02:36:05 -0500
commit759e37f3b192d791e32bda795f4731b29c17d552 (patch)
treee398b7f8a0ecfc6a0839f42df9af520d9d8a53c6
parent4e3b9e03f8ef64a39f587c53e45b2f8d4cf571db (diff)
downloadgitlab-ce-759e37f3b192d791e32bda795f4731b29c17d552.tar.gz
reduce common code even further to satisfy rake flay
-rw-r--r--app/helpers/commits_helper.rb48
1 files changed, 25 insertions, 23 deletions
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index c7d1de0e3b7..f1897119e20 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -128,31 +128,11 @@ module CommitsHelper
end
def revert_commit_link(commit, continue_to_path, btn_class: nil, has_tooltip: true)
- return unless current_user
-
- tooltip = "Revert this #{commit.change_type_title(current_user)} in a new merge request" if has_tooltip
- btn_class = "btn btn-#{btn_class}" unless btn_class.nil?
-
- if can_collaborate_with_project?
- link_to 'Revert', '#modal-revert-commit', 'data-toggle' => 'modal', 'data-container' => 'body', title: (tooltip if has_tooltip), class: "#{btn_class} #{'has-tooltip' if has_tooltip}"
- elsif can?(current_user, :fork_project, @project)
- fork_path = fork_path_url(continue_to_path, message: 'Try to revert this commit again.')
- link_to 'Revert', fork_path, class: btn_class, method: :post, 'data-toggle' => 'tooltip', 'data-container' => 'body', title: (tooltip if has_tooltip)
- end
+ commit_action_link('revert', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip)
end
def cherry_pick_commit_link(commit, continue_to_path, btn_class: nil, has_tooltip: true)
- return unless current_user
-
- tooltip = "Cherry-pick this #{commit.change_type_title(current_user)} in a new merge request" if has_tooltip
- btn_class = "btn btn-#{btn_class}" unless btn_class.nil?
-
- if can_collaborate_with_project?
- link_to 'Cherry-pick', '#modal-cherry-pick-commit', 'data-toggle' => 'modal', 'data-container' => 'body', title: (tooltip if has_tooltip), class: "#{btn_class} #{'has-tooltip' if has_tooltip}"
- elsif can?(current_user, :fork_project, @project)
- fork_path = fork_path_url(continue_to_path, message: 'Try to cherry-pick this commit again.')
- link_to 'Cherry-pick', fork_path, class: btn_class, method: :post, 'data-toggle' => 'tooltip', 'data-container' => 'body', title: (tooltip if has_tooltip)
- end
+ commit_action_link('cherry-pick', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip)
end
protected
@@ -192,6 +172,28 @@ module CommitsHelper
end
end
+ def commit_action_link(action, commit, continue_to_path, btn_class: nil, has_tooltip: true)
+ return unless current_user
+
+ tooltip = "#{action.capitalize} this #{commit.change_type_title(current_user)} in a new merge request" if has_tooltip
+ btn_class = "btn btn-#{btn_class}" unless btn_class.nil?
+
+ if can_collaborate_with_project?
+ link_to action.capitalize, "#modal-#{action}-commit", 'data-toggle' => 'modal', 'data-container' => 'body', title: (tooltip if has_tooltip), class: "#{btn_class} #{'has-tooltip' if has_tooltip}"
+ elsif can?(current_user, :fork_project, @project)
+ continue_params = {
+ to: continue_to_path,
+ notice: "#{edit_in_new_fork_notice} Try to #{action} this commit again.",
+ notice_now: edit_in_new_fork_notice_now
+ }
+ fork_path = namespace_project_forks_path(@project.namespace, @project,
+ namespace_key: current_user.namespace.id,
+ continue: continue_params)
+
+ link_to action.capitalize, fork_path, class: btn_class, method: :post, 'data-toggle' => 'tooltip', 'data-container' => 'body', title: (tooltip if has_tooltip)
+ end
+ end
+
def fork_path_url(continue_to_path, message: nil)
notice = edit_in_new_fork_notice
notice << " #{message}" unless message.nil?
@@ -201,7 +203,7 @@ module CommitsHelper
notice: notice,
notice_now: edit_in_new_fork_notice_now
}
- fork_path = namespace_project_forks_path(@project.namespace, @project,
+ namespace_project_forks_path(@project.namespace, @project,
namespace_key: current_user.namespace.id,
continue: continue_params)
end