diff --git a/.rubocop_todo/layout/line_length.yml b/.rubocop_todo/layout/line_length.yml index 23c42bfcccfb48d2b24140eca537bbf6927a2b6f..07a492e1de601e12495015d87889535ee2a9d18b 100644 --- a/.rubocop_todo/layout/line_length.yml +++ b/.rubocop_todo/layout/line_length.yml @@ -32,21 +32,6 @@ Layout/LineLength: - 'app/controllers/jwt_controller.rb' - 'app/controllers/omniauth_callbacks_controller.rb' - 'app/controllers/profiles/chat_names_controller.rb' - - 'app/controllers/profiles/two_factor_auths_controller.rb' - - 'app/controllers/projects/analytics/cycle_analytics/summary_controller.rb' - - 'app/controllers/projects/blame_controller.rb' - - 'app/controllers/projects/blob_controller.rb' - - 'app/controllers/projects/branches_controller.rb' - - 'app/controllers/projects/build_artifacts_controller.rb' - - 'app/controllers/projects/commit_controller.rb' - - 'app/controllers/projects/compare_controller.rb' - - 'app/controllers/projects/cycle_analytics/events_controller.rb' - - 'app/controllers/projects/cycle_analytics_controller.rb' - - 'app/controllers/projects/discussions_controller.rb' - - 'app/controllers/projects/environments_controller.rb' - - 'app/controllers/projects/error_tracking/stack_traces_controller.rb' - - 'app/controllers/projects/forks_controller.rb' - - 'app/controllers/projects/google_cloud/gcp_regions_controller.rb' - 'app/controllers/projects/issues_controller.rb' - 'app/controllers/projects/jobs_controller.rb' - 'app/controllers/projects/labels_controller.rb' diff --git a/app/controllers/profiles/two_factor_auths_controller.rb b/app/controllers/profiles/two_factor_auths_controller.rb index 0f37f052183fa8f24d85d207105932be50dcac66..f5d76740b924b8755e28fcdb15cb72b07797fbbe 100644 --- a/app/controllers/profiles/two_factor_auths_controller.rb +++ b/app/controllers/profiles/two_factor_auths_controller.rb @@ -3,7 +3,9 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController skip_before_action :check_two_factor_requirement before_action :ensure_verified_primary_email, only: [:show, :create] - before_action :validate_current_password, only: [:create, :codes, :destroy, :destroy_otp, :destroy_webauthn, :create_webauthn], if: :current_password_required? + before_action :validate_current_password, + only: [:create, :codes, :destroy, :destroy_otp, :destroy_webauthn, :create_webauthn], + if: :current_password_required? before_action :update_current_user_otp!, only: [:show] helper_method :current_password_required? @@ -44,7 +46,11 @@ def create end def create_webauthn - @webauthn_registration = Webauthn::RegisterService.new(current_user, device_registration_params, session[:challenge]).execute + @webauthn_registration = Webauthn::RegisterService.new( + current_user, + device_registration_params, + session[:challenge] + ).execute notice = _("Your WebAuthn device was registered!") if @webauthn_registration.persisted? @@ -82,7 +88,9 @@ def destroy result = TwoFactor::DestroyService.new(current_user, user: current_user).execute if result[:status] == :success - redirect_to profile_account_path, status: :found, notice: _('Two-factor authentication has been disabled successfully!') + redirect_to profile_account_path, + status: :found, + notice: _('Two-factor authentication has been disabled successfully!') else redirect_to profile_account_path, status: :found, alert: result[:message] end @@ -92,7 +100,9 @@ def destroy_otp result = TwoFactor::DestroyOtpService.new(current_user, user: current_user).execute if result[:status] == :success - redirect_to profile_two_factor_auth_path, status: :found, notice: _('One-time password authenticator has been deleted!') + redirect_to profile_two_factor_auth_path, + status: :found, + notice: _('One-time password authenticator has been deleted!') else redirect_to profile_two_factor_auth_path, status: :found, alert: result[:message] end @@ -201,15 +211,22 @@ def webauthn_options def groups_notification(groups) group_links = groups.map { |group| view_context.link_to group.full_name, group_path(group) }.to_sentence - leave_group_links = groups.map { |group| view_context.link_to (s_("leave %{group_name}") % { group_name: group.full_name }), leave_group_members_path(group), remote: false, method: :delete }.to_sentence - - s_(%(The group settings for %{group_links} require you to enable Two-Factor Authentication for your account. You can %{leave_group_links}.)) - .html_safe % { group_links: group_links.html_safe, leave_group_links: leave_group_links.html_safe } + leave_group_links = groups.map do |group| + view_context.link_to (s_("leave %{group_name}") % { group_name: group.full_name }), + leave_group_members_path(group), + remote: false, method: :delete + end.to_sentence + + s_( + 'The group settings for %{group_links} require you to enable Two-Factor Authentication for your account. ' \ + 'You can %{leave_group_links}.' + ).html_safe % { group_links: group_links.html_safe, leave_group_links: leave_group_links.html_safe } end def ensure_verified_primary_email unless current_user.two_factor_enabled? || current_user.primary_email_verified? - redirect_to profile_emails_path, notice: s_('You need to verify your primary email first before enabling Two-Factor Authentication.') + redirect_to profile_emails_path, + notice: s_('You need to verify your primary email first before enabling Two-Factor Authentication.') end end @@ -221,7 +238,8 @@ def setup_show_page _('The global settings require you to enable Two-Factor Authentication for your account.') end, admin_2fa: ->(_) do - flash.now[:alert] = _('Administrator users are required to enable Two-Factor Authentication for their account.') + flash.now[:alert] = + _('Administrator users are required to enable Two-Factor Authentication for their account.') end, group: ->(groups) do flash.now[:alert] = groups_notification(groups) @@ -231,7 +249,11 @@ def setup_show_page unless two_factor_grace_period_expired? grace_period_deadline = current_user.otp_grace_period_started_at + two_factor_grace_period.hours - flash.now[:alert] = flash.now[:alert] + (_(" You need to do this before %{grace_period_deadline}.") % { grace_period_deadline: l(grace_period_deadline) }) + flash.now[:alert] = flash.now[:alert] + ( + _(" You need to do this before %{grace_period_deadline}.") % { + grace_period_deadline: l(grace_period_deadline) + } + ) end end diff --git a/app/controllers/projects/analytics/cycle_analytics/summary_controller.rb b/app/controllers/projects/analytics/cycle_analytics/summary_controller.rb index 1f58b97867f262b0d7e5571b253445216c1b3665..63cf141f0ccbb14de2b095c73d6fac788c8d9ca8 100644 --- a/app/controllers/projects/analytics/cycle_analytics/summary_controller.rb +++ b/app/controllers/projects/analytics/cycle_analytics/summary_controller.rb @@ -31,4 +31,10 @@ def allowed_params end end -Projects::Analytics::CycleAnalytics::SummaryController.prepend_mod_with('Projects::Analytics::CycleAnalytics::SummaryController') +# rubocop: disable Cop/InjectEnterpriseEditionModule -- Injecting extension modules must be done on the last line +# of the file. In this case, the line would be too long which would trigger the RuboCop rule Layout/LineLength. +# Hence, Cop/InjectEnterpriseEditionModule was disabled. +Projects::Analytics::CycleAnalytics::SummaryController.prepend_mod_with( + 'Projects::Analytics::CycleAnalytics::SummaryController' +) +# rubocop: enable Cop/InjectEnterpriseEditionModule diff --git a/app/controllers/projects/blame_controller.rb b/app/controllers/projects/blame_controller.rb index 94ae9791bc7a115e4e158c758b3b7ba35924557f..ff5f1c38d56d7bcb7a79b2af6e9216f41f8d01db 100644 --- a/app/controllers/projects/blame_controller.rb +++ b/app/controllers/projects/blame_controller.rb @@ -45,13 +45,18 @@ def load_blob def require_non_binary_blob return unless @blob.binary? - redirect_to project_blob_path(@project, File.join(@ref, @path)), notice: _('Blame for binary files is not supported.') + redirect_to project_blob_path(@project, File.join(@ref, @path)), + notice: _('Blame for binary files is not supported.') end def load_environment environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit } environment_params[:find_latest] = true - @environment = ::Environments::EnvironmentsByDeploymentsFinder.new(@project, current_user, environment_params).execute.last + @environment = ::Environments::EnvironmentsByDeploymentsFinder.new( + @project, + current_user, + environment_params + ).execute.last end def load_blame @@ -59,7 +64,12 @@ def load_blame @blame_pagination = Gitlab::Git::BlamePagination.new(@blob, @blame_mode, blame_params) blame = Gitlab::Blame.new(@blob, @commit, range: @blame_pagination.blame_range) - @blame = Gitlab::View::Presenter::Factory.new(blame, project: @project, path: @path, page: @blame_pagination.page).fabricate! + @blame = Gitlab::View::Presenter::Factory.new( + blame, + project: @project, + path: @path, + page: @blame_pagination.page + ).fabricate! end def blame_params diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 86eb4b5807c01bad793ca4941d5a41ec66e27d3b..05470ceec9e377e1d291b05b235126492ec79b60 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -185,7 +185,11 @@ def assign_blob_vars # rubocop: disable CodeReuse/ActiveRecord def after_edit_path - from_merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).find_by(iid: params[:from_merge_request_iid]) + from_merge_request = MergeRequestsFinder.new( + current_user, + project_id: @project.id + ).find_by(iid: params[:from_merge_request_iid]) + if from_merge_request && @branch_name == @ref diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request) + "##{hexdigest(@path)}" @@ -251,7 +255,11 @@ def set_last_commit_sha def show_html environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: commit } environment_params[:find_latest] = true - @environment = ::Environments::EnvironmentsByDeploymentsFinder.new(@project, current_user, environment_params).execute.last + @environment = ::Environments::EnvironmentsByDeploymentsFinder.new( + @project, + current_user, + environment_params + ).execute.last @last_commit = @repository.last_commit_for_path(commit.id, blob.path, literal_pathspec: true) @code_navigation_path = Gitlab::CodeNavigationPath.new(@project, blob.commit_id).full_json_path_for(blob.path) diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index 34ff7be80a3b53335dfcdc3cce7b0d7bea8a71d1..5bf757d961db3d67a8779981269baff790983dd8 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -129,7 +129,8 @@ def destroy_all_merged ::Branches::DeleteMergedService.new(@project, current_user).async_execute redirect_to project_branches_path(@project), - notice: _('Merged branches are being deleted. This can take some time depending on the number of branches. Please refresh the page to see changes.') + notice: _('Merged branches are being deleted. This can take some time depending on the number of branches. ' \ + 'Please refresh the page to see changes.') end private @@ -191,8 +192,11 @@ def url_to_autodeploy_setup(project, branch_name) def redirect_for_legacy_index_sort_or_search # Normalize a legacy URL with redirect - if request.format != :json && !branches_params[:state].presence && [:sort, :search, :page].any? { |key| branches_params[key].presence } - redirect_to project_branches_filtered_path(@project, state: 'all'), notice: _('Update your bookmarked URLs as filtered/sorted branches URL has been changed.') + if request.format != :json && !branches_params[:state].presence && [:sort, :search, :page].any? do |key| + branches_params[key].presence + end + redirect_to project_branches_filtered_path(@project, state: 'all'), + notice: _('Update your bookmarked URLs as filtered/sorted branches URL has been changed.') end end diff --git a/app/controllers/projects/build_artifacts_controller.rb b/app/controllers/projects/build_artifacts_controller.rb index f70e490341dead4e5b1a7c5f6874d0049339bb9e..53e4b31ec394484dbbab1c3994c4a8fff7d650db 100644 --- a/app/controllers/projects/build_artifacts_controller.rb +++ b/app/controllers/projects/build_artifacts_controller.rb @@ -26,7 +26,12 @@ def raw end def latest_succeeded - redirect_to latest_succeeded_project_artifacts_path(project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job]) + redirect_to latest_succeeded_project_artifacts_path( + project, + job, + ref_name_and_path: params[:ref_name_and_path], + job: params[:job] + ) end private diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index e2b53ea3277c57bf30fe5e4d537bad028ee05a81..a7fe92fced0c1e55e9cd74e0ed6cc877d75faa27 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -16,7 +16,8 @@ class Projects::CommitController < Projects::ApplicationController before_action :authorize_read_code! before_action :authorize_read_pipeline!, only: [:pipelines] before_action :commit - before_action :define_commit_vars, only: [:show, :diff_for_path, :diff_files, :pipelines, :merge_requests, :rapid_diffs] + before_action :define_commit_vars, + only: [:show, :diff_for_path, :diff_files, :pipelines, :merge_requests, :rapid_diffs] before_action :define_commit_box_vars, only: [:show, :pipelines, :rapid_diffs] before_action :define_note_vars, only: [:show, :diff_for_path, :diff_files] before_action :authorize_edit_tree!, only: [:revert, :cherry_pick] @@ -54,7 +55,9 @@ def diff_for_path def diff_files respond_to do |format| format.html do - render template: 'projects/commit/diff_files', layout: false, locals: { diffs: @diffs, environment: @environment } + render template: 'projects/commit/diff_files', + layout: false, + locals: { diffs: @diffs, environment: @environment } end end end @@ -145,7 +148,8 @@ def cherry_pick create_commit( Commits::CherryPickService, - success_notice: "The #{@commit.change_type_title(current_user)} has been successfully cherry-picked into #{@branch_name}.", + success_notice: "The #{@commit.change_type_title(current_user)} has been successfully " \ + "cherry-picked into #{@branch_name}.", success_path: -> { successful_change_path(target_project) }, failure_path: failed_change_path, target_project: target_project @@ -200,7 +204,12 @@ def define_commit_vars return git_not_found! unless commit @diffs = commit.diffs(commit_diff_options) - @environment = ::Environments::EnvironmentsByDeploymentsFinder.new(@project, current_user, commit: @commit, find_latest: true).execute.last + @environment = ::Environments::EnvironmentsByDeploymentsFinder.new( + @project, + current_user, + commit: @commit, + find_latest: true + ).execute.last end # rubocop: disable CodeReuse/ActiveRecord @@ -243,7 +252,10 @@ def define_commit_box_vars return unless @commit.last_pipeline - @last_pipeline_stages = StageSerializer.new(project: @project, current_user: @current_user).represent(@last_pipeline.stages) + @last_pipeline_stages = StageSerializer.new( + project: @project, + current_user: @current_user + ).represent(@last_pipeline.stages) end def assign_change_commit_vars diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index ac859b96b8e6a6f3d159b38f60ec0ceb053f36fd..8c25e923894b7656f5dbc5909e90113a53a0dca9 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -167,9 +167,18 @@ def define_diffs def define_environment if compare - environment_params = source_project.repository.branch_exists?(head_ref) ? { ref: head_ref } : { commit: compare.commit } + environment_params = if source_project.repository.branch_exists?(head_ref) + { ref: head_ref } + else + { commit: compare.commit } + end + environment_params[:find_latest] = true - @environment = ::Environments::EnvironmentsByDeploymentsFinder.new(source_project, current_user, environment_params).execute.last + @environment = ::Environments::EnvironmentsByDeploymentsFinder.new( + source_project, + current_user, + environment_params + ).execute.last end end diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index d41a7e4f2df31e50f7bc3ebc229e9d5d172599c2..1372e30db37f185fe95c017291b478833b6ec450 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -54,7 +54,10 @@ def render_events(events) end def cycle_analytics - @cycle_analytics ||= ::Analytics::CycleAnalytics::ProjectLevel.new(project: project, options: options(cycle_analytics_project_params)) + @cycle_analytics ||= ::Analytics::CycleAnalytics::ProjectLevel.new( + project: project, + options: options(cycle_analytics_project_params) + ) end end end diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb index 1509801804376b0810508a2a8cd2f57cf471457e..e569cad13ac1649b2f8154ce91865dd98355b988 100644 --- a/app/controllers/projects/cycle_analytics_controller.rb +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -35,7 +35,10 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController end def show - @cycle_analytics = Analytics::CycleAnalytics::ProjectLevel.new(project: @project, options: options(cycle_analytics_project_params)) + @cycle_analytics = Analytics::CycleAnalytics::ProjectLevel.new( + project: @project, + options: options(cycle_analytics_project_params) + ) @request_params ||= ::Gitlab::Analytics::CycleAnalytics::RequestParams.new(all_cycle_analytics_params) respond_to do |format| diff --git a/app/controllers/projects/discussions_controller.rb b/app/controllers/projects/discussions_controller.rb index 671d19084b39e2888ad7d04a32d13c1ccb8cbaad..43a024a527772f0d79501251178e835d63ece532 100644 --- a/app/controllers/projects/discussions_controller.rb +++ b/app/controllers/projects/discussions_controller.rb @@ -39,7 +39,12 @@ def render_discussion def render_json_with_discussions_serializer render json: - DiscussionSerializer.new(project: project, noteable: discussion.noteable, current_user: current_user, note_entity: ProjectNoteEntity) + DiscussionSerializer.new( + project: project, + noteable: discussion.noteable, + current_user: current_user, + note_entity: ProjectNoteEntity + ) .represent(discussion, context: self, render_truncated_diff_lines: true) end diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 3467a9121f0da5bd8a521446e4950c8b22accd04..54b9f97ba2743d19bb7d107df2d8f1e662ef14d3 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -24,7 +24,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController before_action :authorize_stop_environment!, only: [:stop] before_action :authorize_update_environment!, only: [:edit, :update, :cancel_auto_stop] before_action :authorize_admin_environment!, only: [:terminal, :terminal_websocket_authorize] - before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :cancel_auto_stop, :k8s] + before_action :environment, + only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :cancel_auto_stop, :k8s] before_action :verify_api_request!, only: :terminal_websocket_authorize before_action :expire_etag_cache, only: [:index], unless: -> { request.format.json? } before_action :set_kas_cookie, only: [:edit, :new, :show, :k8s], if: -> { current_user && request.format.html? } @@ -226,7 +227,12 @@ def environment def search_environments(type: nil) search = params[:search] if params[:search] && params[:search].length >= MIN_SEARCH_LENGTH - @search_environments ||= Environments::EnvironmentsFinder.new(project, current_user, type: type, search: search).execute + @search_environments ||= Environments::EnvironmentsFinder.new( + project, + current_user, + type: type, + search: search + ).execute end def include_all_dashboards? diff --git a/app/controllers/projects/error_tracking/stack_traces_controller.rb b/app/controllers/projects/error_tracking/stack_traces_controller.rb index c5d5d6da6a6a94a343fc369bf2ecb763de5ecd97..2203f27dd95c3bae7f90b40b8bfa768aa82243a2 100644 --- a/app/controllers/projects/error_tracking/stack_traces_controller.rb +++ b/app/controllers/projects/error_tracking/stack_traces_controller.rb @@ -11,7 +11,9 @@ def index result = fetch_latest_event_issue if result[:status] == :success - result_with_syntax_highlight = Gitlab::ErrorTracking::StackTraceHighlightDecorator.decorate(result[:latest_event]) + result_with_syntax_highlight = Gitlab::ErrorTracking::StackTraceHighlightDecorator.decorate( + result[:latest_event] + ) render json: { error: serialize_error_event(result_with_syntax_highlight) } else diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb index c23db0a2d2b240cb9354d73c50e37c2552e5bdb5..8992987f76f30dd69633b343883926c1c0defcef 100644 --- a/app/controllers/projects/forks_controller.rb +++ b/app/controllers/projects/forks_controller.rb @@ -82,7 +82,8 @@ def create elsif continue_params[:to] redirect_to continue_params[:to], notice: continue_params[:notice] else - redirect_to project_path(@forked_project), notice: "The project '#{@forked_project.name}' was successfully forked." + redirect_to project_path(@forked_project), + notice: "The project '#{@forked_project.name}' was successfully forked." end end diff --git a/app/controllers/projects/google_cloud/gcp_regions_controller.rb b/app/controllers/projects/google_cloud/gcp_regions_controller.rb index 593e27eeebf5e4098302bee2789f0f0fef4ec089..ea30f9508372a02ae7ec4e7522aa6c3404b2c379 100644 --- a/app/controllers/projects/google_cloud/gcp_regions_controller.rb +++ b/app/controllers/projects/google_cloud/gcp_regions_controller.rb @@ -4,7 +4,18 @@ class Projects::GoogleCloud::GcpRegionsController < Projects::GoogleCloud::BaseC # filtered list of GCP cloud run locations... # ...that have domain mapping available # Source https://cloud.google.com/run/docs/locations 2022-01-30 - AVAILABLE_REGIONS = %w[asia-east1 asia-northeast1 asia-southeast1 europe-north1 europe-west1 europe-west4 us-central1 us-east1 us-east4 us-west1].freeze + AVAILABLE_REGIONS = %w[ + asia-east1 + asia-northeast1 + asia-southeast1 + europe-north1 + europe-west1 + europe-west4 + us-central1 + us-east1 + us-east4 + us-west1 + ].freeze GCP_REGION_CI_VAR_KEY = 'GCP_REGION' @@ -20,7 +31,10 @@ def index def create permitted_params = params.permit(:ref, :gcp_region) - CloudSeed::GoogleCloud::GcpRegionAddOrReplaceService.new(project).execute(permitted_params[:ref], permitted_params[:gcp_region]) + CloudSeed::GoogleCloud::GcpRegionAddOrReplaceService.new(project).execute( + permitted_params[:ref], + permitted_params[:gcp_region] + ) track_event(:configure_region) redirect_to project_google_cloud_configuration_path(project), notice: _('GCP region configured') end