From 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Feb 2021 10:34:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-9-stable-ee --- app/helpers/commits_helper.rb | 54 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) (limited to 'app/helpers/commits_helper.rb') diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index e6e2b5b128b..f5c75d62097 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -105,31 +105,35 @@ module CommitsHelper tooltip = _("Browse Directory") end - link_to url, class: "btn btn-default has-tooltip", title: tooltip, data: { container: "body" } do + link_to url, class: "btn gl-button btn-default has-tooltip", title: tooltip, data: { container: "body" } do sprite_icon('folder-open') end end - def revert_commit_link(commit, continue_to_path, btn_class: nil, pajamas: false) + def revert_commit_link return unless current_user - action = 'revert' - - if pajamas && can_collaborate_with_project?(@project) - tag(:div, data: { display_text: action.capitalize }, class: "js-revert-commit-trigger") - else - commit_action_link(action, commit, continue_to_path, btn_class: btn_class, has_tooltip: false) - end + tag(:div, data: { display_text: 'Revert' }, class: "js-revert-commit-trigger") end - def cherry_pick_commit_link(commit, continue_to_path, btn_class: nil, has_tooltip: true) - commit_action_link('cherry-pick', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip) + def cherry_pick_commit_link + return unless current_user + + tag(:div, data: { display_text: 'Cherry-pick' }, class: "js-cherry-pick-commit-trigger") end def commit_signature_badge_classes(additional_classes) %w(btn gpg-status-box) + Array(additional_classes) end + def conditionally_paginate_diff_files(diffs, paginate:, per: Projects::CommitController::COMMIT_DIFFS_PER_PAGE) + if paginate && Feature.enabled?(:paginate_commit_view, @project, type: :development) + Kaminari.paginate_array(diffs.diff_files.to_a).page(params[:page]).per(per) + else + diffs.diff_files + end + end + protected # Private: Returns a link to a person. If the person has a matching user and @@ -143,7 +147,7 @@ module CommitsHelper def commit_person_link(commit, options = {}) user = commit.public_send(options[:source]) # rubocop:disable GitlabSecurity/PublicSend - source_name = clean(commit.public_send(:"#{options[:source]}_name")) # rubocop:disable GitlabSecurity/PublicSend + source_name = clean(commit.public_send(:"#{options[:source]}_name")) # rubocop:disable GitlabSecurity/PublicSend source_email = clean(commit.public_send(:"#{options[:source]}_email")) # rubocop:disable GitlabSecurity/PublicSend person_name = user.try(:name) || source_name @@ -166,33 +170,11 @@ 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?(@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 = project_forks_path(@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 view_file_button(commit_sha, diff_new_path, project, replaced: false) path = project_blob_path(project, tree_join(commit_sha, diff_new_path)) title = replaced ? _('View replaced file @ ') : _('View file @ ') - link_to(path, class: 'btn') do + link_to(path, class: 'btn gl-button btn-default') do raw(title) + content_tag(:span, truncate_sha(commit_sha), class: 'commit-sha') end end @@ -203,7 +185,7 @@ module CommitsHelper external_url = environment.external_url_for(diff_new_path, commit_sha) return unless external_url - link_to(external_url, class: 'btn btn-file-option has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: "View on #{environment.formatted_external_url}", data: { container: 'body' }) do + link_to(external_url, class: 'btn gl-button btn-default btn-file-option has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: "View on #{environment.formatted_external_url}", data: { container: 'body' }) do sprite_icon('external-link') end end -- cgit v1.2.1