diff options
author | Robert Speicher <robert@gitlab.com> | 2018-09-13 17:53:05 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-09-13 17:53:05 +0300 |
commit | c7d1eef671dbf598814a6c2ff1f81b924583ae8a (patch) | |
tree | 23988df1d29e933943858a66821ba7f493976b3e /app | |
parent | ff5d8b635f234241441009e41af7b61f5804b2c2 (diff) | |
parent | 2039c8280db1646845c33d6c5a74e5f23ca6f4de (diff) |
Merge branch 'rubocop-code-reuse' into 'master'
Add RuboCop cops to enforce code reusing rules
See merge request gitlab-org/gitlab-ce!21391
Diffstat (limited to 'app')
328 files changed, 1152 insertions, 32 deletions
diff --git a/app/controllers/abuse_reports_controller.rb b/app/controllers/abuse_reports_controller.rb index ed13ead63f9..51547ed7eaf 100644 --- a/app/controllers/abuse_reports_controller.rb +++ b/app/controllers/abuse_reports_controller.rb @@ -30,6 +30,7 @@ class AbuseReportsController < ApplicationController )) end + # rubocop: disable CodeReuse/ActiveRecord def set_user @user = User.find_by(id: params[:user_id]) @@ -39,4 +40,5 @@ class AbuseReportsController < ApplicationController redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked." end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/abuse_reports_controller.rb b/app/controllers/admin/abuse_reports_controller.rb index dc9a6df5f75..68a49f0749f 100644 --- a/app/controllers/admin/abuse_reports_controller.rb +++ b/app/controllers/admin/abuse_reports_controller.rb @@ -1,8 +1,10 @@ class Admin::AbuseReportsController < Admin::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @abuse_reports = AbuseReport.order(id: :desc).page(params[:page]) @abuse_reports.includes(:reporter, :user) end + # rubocop: enable CodeReuse/ActiveRecord def destroy abuse_report = AbuseReport.find(params[:id]) diff --git a/app/controllers/admin/applications_controller.rb b/app/controllers/admin/applications_controller.rb index 5be23c76a95..daa21d1be93 100644 --- a/app/controllers/admin/applications_controller.rb +++ b/app/controllers/admin/applications_controller.rb @@ -4,9 +4,11 @@ class Admin::ApplicationsController < Admin::ApplicationController before_action :set_application, only: [:show, :edit, :update, :destroy] before_action :load_scopes, only: [:new, :create, :edit, :update] + # rubocop: disable CodeReuse/ActiveRecord def index @applications = Doorkeeper::Application.where("owner_id IS NULL") end + # rubocop: enable CodeReuse/ActiveRecord def show end @@ -45,9 +47,11 @@ class Admin::ApplicationsController < Admin::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def set_application @application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord # Only allow a trusted parameter "white list" through. def application_params diff --git a/app/controllers/admin/broadcast_messages_controller.rb b/app/controllers/admin/broadcast_messages_controller.rb index a9109a1d4d0..b2fbbfc3e64 100644 --- a/app/controllers/admin/broadcast_messages_controller.rb +++ b/app/controllers/admin/broadcast_messages_controller.rb @@ -3,10 +3,12 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController before_action :finder, only: [:edit, :update, :destroy] + # rubocop: disable CodeReuse/ActiveRecord def index @broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page]) @broadcast_message = BroadcastMessage.new end + # rubocop: enable CodeReuse/ActiveRecord def edit end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 737942f3eb2..5dc3e6c2990 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -4,10 +4,12 @@ class Admin::DashboardController < Admin::ApplicationController COUNTED_ITEMS = [Project, User, Group, ForkedProjectLink, Issue, MergeRequest, Note, Snippet, Key, Milestone].freeze + # rubocop: disable CodeReuse/ActiveRecord def index @counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS) @projects = Project.order_id_desc.without_deleted.with_route.limit(10) @users = User.order_id_desc.limit(10) @groups = Group.order_id_desc.with_route.limit(10) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index d7a5b745d3f..2a47f01c6ad 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -10,6 +10,7 @@ class Admin::GroupsController < Admin::ApplicationController @groups = @groups.page(params[:page]) end + # rubocop: disable CodeReuse/ActiveRecord def show @group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id]) @members = present_members( @@ -18,6 +19,7 @@ class Admin::GroupsController < Admin::ApplicationController AccessRequestsFinder.new(@group).execute(current_user)) @projects = @group.projects.with_statistics.page(params[:projects_page]) end + # rubocop: enable CodeReuse/ActiveRecord def new @group = Group.new diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index ceb45865804..57ad7389a23 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -44,9 +44,11 @@ class Admin::IdentitiesController < Admin::ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:user_id]) end + # rubocop: enable CodeReuse/ActiveRecord def identity @identity ||= user.identities.find(params[:id]) diff --git a/app/controllers/admin/impersonation_tokens_controller.rb b/app/controllers/admin/impersonation_tokens_controller.rb index a7b562b1d8e..9ebba88ef16 100644 --- a/app/controllers/admin/impersonation_tokens_controller.rb +++ b/app/controllers/admin/impersonation_tokens_controller.rb @@ -30,9 +30,11 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:user_id]) end + # rubocop: enable CodeReuse/ActiveRecord def finder(options = {}) PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options)) @@ -42,6 +44,7 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: []) end + # rubocop: disable CodeReuse/ActiveRecord def set_index_vars @scopes = Gitlab::Auth.available_scopes(current_user) @@ -49,4 +52,5 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController @inactive_impersonation_tokens = finder(state: 'inactive').execute @active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/jobs_controller.rb b/app/controllers/admin/jobs_controller.rb index e355d5fdea7..788693c62c4 100644 --- a/app/controllers/admin/jobs_controller.rb +++ b/app/controllers/admin/jobs_controller.rb @@ -1,4 +1,5 @@ class Admin::JobsController < Admin::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @scope = params[:scope] @all_builds = Ci::Build @@ -16,6 +17,7 @@ class Admin::JobsController < Admin::ApplicationController end @builds = @builds.page(params[:page]).per(30) end + # rubocop: enable CodeReuse/ActiveRecord def cancel_all Ci::Build.running_or_pending.each(&:cancel) diff --git a/app/controllers/admin/keys_controller.rb b/app/controllers/admin/keys_controller.rb index 0b76193a90e..0400a3b2f3b 100644 --- a/app/controllers/admin/keys_controller.rb +++ b/app/controllers/admin/keys_controller.rb @@ -24,9 +24,11 @@ class Admin::KeysController < Admin::ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:user_id]) end + # rubocop: enable CodeReuse/ActiveRecord def key_params params.require(:user_id, :id) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 3afe66c3566..5cb08c9787b 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -19,6 +19,7 @@ class Admin::ProjectsController < Admin::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def show if @group @group_members = present_members( @@ -30,7 +31,9 @@ class Admin::ProjectsController < Admin::ApplicationController @requesters = present_members( AccessRequestsFinder.new(@project).execute(current_user)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def transfer namespace = Namespace.find_by(id: params[:new_namespace_id]) ::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace) @@ -38,6 +41,7 @@ class Admin::ProjectsController < Admin::ApplicationController @project.reload redirect_to admin_project_path(@project) end + # rubocop: enable CodeReuse/ActiveRecord def repository_check RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id) diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb index 6c76c55a9d4..090149fc1e2 100644 --- a/app/controllers/admin/runners_controller.rb +++ b/app/controllers/admin/runners_controller.rb @@ -1,6 +1,7 @@ class Admin::RunnersController < Admin::ApplicationController before_action :runner, except: :index + # rubocop: disable CodeReuse/ActiveRecord def index sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc } @runners = Ci::Runner.order(sort) @@ -8,6 +9,7 @@ class Admin::RunnersController < Admin::ApplicationController @runners = @runners.page(params[:page]).per(30) @active_runners_cnt = Ci::Runner.online.count end + # rubocop: enable CodeReuse/ActiveRecord def show assign_builds_and_projects @@ -57,6 +59,7 @@ class Admin::RunnersController < Admin::ApplicationController params.require(:runner).permit(Ci::Runner::FORM_EDITABLE) end + # rubocop: disable CodeReuse/ActiveRecord def assign_builds_and_projects @builds = runner.builds.order('id DESC').first(30) @projects = @@ -69,4 +72,5 @@ class Admin::RunnersController < Admin::ApplicationController @projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any? @projects = @projects.page(params[:page]).per(30) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/services_controller.rb b/app/controllers/admin/services_controller.rb index 91a36af34f3..c455930c044 100644 --- a/app/controllers/admin/services_controller.rb +++ b/app/controllers/admin/services_controller.rb @@ -30,16 +30,20 @@ class Admin::ServicesController < Admin::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def services_templates Service.available_services_names.map do |service_name| service_template = "#{service_name}_service".camelize.constantize service_template.where(template: true).first_or_create end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def service @service ||= Service.where(id: params[:id], template: true).first end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430') diff --git a/app/controllers/admin/spam_logs_controller.rb b/app/controllers/admin/spam_logs_controller.rb index d52d67a67a5..8df35d25303 100644 --- a/app/controllers/admin/spam_logs_controller.rb +++ b/app/controllers/admin/spam_logs_controller.rb @@ -1,7 +1,9 @@ class Admin::SpamLogsController < Admin::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @spam_logs = SpamLog.order(id: :desc).page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord def destroy spam_log = SpamLog.find(params[:id]) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index a51a8c3ed4a..85bdc85c55b 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -174,9 +174,11 @@ class Admin::UsersController < Admin::ApplicationController user == current_user end + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def redirect_back_or_admin_user(options = {}) redirect_back_or_default(default: default_route, options: options) diff --git a/app/controllers/boards/issues_controller.rb b/app/controllers/boards/issues_controller.rb index 7dd19f87ef5..071906f1e91 100644 --- a/app/controllers/boards/issues_controller.rb +++ b/app/controllers/boards/issues_controller.rb @@ -11,6 +11,7 @@ module Boards before_action :authorize_update_issue, only: [:update] skip_before_action :authenticate_user!, only: [:index] + # rubocop: disable CodeReuse/ActiveRecord def index list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params) issues = list_service.execute @@ -25,6 +26,7 @@ module Boards render_issues(issues, list_service.metadata) end + # rubocop: enable CodeReuse/ActiveRecord def create service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params) diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index dfa1da7872c..961f121548b 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -88,6 +88,7 @@ module AuthenticatesWithTwoFactor # Setup in preparation of communication with a U2F (universal 2nd factor) device # Actual communication is performed using a Javascript API + # rubocop: disable CodeReuse/ActiveRecord def setup_u2f_authentication(user) key_handles = user.u2f_registrations.pluck(:key_handle) u2f = U2F::U2F.new(u2f_app_id) @@ -99,4 +100,5 @@ module AuthenticatesWithTwoFactor sign_requests: sign_requests }) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index b26a76d2b62..709c8aaf337 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -99,6 +99,7 @@ module CreatesCommit end # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def merge_request_exists? strong_memoize(:merge_request) do MergeRequestsFinder.new(current_user, project_id: @project.id) @@ -110,6 +111,7 @@ module CreatesCommit target_branch: @start_branch) end end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables def different_project? diff --git a/app/controllers/concerns/enforces_two_factor_authentication.rb b/app/controllers/concerns/enforces_two_factor_authentication.rb index 997af4ab9e9..69e5cbed343 100644 --- a/app/controllers/concerns/enforces_two_factor_authentication.rb +++ b/app/controllers/concerns/enforces_two_factor_authentication.rb @@ -24,6 +24,7 @@ module EnforcesTwoFactorAuthentication current_user.try(:require_two_factor_authentication_from_group?) end + # rubocop: disable CodeReuse/ActiveRecord def two_factor_authentication_reason(global: -> {}, group: -> {}) if two_factor_authentication_required? if Gitlab::CurrentSettings.require_two_factor_authentication? @@ -34,6 +35,7 @@ module EnforcesTwoFactorAuthentication end end end + # rubocop: enable CodeReuse/ActiveRecord def two_factor_grace_period periods = [Gitlab::CurrentSettings.two_factor_grace_period] diff --git a/app/controllers/concerns/group_tree.rb b/app/controllers/concerns/group_tree.rb index 6ec6897e707..c363cad0ffa 100644 --- a/app/controllers/concerns/group_tree.rb +++ b/app/controllers/concerns/group_tree.rb @@ -1,5 +1,6 @@ module GroupTree # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def render_group_tree(groups) groups = groups.sort_by_attribute(@sort = params[:sort]) @@ -23,7 +24,9 @@ module GroupTree end # rubocop:enable Gitlab/ModuleWithInstanceVariables end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def filtered_groups_with_ancestors(groups) filtered_groups = groups.search(params[:filter]).page(params[:page]) @@ -40,4 +43,5 @@ module GroupTree filtered_groups end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb index 7b6e5bcb5f1..e723107bd7f 100644 --- a/app/controllers/concerns/issuable_actions.rb +++ b/app/controllers/concerns/issuable_actions.rb @@ -89,6 +89,7 @@ module IssuableActions render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" } end + # rubocop: disable CodeReuse/ActiveRecord def discussions notes = issuable.discussion_notes .inc_relations_for_view @@ -103,6 +104,7 @@ module IssuableActions render json: discussion_serializer.represent(discussions, context: self) end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index a2c96f5d635..d29154d5c60 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -48,9 +48,11 @@ module IssuableCollections false end + # rubocop: disable CodeReuse/ActiveRecord def issuables_collection finder.execute.preload(preload_for_collection) end + # rubocop: enable CodeReuse/ActiveRecord def redirect_out_of_range(total_pages) return false if total_pages.nil? || total_pages.zero? @@ -81,6 +83,7 @@ module IssuableCollections end # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def filter_params set_sort_order_from_cookie set_default_state @@ -101,6 +104,7 @@ module IssuableCollections @filter_params.permit(finder_type.valid_params) end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables def set_default_state diff --git a/app/controllers/concerns/issues_calendar.rb b/app/controllers/concerns/issues_calendar.rb index 671a204621d..76e1d1ff4e8 100644 --- a/app/controllers/concerns/issues_calendar.rb +++ b/app/controllers/concerns/issues_calendar.rb @@ -2,6 +2,7 @@ module IssuesCalendar extend ActiveSupport::Concern # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def render_issues_calendar(issuables) @issues = issuables .non_archived @@ -20,5 +21,6 @@ module IssuesCalendar end end end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables end diff --git a/app/controllers/concerns/members_presentation.rb b/app/controllers/concerns/members_presentation.rb index 215e0bdf3cb..e146e7574aa 100644 --- a/app/controllers/concerns/members_presentation.rb +++ b/app/controllers/concerns/members_presentation.rb @@ -10,10 +10,12 @@ module MembersPresentation ).fabricate! end + # rubocop: disable CodeReuse/ActiveRecord def preload_associations(members) ActiveRecord::Associations::Preloader.new.preload(members, :user) ActiveRecord::Associations::Preloader.new.preload(members, :source) ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status) ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 409e6d4c4d2..94a352c0bcc 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -57,6 +57,7 @@ module MembershipActions redirect_to members_page_url end + # rubocop: disable CodeReuse/ActiveRecord def leave member = membershipable.members_and_requesters.find_by!(user_id: current_user.id) Members::DestroyService.new(current_user).execute(member) @@ -77,6 +78,7 @@ module MembershipActions format.json { render json: { notice: notice } } end end + # rubocop: enable CodeReuse/ActiveRecord def resend_invite member = membershipable.members.find(params[:id]) diff --git a/app/controllers/concerns/renders_member_access.rb b/app/controllers/concerns/renders_member_access.rb index d640378c24d..c5b77dacb26 100644 --- a/app/controllers/concerns/renders_member_access.rb +++ b/app/controllers/concerns/renders_member_access.rb @@ -13,6 +13,7 @@ module RendersMemberAccess private + # rubocop: disable CodeReuse/ActiveRecord def preload_max_member_access_for_collection(klass, collection) return if !current_user || collection.blank? @@ -20,4 +21,5 @@ module RendersMemberAccess current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index cf04023080a..c5f23e33424 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -20,9 +20,11 @@ module RendersNotes project.team.max_member_access_for_user_ids(user_ids) end + # rubocop: disable CodeReuse/ActiveRecord def preload_noteable_for_regular_notes(notes) ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable) end + # rubocop: enable CodeReuse/ActiveRecord def preload_first_time_contribution_for_authors(noteable, notes) return unless noteable.is_a?(Issuable) && noteable.first_contribution? @@ -30,7 +32,9 @@ module RendersNotes notes.each {|n| n.specialize_for_first_contribution!(noteable)} end + # rubocop: disable CodeReuse/ActiveRecord def preload_author_status(notes) ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status }) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index bb8c245a5b7..56772df21d7 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -89,6 +89,7 @@ module UploadsActions end end + # rubocop: disable CodeReuse/ActiveRecord def build_uploader_from_upload return unless uploader = build_uploader @@ -96,6 +97,7 @@ module UploadsActions upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_paths) upload&.build_uploader end + # rubocop: enable CodeReuse/ActiveRecord def build_uploader_from_params return unless uploader = build_uploader diff --git a/app/controllers/dashboard/projects_controller.rb b/app/controllers/dashboard/projects_controller.rb index ccfcbbdc776..e8f796f17ca 100644 --- a/app/controllers/dashboard/projects_controller.rb +++ b/app/controllers/dashboard/projects_controller.rb @@ -23,6 +23,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def starred @projects = load_projects(params.merge(starred: true)) .includes(:forked_from_project, :tags) @@ -38,6 +39,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -46,6 +48,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController @sort = params[:sort] end + # rubocop: disable CodeReuse/ActiveRecord def load_projects(finder_params) projects = ProjectsFinder .new(params: finder_params, current_user: current_user) @@ -55,6 +58,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController prepare_projects_for_rendering(projects) end + # rubocop: enable CodeReuse/ActiveRecord def load_events projects = load_projects(params.merge(non_public: true)) diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index bd7111e28bc..231a23427f7 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -73,6 +73,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id) end + # rubocop: disable CodeReuse/ActiveRecord def redirect_out_of_range(todos) total_pages = if todo_params.except(:sort, :page).empty? @@ -91,4 +92,5 @@ class Dashboard::TodosController < Dashboard::ApplicationController out_of_range end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb index c7273606a85..03a2ee07fea 100644 --- a/app/controllers/explore/projects_controller.rb +++ b/app/controllers/explore/projects_controller.rb @@ -34,6 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def starred @projects = load_projects.reorder('star_count DESC') @@ -46,9 +47,11 @@ class Explore::ProjectsController < Explore::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def load_projects projects = ProjectsFinder.new(current_user: current_user, params: params) .execute @@ -58,4 +61,5 @@ class Explore::ProjectsController < Explore::ApplicationController prepare_projects_for_rendering(projects) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 1f48c3417d0..8b46eedae79 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -97,6 +97,7 @@ class GroupsController < Groups::ApplicationController redirect_to root_path, status: 302, alert: "Group '#{@group.name}' was scheduled for deletion." end + # rubocop: disable CodeReuse/ActiveRecord def transfer parent_group = Group.find_by(id: params[:new_parent_group_id]) service = ::Groups::TransferService.new(@group, current_user) @@ -109,9 +110,11 @@ class GroupsController < Groups::ApplicationController render :edit end end + # rubocop: enable CodeReuse/ActiveRecord protected + # rubocop: disable CodeReuse/ActiveRecord def authorize_create_group! allowed = if params[:parent_id].present? parent = Group.find_by(id: params[:parent_id]) @@ -122,6 +125,7 @@ class GroupsController < Groups::ApplicationController render_404 unless allowed end + # rubocop: enable CodeReuse/ActiveRecord def determine_layout if [:new, :create].include?(action_name.to_sym) @@ -156,6 +160,7 @@ class GroupsController < Groups::ApplicationController ] end + # rubocop: disable CodeReuse/ActiveRecord def load_events params[:sort] ||= 'latest_activity_desc' @@ -175,6 +180,7 @@ class GroupsController < Groups::ApplicationController .new(current_user) .execute(@events, atom_request: request.format.atom?) end + # rubocop: enable CodeReuse/ActiveRecord def user_actions if current_user diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 5766c6924cd..14b8c6e4137 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -1,16 +1,20 @@ class Import::BaseController < ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def find_already_added_projects(import_type) current_user.created_projects.where(import_type: import_type).includes(:import_state) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def find_jobs(import_type) current_user.created_projects .includes(:import_state) .where(import_type: import_type) .to_json(only: [:id], methods: [:import_status]) end + # rubocop: enable CodeReuse/ActiveRecord def find_or_create_namespace(names, owner) names = params[:target_namespace].presence || names diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index fa31933e778..f885e04b198 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -16,6 +16,7 @@ class Import::BitbucketController < Import::BaseController redirect_to status_import_bitbucket_url end + # rubocop: disable CodeReuse/ActiveRecord def status bitbucket_client = Bitbucket::Client.new(credentials) repos = bitbucket_client.repos @@ -27,6 +28,7 @@ class Import::BitbucketController < Import::BaseController @repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.full_name) } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('bitbucket') diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index 798daeca6c9..fdd1078cdf7 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -52,6 +52,7 @@ class Import::BitbucketServerController < Import::BaseController redirect_to status_import_bitbucket_server_path end + # rubocop: disable CodeReuse/ActiveRecord def status repos = bitbucket_client.repos @@ -66,6 +67,7 @@ class Import::BitbucketServerController < Import::BaseController clear_session_data redirect_to new_import_bitbucket_server_path end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('bitbucket_server') diff --git a/app/controllers/import/fogbugz_controller.rb b/app/controllers/import/fogbugz_controller.rb index 2d665e05ac3..df96d181153 100644 --- a/app/controllers/import/fogbugz_controller.rb +++ b/app/controllers/import/fogbugz_controller.rb @@ -39,6 +39,7 @@ class Import::FogbugzController < Import::BaseController redirect_to status_import_fogbugz_path end + # rubocop: disable CodeReuse/ActiveRecord def status unless client.valid? return redirect_to new_import_fogbugz_path @@ -51,6 +52,7 @@ class Import::FogbugzController < Import::BaseController @repos.reject! { |repo| already_added_projects_names.include? repo.name } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('fogbugz') diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index c9870332c0f..f8b43b4fde5 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -22,6 +22,7 @@ class Import::GithubController < Import::BaseController redirect_to status_import_url end + # rubocop: disable CodeReuse/ActiveRecord def status @repos = client.repos @already_added_projects = find_already_added_projects(provider) @@ -29,6 +30,7 @@ class Import::GithubController < Import::BaseController @repos.reject! { |repo| already_added_projects_names.include? repo.full_name } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs(provider) @@ -104,9 +106,11 @@ class Import::GithubController < Import::BaseController :github end + # rubocop: disable CodeReuse/ActiveRecord def logged_in_with_provider? current_user.identities.exists?(provider: provider) end + # rubocop: enable CodeReuse/ActiveRecord def provider_auth if session[access_token_key].blank? diff --git a/app/controllers/import/gitlab_controller.rb b/app/controllers/import/gitlab_controller.rb index 53f70446d95..bdc402b0a77 100644 --- a/app/controllers/import/gitlab_controller.rb +++ b/app/controllers/import/gitlab_controller.rb @@ -12,6 +12,7 @@ class Import::GitlabController < Import::BaseController redirect_to status_import_gitlab_url end + # rubocop: disable CodeReuse/ActiveRecord def status @repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS) @@ -20,6 +21,7 @@ class Import::GitlabController < Import::BaseController @repos = @repos.to_a.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('gitlab') diff --git a/app/controllers/import/google_code_controller.rb b/app/controllers/import/google_code_controller.rb index 3bce27e810a..e9387d0ad14 100644 --- a/app/controllers/import/google_code_controller.rb +++ b/app/controllers/import/google_code_controller.rb @@ -65,6 +65,7 @@ class Import::GoogleCodeController < Import::BaseController redirect_to status_import_google_code_path end + # rubocop: disable CodeReuse/ActiveRecord def status unless client.valid? return redirect_to new_import_google_code_path @@ -78,6 +79,7 @@ class Import::GoogleCodeController < Import::BaseController @repos.reject! { |repo| already_added_projects_names.include? repo.name } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('google_code') diff --git a/app/controllers/import/manifest_controller.rb b/app/controllers/import/manifest_controller.rb index e5a719fa0df..4ed9dca2475 100644 --- a/app/controllers/import/manifest_controller.rb +++ b/app/controllers/import/manifest_controller.rb @@ -6,6 +6,7 @@ class Import::ManifestController < Import::BaseController def new end + # rubocop: disable CodeReuse/ActiveRecord def status @already_added_projects = find_already_added_projects already_added_import_urls = @already_added_projects.pluck(:import_url) @@ -14,6 +15,7 @@ class Import::ManifestController < Import::BaseController already_added_import_urls.include?(repository[:url]) end end + # rubocop: enable CodeReuse/ActiveRecord def upload group = Group.find(params[:group_id]) @@ -64,9 +66,11 @@ class Import::ManifestController < Import::BaseController end end + # rubocop: disable CodeReuse/ActiveRecord def group @group ||= Group.find_by(id: session[:manifest_import_group_id]) end + # rubocop: enable CodeReuse/ActiveRecord def repositories @repositories ||= session[:manifest_import_repositories] @@ -76,12 +80,14 @@ class Import::ManifestController < Import::BaseController find_already_added_projects.to_json(only: [:id], methods: [:import_status]) end + # rubocop: disable CodeReuse/ActiveRecord def find_already_added_projects group.all_projects .where(import_type: 'manifest') .where(creator_id: current_user) .includes(:import_state) end + # rubocop: enable CodeReuse/ActiveRecord def verify_import_enabled render_404 unless manifest_import_enabled? diff --git a/app/controllers/instance_statistics/conversational_development_index_controller.rb b/app/controllers/instance_statistics/conversational_development_index_controller.rb index d6d2191849f..306c16d559c 100644 --- a/app/controllers/instance_statistics/conversational_development_index_controller.rb +++ b/app/controllers/instance_statistics/conversational_development_index_controller.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index 331583c49e6..a1bcf206b65 100644 --- a/app/controllers/passwords_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -5,6 +5,7 @@ class PasswordsController < Devise::PasswordsController before_action :check_password_authentication_available, only: [:create] before_action :throttle_reset, only: [:create] + # rubocop: disable CodeReuse/ActiveRecord def edit super reset_password_token = Devise.token_generator.digest( @@ -24,6 +25,7 @@ class PasswordsController < Devise::PasswordsController end end end + # rubocop: enable CodeReuse/ActiveRecord def update super do |resource| diff --git a/app/controllers/profiles/accounts_controller.rb b/app/controllers/profiles/accounts_controller.rb index 7d1aa8d1ce0..fd9cb9fca3e 100644 --- a/app/controllers/profiles/accounts_controller.rb +++ b/app/controllers/profiles/accounts_controller.rb @@ -5,6 +5,7 @@ class Profiles::AccountsController < Profiles::ApplicationController @user = current_user end + # rubocop: disable CodeReuse/ActiveRecord def unlink provider = params[:provider] identity = current_user.identities.find_by(provider: provider) @@ -19,4 +20,5 @@ class Profiles::AccountsController < Profiles::ApplicationController redirect_to profile_account_path end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/profiles/notifications_controller.rb b/app/controllers/profiles/notifications_controller.rb index 8a38ba65d4c..00bd2040b9a 100644 --- a/app/controllers/profiles/notifications_controller.rb +++ b/app/controllers/profiles/notifications_controller.rb @@ -1,10 +1,12 @@ class Profiles::NotificationsController < Profiles::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def show @user = current_user @group_notifications = current_user.notification_settings.for_groups.order(:id) @project_notifications = current_user.notification_settings.for_projects.order(:id) @global_notification_setting = current_user.global_notification_setting end + # rubocop: enable CodeReuse/ActiveRecord def update result = Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute diff --git a/app/controllers/profiles/personal_access_tokens_controller.rb b/app/controllers/profiles/personal_access_tokens_controller.rb index 346eab4ba19..b357741e3fb 100644 --- a/app/controllers/profiles/personal_access_tokens_controller.rb +++ b/app/controllers/profiles/personal_access_tokens_controller.rb @@ -38,6 +38,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController params.require(:personal_access_token).permit(:name, :expires_at, scopes: []) end + # rubocop: disable CodeReuse/ActiveRecord def set_index_vars @scopes = Gitlab::Auth.available_scopes(current_user) @@ -46,4 +47,5 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController @new_personal_access_token = PersonalAccessToken.redis_getdel(current_user.id) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 5671663f81e..94e6efca487 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -44,11 +44,13 @@ class ProfilesController < Profiles::ApplicationController redirect_to profile_personal_access_tokens_path end + # rubocop: disable CodeReuse/ActiveRecord def audit_log @events = AuditEvent.where(entity_type: "User", entity_id: current_user.id) .order("created_at DESC") .page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord def update_username result = Users::UpdateService.new(current_user, user: @user, username: username_param).execute diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index 6484a713f8e..3e8ffa485dd 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -82,16 +82,20 @@ class Projects::ArtifactsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def build_from_id project.builds.find_by(id: params[:job_id]) if params[:job_id] end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def build_from_ref return unless @ref_name builds = project.latest_successful_builds_for(@ref_name) builds.find_by(name: params[:job]) end + # rubocop: enable CodeReuse/ActiveRecord def artifacts_file @artifacts_file ||= build.artifacts_file diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 56dafa31332..bfe4e7f934f 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -177,6 +177,7 @@ class Projects::BlobController < Projects::ApplicationController render_404 end + # 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]) if from_merge_request && @branch_name == @ref @@ -186,6 +187,7 @@ class Projects::BlobController < Projects::ApplicationController project_blob_path(@project, File.join(@branch_name, @path)) end end + # rubocop: enable CodeReuse/ActiveRecord def editor_variables @branch_name = params[:branch_name] diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index d1dc9fe9600..d14795e787b 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -48,6 +48,7 @@ class Projects::BranchesController < Projects::ApplicationController @branches = @repository.recent_branches end + # rubocop: disable CodeReuse/ActiveRecord def create branch_name = sanitize(strip_tags(params[:branch_name])) branch_name = Addressable::URI.unescape(branch_name) @@ -88,6 +89,7 @@ class Projects::BranchesController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def destroy @branch_name = Addressable::URI.unescape(params[:id]) diff --git a/app/controllers/projects/build_artifacts_controller.rb b/app/controllers/projects/build_artifacts_controller.rb index b45e5d7ff43..9e99a84fac7 100644 --- a/app/controllers/projects/build_artifacts_controller.rb +++ b/app/controllers/projects/build_artifacts_controller.rb @@ -42,14 +42,18 @@ class Projects::BuildArtifactsController < Projects::ApplicationController @job ||= job_from_id || job_from_ref end + # rubocop: disable CodeReuse/ActiveRecord def job_from_id project.builds.find_by(id: params[:build_id]) if params[:build_id] end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def job_from_ref return unless @ref_name jobs = project.latest_successful_builds_for(@ref_name) jobs.find_by(name: params[:job]) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/clusters/applications_controller.rb b/app/controllers/projects/clusters/applications_controller.rb index a5c82caa897..8c9df51981a 100644 --- a/app/controllers/projects/clusters/applications_controller.rb +++ b/app/controllers/projects/clusters/applications_controller.rb @@ -4,6 +4,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll before_action :authorize_read_cluster! before_action :authorize_create_cluster!, only: [:create] + # rubocop: disable CodeReuse/ActiveRecord def create application = @application_class.find_or_initialize_by(cluster: @cluster) @@ -23,6 +24,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll rescue StandardError head :bad_request end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 53637780a07..81f375875b2 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -38,6 +38,7 @@ class Projects::CommitController < Projects::ApplicationController render_diff_for_path(@commit.diffs(diff_options)) end + # rubocop: disable CodeReuse/ActiveRecord def pipelines @pipelines = @commit.pipelines.order(id: :desc) @pipelines = @pipelines.where(ref: params[:ref]) if params[:ref] @@ -58,6 +59,7 @@ class Projects::CommitController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def merge_requests @merge_requests = @commit.merge_requests.map do |mr| @@ -144,6 +146,7 @@ class Projects::CommitController < Projects::ApplicationController @environment = EnvironmentsFinder.new(@project, current_user, commit: @commit).execute.last end + # rubocop: disable CodeReuse/ActiveRecord def define_note_vars @noteable = @commit @note = @project.build_commit_note(commit) @@ -176,6 +179,7 @@ class Projects::CommitController < Projects::ApplicationController @notes = (@grouped_diff_discussions.values.flatten + @discussions).flat_map(&:notes) @notes = prepare_notes_for_rendering(@notes, @commit) end + # rubocop: enable CodeReuse/ActiveRecord def assign_change_commit_vars @start_branch = params[:start_branch] diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 5546bef850b..cd9c9aa30f1 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -15,6 +15,7 @@ class Projects::CommitsController < Projects::ApplicationController redirect_to project_commits_path(@project, @project.default_branch) end + # rubocop: disable CodeReuse/ActiveRecord def show @merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened .find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref) @@ -32,6 +33,7 @@ class Projects::CommitsController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def signatures respond_to do |format| diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index a1e12821caf..cca77903250 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -96,8 +96,10 @@ class Projects::CompareController < Projects::ApplicationController @diff_notes_disabled = compare.present? end + # rubocop: disable CodeReuse/ActiveRecord def merge_request @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened .find_by(source_project: @project, source_branch: head_ref, target_branch: start_ref) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/deploy_keys_controller.rb b/app/controllers/projects/deploy_keys_controller.rb index 28fea322334..2555139cd2c 100644 --- a/app/controllers/projects/deploy_keys_controller.rb +++ b/app/controllers/projects/deploy_keys_controller.rb @@ -52,6 +52,7 @@ class Projects::DeployKeysController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def disable deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id]) return render_404 unless deploy_key_project @@ -63,6 +64,7 @@ class Projects::DeployKeysController < Projects::ApplicationController format.json { head :ok } end end + # rubocop: enable CodeReuse/ActiveRecord protected diff --git a/app/controllers/projects/deployments_controller.rb b/app/controllers/projects/deployments_controller.rb index b68cdc39cb8..5a2da7274d1 100644 --- a/app/controllers/projects/deployments_controller.rb +++ b/app/controllers/projects/deployments_controller.rb @@ -2,6 +2,7 @@ class Projects::DeploymentsController < Projects::ApplicationController before_action :authorize_read_environment! before_action :authorize_read_deployment! + # rubocop: disable CodeReuse/ActiveRecord def index deployments = environment.deployments.reorder(created_at: :desc) deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time @@ -9,6 +10,7 @@ class Projects::DeploymentsController < Projects::ApplicationController render json: { deployments: DeploymentSerializer.new(project: project) .represent_concise(deployments) } end + # rubocop: enable CodeReuse/ActiveRecord def metrics return render_404 unless deployment.has_metrics? @@ -41,9 +43,11 @@ class Projects::DeploymentsController < Projects::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def deployment @deployment ||= environment.deployments.find_by(iid: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def environment @environment ||= project.environments.find(params[:environment_id]) diff --git a/app/controllers/projects/discussions_controller.rb b/app/controllers/projects/discussions_controller.rb index 78b9d53a780..efdddb24290 100644 --- a/app/controllers/projects/discussions_controller.rb +++ b/app/controllers/projects/discussions_controller.rb @@ -50,9 +50,11 @@ class Projects::DiscussionsController < Projects::ApplicationController } end + # rubocop: disable CodeReuse/ActiveRecord def merge_request @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id]) end + # rubocop: enable CodeReuse/ActiveRecord def discussion @discussion ||= @merge_request.find_discussion(params[:id]) || render_404 diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 68353e6a210..be22950286e 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -31,6 +31,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def folder folder_environments = project.environments.where(environment_type: params[:id]) @environments = folder_environments.with_state(params[:scope] || :available) @@ -51,10 +52,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def show @deployments = environment.deployments.order(id: :desc).page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord def new @environment = project.environments.new diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb index f43bba18d81..b709edc8f10 100644 --- a/app/controllers/projects/forks_controller.rb +++ b/app/controllers/projects/forks_controller.rb @@ -7,6 +7,7 @@ class Projects::ForksController < Projects::ApplicationController before_action :authorize_download_code! before_action :authenticate_user!, only: [:new, :create] + # rubocop: disable CodeReuse/ActiveRecord def index base_query = project.forks.includes(:creator) @@ -27,12 +28,14 @@ class Projects::ForksController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def new @namespaces = current_user.manageable_namespaces @namespaces.delete(@project.namespace) end + # rubocop: disable CodeReuse/ActiveRecord def create namespace = Namespace.find(params[:namespace_key]) @@ -55,6 +58,7 @@ class Projects::ForksController < Projects::ApplicationController render :error end end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335') diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index c3ac8e107fb..632e498e4ba 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -161,6 +161,7 @@ class Projects::IssuesController < Projects::ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def issue return @issue if defined?(@issue) @@ -172,6 +173,7 @@ class Projects::IssuesController < Projects::ApplicationController @issue end + # rubocop: enable CodeReuse/ActiveRecord alias_method :subscribable_resource, :issue alias_method :issuable, :issue alias_method :awardable, :issue diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb index e69faae754a..62b74e84c2c 100644 --- a/app/controllers/projects/jobs_controller.rb +++ b/app/controllers/projects/jobs_controller.rb @@ -11,6 +11,7 @@ class Projects::JobsController < Projects::ApplicationController layout 'project' + # rubocop: disable CodeReuse/ActiveRecord def index @scope = params[:scope] @all_builds = project.builds.relevant @@ -33,6 +34,7 @@ class Projects::JobsController < Projects::ApplicationController ]) @builds = @builds.page(params[:page]).per(30).without_count end + # rubocop: enable CodeReuse/ActiveRecord def cancel_all return access_denied! unless can?(current_user, :update_build, project) @@ -44,6 +46,7 @@ class Projects::JobsController < Projects::ApplicationController redirect_to project_jobs_path(project) end + # rubocop: disable CodeReuse/ActiveRecord def show @pipeline = @build.pipeline @builds = @pipeline.builds @@ -61,6 +64,7 @@ class Projects::JobsController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def trace build.trace.read do |stream| diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index 69332ee2a0e..1fd4f0721a7 100644 --- a/app/controllers/projects/labels_controller.rb +++ b/app/controllers/projects/labels_controller.rb @@ -90,6 +90,7 @@ class Projects::LabelsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def set_priorities Label.transaction do available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id) @@ -105,6 +106,7 @@ class Projects::LabelsController < Projects::ApplicationController format.json { render json: { message: 'success' } } end end + # rubocop: enable CodeReuse/ActiveRecord def promote promote_service = Labels::PromoteService.new(@project, @current_user) diff --git a/app/controllers/projects/lfs_api_controller.rb b/app/controllers/projects/lfs_api_controller.rb index a01351ba292..6d6f88c1075 100644 --- a/app/controllers/projects/lfs_api_controller.rb +++ b/app/controllers/projects/lfs_api_controller.rb @@ -41,11 +41,13 @@ class Projects::LfsApiController < Projects::GitHttpClientController params[:operation] == 'upload' end + # rubocop: disable CodeReuse/ActiveRecord def existing_oids @existing_oids ||= begin project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid) end end + # rubocop: enable CodeReuse/ActiveRecord def download_objects! objects.each do |object| diff --git a/app/controllers/projects/lfs_storage_controller.rb b/app/controllers/projects/lfs_storage_controller.rb index dd7e673ec75..930d9a05c50 100644 --- a/app/controllers/projects/lfs_storage_controller.rb +++ b/app/controllers/projects/lfs_storage_controller.rb @@ -56,6 +56,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController params[:size].to_i end + # rubocop: disable CodeReuse/ActiveRecord def store_file!(oid, size) object = LfsObject.find_by(oid: oid, size: size) unless object&.file&.exists? @@ -66,6 +67,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController link_to_project!(object) end + # rubocop: enable CodeReuse/ActiveRecord def create_file!(oid, size) uploaded_file = UploadedFile.from_params( @@ -75,9 +77,11 @@ class Projects::LfsStorageController < Projects::GitHttpClientController LfsObject.create!(oid: oid, size: size, file: uploaded_file) end + # rubocop: disable CodeReuse/ActiveRecord def link_to_project!(object) if object && !object.projects.exists?(storage_project.id) object.lfs_objects_projects.create!(project: storage_project) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/merge_requests/application_controller.rb b/app/controllers/projects/merge_requests/application_controller.rb index fead81dd472..aa2008722ec 100644 --- a/app/controllers/projects/merge_requests/application_controller.rb +++ b/app/controllers/projects/merge_requests/application_controller.rb @@ -5,9 +5,11 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont private + # rubocop: disable CodeReuse/ActiveRecord def merge_request @issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def merge_request_params params.require(:merge_request).permit(merge_request_params_attributes) diff --git a/app/controllers/projects/merge_requests/creations_controller.rb b/app/controllers/projects/merge_requests/creations_controller.rb index 03d0290ac1d..2ccb3896857 100644 --- a/app/controllers/projects/merge_requests/creations_controller.rb +++ b/app/controllers/projects/merge_requests/creations_controller.rb @@ -109,6 +109,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap set_pipeline_variables end + # rubocop: disable CodeReuse/ActiveRecord def selected_target_project if @project.id.to_s == params[:target_project_id] || !@project.forked? @project @@ -119,6 +120,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap @project.forked_from_project end end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42384') diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 34de554212f..666e65b6c5e 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -34,13 +34,16 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @diffs = @compare.diffs(diff_options) end + # rubocop: disable CodeReuse/ActiveRecord def commit return nil unless commit_id = params[:commit_id].presence return nil unless @merge_request.all_commits.exists?(sha: commit_id) @commit ||= @project.commit(commit_id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def find_merge_request_diff_compare @merge_request_diff = if diff_id = params[:diff_id].presence @@ -68,6 +71,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @merge_request_diff end end + # rubocop: enable CodeReuse/ActiveRecord def additional_attributes { diff --git a/app/controllers/projects/milestones_controller.rb b/app/controllers/projects/milestones_controller.rb index b9b3dcd5a85..e2c05171cd6 100644 --- a/app/controllers/projects/milestones_controller.rb +++ b/app/controllers/projects/milestones_controller.rb @@ -118,9 +118,11 @@ class Projects::MilestonesController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def milestone @milestone ||= @project.milestones.find_by!(iid: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def authorize_admin_milestone! return render_404 unless can?(current_user, :admin_milestone, @project) diff --git a/app/controllers/projects/pages_controller.rb b/app/controllers/projects/pages_controller.rb index ff49911d892..e1eba4f8327 100644 --- a/app/controllers/projects/pages_controller.rb +++ b/app/controllers/projects/pages_controller.rb @@ -5,9 +5,11 @@ class Projects::PagesController < Projects::ApplicationController before_action :authorize_read_pages!, only: [:show] before_action :authorize_update_pages!, except: [:show] + # rubocop: disable CodeReuse/ActiveRecord def show @domains = @project.pages_domains.order(:domain) end + # rubocop: enable CodeReuse/ActiveRecord def destroy project.remove_pages diff --git a/app/controllers/projects/pages_domains_controller.rb b/app/controllers/projects/pages_domains_controller.rb index 4856be61e88..c29b3c953a6 100644 --- a/app/controllers/projects/pages_domains_controller.rb +++ b/app/controllers/projects/pages_domains_controller.rb @@ -70,7 +70,9 @@ class Projects::PagesDomainsController < Projects::ApplicationController params.require(:pages_domain).permit(:key, :certificate) end + # rubocop: disable CodeReuse/ActiveRecord def domain @domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/pipeline_schedules_controller.rb b/app/controllers/projects/pipeline_schedules_controller.rb index aeda7b3edf5..d8adeffd0b2 100644 --- a/app/controllers/projects/pipeline_schedules_controller.rb +++ b/app/controllers/projects/pipeline_schedules_controller.rb @@ -8,12 +8,14 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play] before_action :authorize_admin_pipeline_schedule!, only: [:destroy] + # rubocop: disable CodeReuse/ActiveRecord def index @scope = params[:scope] @all_schedules = PipelineSchedulesFinder.new(@project).execute @schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope]) .includes(:last_pipeline) end + # rubocop: enable CodeReuse/ActiveRecord def new @schedule = project.pipeline_schedules.new diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index b5db646bf57..2cc721dfeec 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -159,6 +159,7 @@ class Projects::PipelinesController < Projects::ApplicationController params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value]) end + # rubocop: disable CodeReuse/ActiveRecord def pipeline @pipeline ||= project .pipelines @@ -166,6 +167,7 @@ class Projects::PipelinesController < Projects::ApplicationController .find_by!(id: params[:id]) .present(current_user: current_user) end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting # Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343 diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index cfa5e72af64..08d5e377941 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -6,6 +6,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController # Authorize before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access] + # rubocop: disable CodeReuse/ActiveRecord def index @sort = params[:sort].presence || sort_value_name @group_links = @project.project_group_links @@ -25,6 +26,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController @requesters = present_members(AccessRequestsFinder.new(@project).execute(current_user)) @project_member = @project.project_members.new end + # rubocop: enable CodeReuse/ActiveRecord def import @projects = current_user.authorized_projects.order_id_desc diff --git a/app/controllers/projects/releases_controller.rb b/app/controllers/projects/releases_controller.rb index 19e09b3af6f..caf400ecd92 100644 --- a/app/controllers/projects/releases_controller.rb +++ b/app/controllers/projects/releases_controller.rb @@ -28,9 +28,11 @@ class Projects::ReleasesController < Projects::ApplicationController @tag ||= @repository.find_tag(params[:tag_id]) end + # rubocop: disable CodeReuse/ActiveRecord def release @release ||= @project.releases.find_or_initialize_by(tag: @tag.name) end + # rubocop: enable CodeReuse/ActiveRecord def release_params params.require(:release).permit(:description) diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb index 4697af4f26a..ccd481b4dbd 100644 --- a/app/controllers/projects/settings/repository_controller.rb +++ b/app/controllers/projects/settings/repository_controller.rb @@ -31,6 +31,7 @@ module Projects render 'show' end + # rubocop: disable CodeReuse/ActiveRecord def define_protected_refs @protected_branches = @project.protected_branches.order(:name).page(params[:page]) @protected_tags = @project.protected_tags.order(:name).page(params[:page]) @@ -42,6 +43,7 @@ module Projects load_gon_index end + # rubocop: enable CodeReuse/ActiveRecord def remote_mirror @remote_mirror = project.remote_mirrors.first_or_initialize diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb index 7f2c3ca38ad..74bba97987f 100644 --- a/app/controllers/projects/tags_controller.rb +++ b/app/controllers/projects/tags_controller.rb @@ -7,6 +7,7 @@ class Projects::TagsController < Projects::ApplicationController before_action :authorize_push_code!, only: [:new, :create] before_action :authorize_admin_project!, only: [:destroy] + # rubocop: disable CodeReuse/ActiveRecord def index params[:sort] = params[:sort].presence || sort_value_recently_updated @@ -23,7 +24,9 @@ class Projects::TagsController < Projects::ApplicationController format.atom { render layout: 'xml.atom' } end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def show @tag = @repository.find_tag(params[:id]) @@ -32,6 +35,7 @@ class Projects::TagsController < Projects::ApplicationController @release = @project.releases.find_or_initialize_by(tag: @tag.name) @commit = @repository.commit(@tag.dereferenced_target) end + # rubocop: enable CodeReuse/ActiveRecord def create result = Tags::CreateService.new(@project, current_user) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 98076791ab9..e2f9d501c4b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -25,12 +25,14 @@ class ProjectsController < Projects::ApplicationController redirect_to(current_user ? root_path : explore_root_path) end + # rubocop: disable CodeReuse/ActiveRecord def new namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id] return access_denied! if namespace && !can?(current_user, :create_projects, namespace) @project = Project.new(namespace_id: namespace&.id) end + # rubocop: enable CodeReuse/ActiveRecord def edit @badge_api_endpoint = expose_url(api_v4_projects_badges_path(id: @project.id)) @@ -75,6 +77,7 @@ class ProjectsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def transfer return access_denied! unless can?(current_user, :change_namespace, @project) @@ -85,6 +88,7 @@ class ProjectsController < Projects::ApplicationController flash[:alert] = @project.errors[:new_namespace].first end end + # rubocop: enable CodeReuse/ActiveRecord def remove_fork return access_denied! unless can?(current_user, :remove_fork_project, @project) @@ -231,6 +235,7 @@ class ProjectsController < Projects::ApplicationController } end + # rubocop: disable CodeReuse/ActiveRecord def refs find_refs = params['find'] @@ -265,6 +270,7 @@ class ProjectsController < Projects::ApplicationController render json: options.to_json end + # rubocop: enable CodeReuse/ActiveRecord # Render project landing depending of which features are available # So if page is not availble in the list it renders the next page @@ -303,6 +309,7 @@ class ProjectsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def load_events projects = Project.where(id: @project.id) @@ -312,6 +319,7 @@ class ProjectsController < Projects::ApplicationController Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?) end + # rubocop: enable CodeReuse/ActiveRecord def project_params params.require(:project) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 983f888b8ec..a928758f325 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -31,6 +31,7 @@ class SearchController < ApplicationController check_single_commit_result end + # rubocop: disable CodeReuse/ActiveRecord def autocomplete term = params[:term] @@ -43,6 +44,7 @@ class SearchController < ApplicationController render json: search_autocomplete_opts(term).to_json end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ab8e2e35b98..9f2e66dea90 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -107,6 +107,7 @@ class SessionsController < Devise::SessionsController # Handle an "initial setup" state, where there's only one user, it's an admin, # and they require a password change. + # rubocop: disable CodeReuse/ActiveRecord def check_initial_setup return unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one @@ -121,6 +122,7 @@ class SessionsController < Devise::SessionsController redirect_to edit_user_password_path(reset_password_token: @token), notice: "Please create a password for your new account." end + # rubocop: enable CodeReuse/ActiveRecord def user_params params.require(:user).permit(:login, :password, :remember_me, :otp_attempt, :device_response) diff --git a/app/controllers/snippets/notes_controller.rb b/app/controllers/snippets/notes_controller.rb index 217da89a1fd..e992afc0026 100644 --- a/app/controllers/snippets/notes_controller.rb +++ b/app/controllers/snippets/notes_controller.rb @@ -17,9 +17,11 @@ class Snippets::NotesController < ApplicationController nil end + # rubocop: disable CodeReuse/ActiveRecord def snippet PersonalSnippet.find_by(id: params[:snippet_id]) end + # rubocop: enable CodeReuse/ActiveRecord alias_method :noteable, :snippet def note_params diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index dcf18c1f751..19d865900e9 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -24,6 +24,7 @@ class SnippetsController < ApplicationController layout 'snippets' respond_to :html + # rubocop: disable CodeReuse/ActiveRecord def index if params[:username].present? @user = User.find_by(username: params[:username]) @@ -38,6 +39,7 @@ class SnippetsController < ApplicationController redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path) end end + # rubocop: enable CodeReuse/ActiveRecord def new @snippet = PersonalSnippet.new @@ -94,9 +96,11 @@ class SnippetsController < ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def snippet @snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord alias_method :awardable, :snippet alias_method :spammable, :snippet diff --git a/app/controllers/user_callouts_controller.rb b/app/controllers/user_callouts_controller.rb index 18cde4a7b1a..b8d2deba93b 100644 --- a/app/controllers/user_callouts_controller.rb +++ b/app/controllers/user_callouts_controller.rb @@ -13,9 +13,11 @@ class UserCalloutsController < ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def ensure_callout current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name]) end + # rubocop: enable CodeReuse/ActiveRecord def feature_name params.require(:feature_name) diff --git a/app/finders/admin/projects_finder.rb b/app/finders/admin/projects_finder.rb index 543bf1a1415..6b805c432f6 100644 --- a/app/finders/admin/projects_finder.rb +++ b/app/finders/admin/projects_finder.rb @@ -6,6 +6,7 @@ class Admin::ProjectsFinder @current_user = current_user end + # rubocop: disable CodeReuse/ActiveRecord def execute items = Project.without_deleted.with_statistics.with_route items = by_namespace_id(items) @@ -19,6 +20,7 @@ class Admin::ProjectsFinder items = items.includes(namespace: [:owner, :route]) sort(items).page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord private @@ -26,9 +28,11 @@ class Admin::ProjectsFinder params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items end + # rubocop: disable CodeReuse/ActiveRecord def by_visibilty_level(items) params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items end + # rubocop: enable CodeReuse/ActiveRecord def by_with_push(items) params[:with_push].present? ? items.with_push : items @@ -38,9 +42,11 @@ class Admin::ProjectsFinder params[:abandoned].present? ? items.abandoned : items end + # rubocop: disable CodeReuse/ActiveRecord def by_last_repository_check_failed(items) params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items end + # rubocop: enable CodeReuse/ActiveRecord def by_archived(items) if params[:archived] == 'only' diff --git a/app/finders/autocomplete/users_finder.rb b/app/finders/autocomplete/users_finder.rb index b2557469079..e2283f3266e 100644 --- a/app/finders/autocomplete/users_finder.rb +++ b/app/finders/autocomplete/users_finder.rb @@ -44,6 +44,7 @@ module Autocomplete # Returns the users based on the input parameters, as an Array. # # This method is separate so it is easier to extend in EE. + # rubocop: disable CodeReuse/ActiveRecord def limited_users # When changing the order of these method calls, make sure that # reorder_by_name() is called _before_ optionally_search(), otherwise @@ -61,6 +62,7 @@ module Autocomplete .limit(LIMIT) .to_a end + # rubocop: enable CodeReuse/ActiveRecord def prepend_current_user? filter_by_current_user.present? && current_user @@ -70,6 +72,7 @@ module Autocomplete author_id.present? && current_user end + # rubocop: disable CodeReuse/ActiveRecord def find_users if project project.authorized_users.union_with_user(author_id) @@ -81,5 +84,6 @@ module Autocomplete User.none end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/finders/concerns/custom_attributes_filter.rb b/app/finders/concerns/custom_attributes_filter.rb index 5bbf9ca242d..022a19b0a7f 100644 --- a/app/finders/concerns/custom_attributes_filter.rb +++ b/app/finders/concerns/custom_attributes_filter.rb @@ -1,4 +1,5 @@ module CustomAttributesFilter + # rubocop: disable CodeReuse/ActiveRecord def by_custom_attributes(items) return items unless params[:custom_attributes].is_a?(Hash) return items unless Ability.allowed?(current_user, :read_custom_attribute) @@ -17,4 +18,5 @@ module CustomAttributesFilter scope.where('EXISTS (?)', custom_attributes.where(key: key, value: value)) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/concerns/finder_methods.rb b/app/finders/concerns/finder_methods.rb index 2e905fa5750..ce0ec214b8a 100644 --- a/app/finders/concerns/finder_methods.rb +++ b/app/finders/concerns/finder_methods.rb @@ -1,11 +1,15 @@ module FinderMethods + # rubocop: disable CodeReuse/ActiveRecord def find_by!(*args) raise_not_found_unless_authorized execute.find_by!(*args) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def find_by(*args) if_authorized execute.find_by(*args) end + # rubocop: enable CodeReuse/ActiveRecord def find(*args) raise_not_found_unless_authorized model.find(*args) diff --git a/app/finders/concerns/finder_with_cross_project_access.rb b/app/finders/concerns/finder_with_cross_project_access.rb index 92bf98d7cd2..f70a0b60864 100644 --- a/app/finders/concerns/finder_with_cross_project_access.rb +++ b/app/finders/concerns/finder_with_cross_project_access.rb @@ -14,6 +14,7 @@ module FinderWithCrossProjectAccess end override :execute + # rubocop: disable CodeReuse/ActiveRecord def execute(*args) check = Gitlab::CrossProjectAccess.find_check(self) original = super @@ -27,6 +28,7 @@ module FinderWithCrossProjectAccess original end end + # rubocop: enable CodeReuse/ActiveRecord # We can skip the cross project check for finding indivitual records. # this would be handled by the `can?(:read_*, result)` call in `FinderMethods` diff --git a/app/finders/contributed_projects_finder.rb b/app/finders/contributed_projects_finder.rb index a685719555c..1447def0cdf 100644 --- a/app/finders/contributed_projects_finder.rb +++ b/app/finders/contributed_projects_finder.rb @@ -10,11 +10,13 @@ class ContributedProjectsFinder < UnionFinder # visible by this user. # # Returns an ActiveRecord::Relation. + # rubocop: disable CodeReuse/ActiveRecord def execute(current_user = nil) segments = all_projects(current_user) find_union(segments, Project).includes(:namespace).order_id_desc end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/finders/environments_finder.rb b/app/finders/environments_finder.rb index a59f8c1efa3..95af6214c7d 100644 --- a/app/finders/environments_finder.rb +++ b/app/finders/environments_finder.rb @@ -5,6 +5,7 @@ class EnvironmentsFinder @project, @current_user, @params = project, current_user, params end + # rubocop: disable CodeReuse/ActiveRecord def execute deployments = project.deployments deployments = @@ -42,6 +43,7 @@ class EnvironmentsFinder environments end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/finders/events_finder.rb b/app/finders/events_finder.rb index 8676925a540..a8d4f56a84c 100644 --- a/app/finders/events_finder.rb +++ b/app/finders/events_finder.rb @@ -36,32 +36,42 @@ class EventsFinder private + # rubocop: disable CodeReuse/ActiveRecord def by_current_user_access(events) - events.merge(ProjectsFinder.new(current_user: current_user).execute) + events.merge(ProjectsFinder.new(current_user: current_user).execute) # rubocop: disable CodeReuse/Finder .joins(:project) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_action(events) return events unless Event::ACTIONS[params[:action]] events.where(action: Event::ACTIONS[params[:action]]) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_target_type(events) return events unless Event::TARGET_TYPES[params[:target_type]] events.where(target_type: Event::TARGET_TYPES[params[:target_type]]) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_created_at_before(events) return events unless params[:before] events.where('events.created_at < ?', params[:before].beginning_of_day) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_created_at_after(events) return events unless params[:after] events.where('events.created_at > ?', params[:after].end_of_day) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/fork_projects_finder.rb b/app/finders/fork_projects_finder.rb index 28d1b31868e..8713d43136f 100644 --- a/app/finders/fork_projects_finder.rb +++ b/app/finders/fork_projects_finder.rb @@ -1,6 +1,8 @@ class ForkProjectsFinder < ProjectsFinder + # rubocop: disable CodeReuse/ActiveRecord def initialize(project, params: {}, current_user: nil) project_ids = project.forks.includes(:creator).select(:id) super(params: params, current_user: current_user, project_ids_relation: project_ids) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/group_descendants_finder.rb b/app/finders/group_descendants_finder.rb index 2300b7fd114..15060a99930 100644 --- a/app/finders/group_descendants_finder.rb +++ b/app/finders/group_descendants_finder.rb @@ -61,12 +61,16 @@ class GroupDescendantsFinder end def direct_child_groups + # rubocop: disable CodeReuse/Finder GroupsFinder.new(current_user, parent: parent_group, all_available: true).execute + # rubocop: enable CodeReuse/Finder end + # rubocop: disable CodeReuse/ActiveRecord def all_visible_descendant_groups + # rubocop: disable CodeReuse/Finder groups_table = Group.arel_table visible_to_user = groups_table[:visibility_level] .in(Gitlab::VisibilityLevel.levels_for_user(current_user)) @@ -84,7 +88,9 @@ class GroupDescendantsFinder hierarchy_for_parent .descendants .where(visible_to_user) + # rubocop: enable CodeReuse/Finder end + # rubocop: enable CodeReuse/ActiveRecord def subgroups_matching_filter all_visible_descendant_groups @@ -101,24 +107,29 @@ class GroupDescendantsFinder # # So when searching 'project', on the 'subgroup' page we want to preload # 'nested-group' but not 'subgroup' or 'root' + # rubocop: disable CodeReuse/ActiveRecord def ancestors_of_groups(base_for_ancestors) group_ids = base_for_ancestors.except(:select, :sort).select(:id) Gitlab::GroupHierarchy.new(Group.where(id: group_ids)) .base_and_ancestors(upto: parent_group.id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def ancestors_of_filtered_projects projects_to_load_ancestors_of = projects.where.not(namespace: parent_group) groups_to_load_ancestors_of = Group.where(id: projects_to_load_ancestors_of.select(:namespace_id)) ancestors_of_groups(groups_to_load_ancestors_of) .with_selects_for_list(archived: params[:archived]) end + # rubocop: enable CodeReuse/ActiveRecord def ancestors_of_filtered_subgroups ancestors_of_groups(subgroups) .with_selects_for_list(archived: params[:archived]) end + # rubocop: disable CodeReuse/ActiveRecord def subgroups return Group.none unless Group.supports_nested_groups? @@ -132,22 +143,29 @@ class GroupDescendantsFinder groups.with_selects_for_list(archived: params[:archived]).order_by(sort) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/Finder def direct_child_projects GroupProjectsFinder.new(group: parent_group, current_user: current_user, params: params, options: { only_owned: true }) .execute end + # rubocop: enable CodeReuse/Finder # Finds all projects nested under `parent_group` or any of its descendant # groups + # rubocop: disable CodeReuse/ActiveRecord def projects_matching_filter + # rubocop: disable CodeReuse/Finder projects_nested_in_group = Project.where(namespace_id: hierarchy_for_parent.base_and_descendants.select(:id)) params_with_search = params.merge(search: params[:filter]) ProjectsFinder.new(params: params_with_search, current_user: current_user, project_ids_relation: projects_nested_in_group).execute + # rubocop: enable CodeReuse/Finder end + # rubocop: enable CodeReuse/ActiveRecord def projects projects = if params[:filter] @@ -163,7 +181,9 @@ class GroupDescendantsFinder params.fetch(:sort, 'id_asc') end + # rubocop: disable CodeReuse/ActiveRecord def hierarchy_for_parent @hierarchy ||= Gitlab::GroupHierarchy.new(Group.where(id: parent_group.id)) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/group_finder.rb b/app/finders/group_finder.rb index 24c84d2d1aa..8fde3a00af7 100644 --- a/app/finders/group_finder.rb +++ b/app/finders/group_finder.rb @@ -5,6 +5,7 @@ class GroupFinder @current_user = current_user end + # rubocop: disable CodeReuse/ActiveRecord def execute(*params) group = Group.find_by(*params) @@ -14,4 +15,5 @@ class GroupFinder nil end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/group_members_finder.rb b/app/finders/group_members_finder.rb index 2a656c0d31c..cab1ff8fb98 100644 --- a/app/finders/group_members_finder.rb +++ b/app/finders/group_members_finder.rb @@ -3,6 +3,7 @@ class GroupMembersFinder @group = group end + # rubocop: disable CodeReuse/ActiveRecord def execute(include_descendants: false) group_members = @group.members wheres = [] @@ -29,4 +30,5 @@ class GroupMembersFinder GroupMember.where(wheres.join(' OR ')) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/group_projects_finder.rb b/app/finders/group_projects_finder.rb index b6bdb2b7b0f..52a347fa598 100644 --- a/app/finders/group_projects_finder.rb +++ b/app/finders/group_projects_finder.rb @@ -82,6 +82,7 @@ class GroupProjectsFinder < ProjectsFinder options.fetch(:include_subgroups, false) end + # rubocop: disable CodeReuse/ActiveRecord def owned_projects if include_subgroups? Project.where(namespace_id: group.self_and_descendants.select(:id)) @@ -89,6 +90,7 @@ class GroupProjectsFinder < ProjectsFinder group.projects end end + # rubocop: enable CodeReuse/ActiveRecord def shared_projects group.shared_projects diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb index 0eeba1d2428..436abb332ff 100644 --- a/app/finders/groups_finder.rb +++ b/app/finders/groups_finder.rb @@ -38,6 +38,7 @@ class GroupsFinder < UnionFinder attr_reader :current_user, :params + # rubocop: disable CodeReuse/ActiveRecord def all_groups return [owned_groups] if params[:owned] return [groups_with_min_access_level] if min_access_level? @@ -49,6 +50,7 @@ class GroupsFinder < UnionFinder groups << Group.none if groups.empty? groups end + # rubocop: enable CodeReuse/ActiveRecord def groups_for_ancestors current_user.authorized_groups @@ -58,6 +60,7 @@ class GroupsFinder < UnionFinder current_user.groups end + # rubocop: disable CodeReuse/ActiveRecord def groups_with_min_access_level groups = current_user .groups @@ -67,16 +70,21 @@ class GroupsFinder < UnionFinder .new(groups) .base_and_descendants end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_parent(groups) return groups unless params[:parent] groups.where(parent: params[:parent]) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def owned_groups current_user&.owned_groups || Group.none end + # rubocop: enable CodeReuse/ActiveRecord def include_public_groups? current_user.nil? || all_available? diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 372e2a96c2c..3308fd6d697 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -109,6 +109,7 @@ class IssuableFinder # (even if that query is slower than any of the individual state queries) and # grouping and counting within that query. # + # rubocop: disable CodeReuse/ActiveRecord def count_by_state count_params = params.merge(state: nil, sort: nil) finder = self.class.new(current_user, count_params) @@ -132,6 +133,7 @@ class IssuableFinder counts.with_indifferent_access end + # rubocop: enable CodeReuse/ActiveRecord def group return @group if defined?(@group) @@ -157,6 +159,7 @@ class IssuableFinder @project = project end + # rubocop: disable CodeReuse/ActiveRecord def projects(items = nil) return @projects = project if project? @@ -165,13 +168,14 @@ class IssuableFinder current_user.authorized_projects elsif group finder_options = { include_subgroups: params[:include_subgroups], only_owned: true } - GroupProjectsFinder.new(group: group, current_user: current_user, options: finder_options).execute + GroupProjectsFinder.new(group: group, current_user: current_user, options: finder_options).execute # rubocop: disable CodeReuse/Finder else - ProjectsFinder.new(current_user: current_user).execute + ProjectsFinder.new(current_user: current_user).execute # rubocop: disable CodeReuse/Finder end @projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil) end + # rubocop: enable CodeReuse/ActiveRecord def search params[:search].presence @@ -185,6 +189,7 @@ class IssuableFinder milestones? && params[:milestone_title] == Milestone::None.title end + # rubocop: disable CodeReuse/ActiveRecord def milestones return @milestones if defined?(@milestones) @@ -200,11 +205,12 @@ class IssuableFinder search_params = { title: params[:milestone_title], project_ids: project_id, group_ids: group_id } - MilestonesFinder.new(search_params).execute + MilestonesFinder.new(search_params).execute # rubocop: disable CodeReuse/Finder else Milestone.none end end + # rubocop: enable CodeReuse/ActiveRecord def labels? params[:label_name].present? @@ -214,16 +220,18 @@ class IssuableFinder labels? && params[:label_name].include?(Label::None.title) end + # rubocop: disable CodeReuse/ActiveRecord def labels return @labels if defined?(@labels) @labels = if labels? && !filter_by_no_label? - LabelsFinder.new(current_user, project_ids: projects, title: label_names).execute(skip_authorization: true) + LabelsFinder.new(current_user, project_ids: projects, title: label_names).execute(skip_authorization: true) # rubocop: disable CodeReuse/Finder else Label.none end end + # rubocop: enable CodeReuse/ActiveRecord def assignee_id? params[:assignee_id].present? && params[:assignee_id] != NONE @@ -238,6 +246,7 @@ class IssuableFinder params[:assignee_id] == NONE || params[:assignee_username] == NONE end + # rubocop: disable CodeReuse/ActiveRecord def assignee return @assignee if defined?(@assignee) @@ -250,6 +259,7 @@ class IssuableFinder nil end end + # rubocop: enable CodeReuse/ActiveRecord def author_id? params[:author_id].present? && params[:author_id] != NONE @@ -264,6 +274,7 @@ class IssuableFinder params[:author_id] == NONE || params[:author_username] == NONE end + # rubocop: disable CodeReuse/ActiveRecord def author return @author if defined?(@author) @@ -276,6 +287,7 @@ class IssuableFinder nil end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -283,6 +295,7 @@ class IssuableFinder klass.all end + # rubocop: disable CodeReuse/ActiveRecord def by_scope(items) return items.none if current_user_related? && !current_user @@ -295,6 +308,7 @@ class IssuableFinder items end end + # rubocop: enable CodeReuse/ActiveRecord def by_updated_at(items) items = items.updated_after(params[:updated_after]) if params[:updated_after].present? @@ -303,6 +317,7 @@ class IssuableFinder items end + # rubocop: disable CodeReuse/ActiveRecord def by_state(items) case params[:state].to_s when 'closed' @@ -317,12 +332,14 @@ class IssuableFinder items end end + # rubocop: enable CodeReuse/ActiveRecord def by_group(items) # Selection by group is already covered by `by_project` and `projects` items end + # rubocop: disable CodeReuse/ActiveRecord def by_project(items) items = if project? @@ -335,6 +352,7 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord def use_cte_for_search? return false unless search @@ -343,6 +361,7 @@ class IssuableFinder params[:use_cte_for_search] end + # rubocop: disable CodeReuse/ActiveRecord def by_search(items) return items unless search @@ -355,17 +374,23 @@ class IssuableFinder items.full_search(search) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_iids(items) params[:iids].present? ? items.where(iid: params[:iids]) : items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def sort(items) # Ensure we always have an explicit sort order (instead of inheriting # multiple orders when combining ActiveRecord::Relation objects). params[:sort] ? items.sort_by_attribute(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_assignee(items) if assignee items = items.where(assignee_id: assignee.id) @@ -377,7 +402,9 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_author(items) if author items = items.where(author_id: author.id) @@ -389,6 +416,7 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord def filter_by_upcoming_milestone? params[:milestone_title] == Milestone::Upcoming.name @@ -398,6 +426,7 @@ class IssuableFinder params[:milestone_title] == Milestone::Started.name end + # rubocop: disable CodeReuse/ActiveRecord def by_milestone(items) if milestones? if filter_by_no_milestone? @@ -414,6 +443,7 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord def by_label(items) return items unless labels? diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index 24a6b9349a0..c347ef1ec19 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -29,10 +29,13 @@ class IssuesFinder < IssuableFinder @scalar_params ||= super + [:due_date] end + # rubocop: disable CodeReuse/ActiveRecord def klass Issue.includes(:author) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def with_confidentiality_access_check return Issue.all if user_can_see_all_confidential_issues? return Issue.where('issues.confidential IS NOT TRUE') if user_cannot_see_confidential_issues? @@ -46,6 +49,7 @@ class IssuesFinder < IssuableFinder user_id: current_user.id, project_ids: current_user.authorized_projects(CONFIDENTIAL_ACCESS_LEVEL).select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord private @@ -125,6 +129,7 @@ class IssuesFinder < IssuableFinder current_user.blank? end + # rubocop: disable CodeReuse/ActiveRecord def by_assignee(items) if assignee items.assigned_to(assignee) @@ -136,4 +141,5 @@ class IssuesFinder < IssuableFinder items end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb index 8418577dab2..17c55f8db50 100644 --- a/app/finders/labels_finder.rb +++ b/app/finders/labels_finder.rb @@ -10,6 +10,7 @@ class LabelsFinder < UnionFinder @params = params end + # rubocop: disable CodeReuse/ActiveRecord def execute(skip_authorization: false) @skip_authorization = skip_authorization items = find_union(label_ids, Label) || Label.none @@ -17,11 +18,13 @@ class LabelsFinder < UnionFinder items = by_search(items) sort(items) end + # rubocop: enable CodeReuse/ActiveRecord private attr_reader :current_user, :params, :skip_authorization + # rubocop: disable CodeReuse/ActiveRecord def label_ids label_ids = [] @@ -52,7 +55,9 @@ class LabelsFinder < UnionFinder label_ids end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def sort(items) if params[:sort] items.order_by(params[:sort]) @@ -60,13 +65,16 @@ class LabelsFinder < UnionFinder items.reorder(title: :asc) end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def with_title(items) return items if title.nil? return items.none if title.blank? items.where(title: title) end + # rubocop: enable CodeReuse/ActiveRecord def by_search(labels) return labels unless search? @@ -138,13 +146,14 @@ class LabelsFinder < UnionFinder @project end + # rubocop: disable CodeReuse/ActiveRecord def projects return @projects if defined?(@projects) @projects = if skip_authorization Project.all else - ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute + ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute # rubocop: disable CodeReuse/Finder end @projects = @projects.in_namespace(params[:group_id]) if group? @@ -153,6 +162,7 @@ class LabelsFinder < UnionFinder @projects end + # rubocop: enable CodeReuse/ActiveRecord def authorized_to_read_labels?(label_parent) return true if skip_authorization diff --git a/app/finders/members_finder.rb b/app/finders/members_finder.rb index 4c893ae2de6..58e3606692d 100644 --- a/app/finders/members_finder.rb +++ b/app/finders/members_finder.rb @@ -7,12 +7,13 @@ class MembersFinder @group = project.group end + # rubocop: disable CodeReuse/ActiveRecord def execute(include_descendants: false) project_members = project.project_members project_members = project_members.non_invite unless can?(current_user, :admin_project, project) if group - group_members = GroupMembersFinder.new(group).execute(include_descendants: include_descendants) + group_members = GroupMembersFinder.new(group).execute(include_descendants: include_descendants) # rubocop: disable CodeReuse/Finder group_members = group_members.non_invite union = Gitlab::SQL::Union.new([project_members, group_members], remove_duplicates: false) @@ -24,6 +25,7 @@ class MembersFinder project_members end end + # rubocop: enable CodeReuse/ActiveRecord def can?(*args) Ability.allowed?(*args) diff --git a/app/finders/merge_request_target_project_finder.rb b/app/finders/merge_request_target_project_finder.rb index 188ec447a94..66d4c4018f3 100644 --- a/app/finders/merge_request_target_project_finder.rb +++ b/app/finders/merge_request_target_project_finder.rb @@ -8,6 +8,7 @@ class MergeRequestTargetProjectFinder @source_project = source_project end + # rubocop: disable CodeReuse/ActiveRecord def execute if @source_project.fork_network @source_project.fork_network.projects @@ -18,4 +19,5 @@ class MergeRequestTargetProjectFinder Project.where(id: source_project) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/merge_requests_finder.rb b/app/finders/merge_requests_finder.rb index 40089c082c1..c6403f8f25d 100644 --- a/app/finders/merge_requests_finder.rb +++ b/app/finders/merge_requests_finder.rb @@ -41,19 +41,23 @@ class MergeRequestsFinder < IssuableFinder @source_branch ||= params[:source_branch].presence end + # rubocop: disable CodeReuse/ActiveRecord def by_source_branch(items) return items unless source_branch items.where(source_branch: source_branch) end + # rubocop: enable CodeReuse/ActiveRecord def target_branch @target_branch ||= params[:target_branch].presence end + # rubocop: disable CodeReuse/ActiveRecord def by_target_branch(items) return items unless target_branch items.where(target_branch: target_branch) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/milestones_finder.rb b/app/finders/milestones_finder.rb index f5d2b9f253a..7dc2a5b0b66 100644 --- a/app/finders/milestones_finder.rb +++ b/app/finders/milestones_finder.rb @@ -18,6 +18,7 @@ class MilestonesFinder @params = params end + # rubocop: disable CodeReuse/ActiveRecord def execute return Milestone.none if project_ids.empty? && group_ids.empty? @@ -28,6 +29,7 @@ class MilestonesFinder order(items) end + # rubocop: enable CodeReuse/ActiveRecord private @@ -35,6 +37,7 @@ class MilestonesFinder items.for_projects_and_groups(project_ids, group_ids) end + # rubocop: disable CodeReuse/ActiveRecord def by_title(items) if params[:title] items.where(title: params[:title]) @@ -42,13 +45,16 @@ class MilestonesFinder items end end + # rubocop: enable CodeReuse/ActiveRecord def by_state(items) Milestone.filter_by_state(items, params[:state]) end + # rubocop: disable CodeReuse/ActiveRecord def order(items) order_statement = Gitlab::Database.nulls_last_order('due_date', 'ASC') items.reorder(order_statement).order('title ASC') end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 9b7a35fb3b5..580984329a1 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -65,21 +65,23 @@ class NotesFinder @params[:target_type] end + # rubocop: disable CodeReuse/ActiveRecord def notes_of_any_type types = %w(commit issue merge_request snippet) note_relations = types.map { |t| notes_for_type(t) } note_relations.map! { |notes| search(notes) } - UnionFinder.new.find_union(note_relations, Note.includes(:author)) + UnionFinder.new.find_union(note_relations, Note.includes(:author)) # rubocop: disable CodeReuse/Finder end + # rubocop: enable CodeReuse/ActiveRecord def noteables_for_type(noteable_type) case noteable_type when "issue" - IssuesFinder.new(@current_user, project_id: @project.id).execute + IssuesFinder.new(@current_user, project_id: @project.id).execute # rubocop: disable CodeReuse/Finder when "merge_request" - MergeRequestsFinder.new(@current_user, project_id: @project.id).execute + MergeRequestsFinder.new(@current_user, project_id: @project.id).execute # rubocop: disable CodeReuse/Finder when "snippet", "project_snippet" - SnippetsFinder.new(@current_user, project: @project).execute + SnippetsFinder.new(@current_user, project: @project).execute # rubocop: disable CodeReuse/Finder when "personal_snippet" PersonalSnippet.all else @@ -87,6 +89,7 @@ class NotesFinder end end + # rubocop: disable CodeReuse/ActiveRecord def notes_for_type(noteable_type) if noteable_type == "commit" if Ability.allowed?(@current_user, :download_code, @project) @@ -99,6 +102,7 @@ class NotesFinder @project.notes.where(noteable_type: finder.base_class.name, noteable_id: finder.reorder(nil)) end end + # rubocop: enable CodeReuse/ActiveRecord def notes_on_target if target.respond_to?(:related_notes) diff --git a/app/finders/personal_access_tokens_finder.rb b/app/finders/personal_access_tokens_finder.rb index d975f354a88..6b610ffc687 100644 --- a/app/finders/personal_access_tokens_finder.rb +++ b/app/finders/personal_access_tokens_finder.rb @@ -16,11 +16,13 @@ class PersonalAccessTokensFinder private + # rubocop: disable CodeReuse/ActiveRecord def by_user(tokens) return tokens unless @params[:user] tokens.where(user: @params[:user]) end + # rubocop: enable CodeReuse/ActiveRecord def by_impersonation(tokens) case @params[:impersonation] diff --git a/app/finders/personal_projects_finder.rb b/app/finders/personal_projects_finder.rb index a56a3a1e1a9..16e4e060786 100644 --- a/app/finders/personal_projects_finder.rb +++ b/app/finders/personal_projects_finder.rb @@ -15,6 +15,7 @@ class PersonalProjectsFinder < UnionFinder # min_access_level: integer # # Returns an ActiveRecord::Relation. + # rubocop: disable CodeReuse/ActiveRecord def execute(current_user = nil) return Project.none unless can?(current_user, :read_user_profile, @user) @@ -22,6 +23,7 @@ class PersonalProjectsFinder < UnionFinder find_union(segments, Project).includes(:namespace).order_updated_desc end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/finders/pipeline_schedules_finder.rb b/app/finders/pipeline_schedules_finder.rb index 2ac4289fbbe..d131e1659c1 100644 --- a/app/finders/pipeline_schedules_finder.rb +++ b/app/finders/pipeline_schedules_finder.rb @@ -6,6 +6,7 @@ class PipelineSchedulesFinder @pipeline_schedules = project.pipeline_schedules end + # rubocop: disable CodeReuse/ActiveRecord def execute(scope: nil) scoped_schedules = case scope @@ -19,4 +20,5 @@ class PipelineSchedulesFinder scoped_schedules.order(id: :desc) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb index a99a889a7e9..b03d730f975 100644 --- a/app/finders/pipelines_finder.rb +++ b/app/finders/pipelines_finder.rb @@ -10,6 +10,7 @@ class PipelinesFinder @params = params end + # rubocop: disable CodeReuse/ActiveRecord def execute unless Ability.allowed?(current_user, :read_pipeline, project) return Ci::Pipeline.none @@ -25,16 +26,21 @@ class PipelinesFinder items = by_yaml_errors(items) sort_items(items) end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def ids_for_ref(refs) pipelines.where(ref: refs).group(:ref).select('max(id)') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def from_ids(ids) pipelines.unscoped.where(id: ids) end + # rubocop: enable CodeReuse/ActiveRecord def branches project.repository.branch_names @@ -61,12 +67,15 @@ class PipelinesFinder end end + # rubocop: disable CodeReuse/ActiveRecord def by_status(items) return items unless HasStatus::AVAILABLE_STATUSES.include?(params[:status]) items.where(status: params[:status]) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_ref(items) if params[:ref].present? items.where(ref: params[:ref]) @@ -74,7 +83,9 @@ class PipelinesFinder items end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_sha(items) if params[:sha].present? items.where(sha: params[:sha]) @@ -82,7 +93,9 @@ class PipelinesFinder items end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_name(items) if params[:name].present? items.joins(:user).where(users: { name: params[:name] }) @@ -90,7 +103,9 @@ class PipelinesFinder items end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_username(items) if params[:username].present? items.joins(:user).where(users: { username: params[:username] }) @@ -98,7 +113,9 @@ class PipelinesFinder items end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_yaml_errors(items) case Gitlab::Utils.to_boolean(params[:yaml_errors]) when true @@ -109,7 +126,9 @@ class PipelinesFinder items end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def sort_items(items) order_by = if ALLOWED_INDEXED_COLUMNS.include?(params[:order_by]) params[:order_by] @@ -125,4 +144,5 @@ class PipelinesFinder items.order(order_by => sort) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index 0398ccce93b..0f2fdf317a4 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -35,7 +35,7 @@ class ProjectsFinder < UnionFinder user = params.delete(:user) collection = if user - PersonalProjectsFinder.new(user, finder_params).execute(current_user) + PersonalProjectsFinder.new(user, finder_params).execute(current_user) # rubocop: disable CodeReuse/Finder else init_collection end @@ -64,6 +64,7 @@ class ProjectsFinder < UnionFinder end end + # rubocop: disable CodeReuse/ActiveRecord def collection_with_user if owned_projects? current_user.owned_projects @@ -77,8 +78,10 @@ class ProjectsFinder < UnionFinder end end end + # rubocop: enable CodeReuse/ActiveRecord # Builds a collection for an anonymous user. + # rubocop: disable CodeReuse/ActiveRecord def collection_without_user if private_only? || owned_projects? || min_access_level? Project.none @@ -86,6 +89,7 @@ class ProjectsFinder < UnionFinder Project.public_to_user end end + # rubocop: enable CodeReuse/ActiveRecord def owned_projects? params[:owned].present? @@ -99,9 +103,11 @@ class ProjectsFinder < UnionFinder params[:min_access_level].present? end + # rubocop: disable CodeReuse/ActiveRecord def by_ids(items) project_ids_relation ? items.where(id: project_ids_relation) : items end + # rubocop: enable CodeReuse/ActiveRecord def union(items) find_union(items, Project).with_route @@ -119,9 +125,11 @@ class ProjectsFinder < UnionFinder params[:trending].present? ? items.trending : items end + # rubocop: disable CodeReuse/ActiveRecord def by_visibilty_level(items) params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items end + # rubocop: enable CodeReuse/ActiveRecord def by_tags(items) params[:tag].present? ? items.tagged_with(params[:tag]) : items diff --git a/app/finders/runner_jobs_finder.rb b/app/finders/runner_jobs_finder.rb index 52340f94523..d4f2474197f 100644 --- a/app/finders/runner_jobs_finder.rb +++ b/app/finders/runner_jobs_finder.rb @@ -14,9 +14,11 @@ class RunnerJobsFinder private + # rubocop: disable CodeReuse/ActiveRecord def by_status(items) return items unless HasStatus::AVAILABLE_STATUSES.include?(params[:status]) items.where(status: params[:status]) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb index 9d3772d7541..32da3e8f404 100644 --- a/app/finders/snippets_finder.rb +++ b/app/finders/snippets_finder.rb @@ -41,6 +41,7 @@ class SnippetsFinder < UnionFinder end end + # rubocop: disable CodeReuse/ActiveRecord def authorized_snippets_from_project if can?(current_user, :read_project_snippet, project) if project.team.member?(current_user) @@ -52,7 +53,9 @@ class SnippetsFinder < UnionFinder Snippet.none end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def authorized_snippets # This query was intentionally converted to a raw one to get it work in Rails 5.0. # In Rails 5.0 and 5.1 there's a bug: https://github.com/rails/arel/issues/531 @@ -60,6 +63,7 @@ class SnippetsFinder < UnionFinder Snippet.where("#{feature_available_projects} OR #{not_project_related}") .public_or_visible_to_user(current_user) end + # rubocop: enable CodeReuse/ActiveRecord # Returns a collection of projects that is either public or visible to the # logged in user. @@ -68,6 +72,7 @@ class SnippetsFinder < UnionFinder # the query, e.g. to apply .with_feature_available_for_user on top of it. # This is useful for performance as we can stick those additional filters # at the bottom of e.g. the UNION. + # rubocop: disable CodeReuse/ActiveRecord def projects_for_user return yield(Project.public_to_user) unless current_user @@ -86,6 +91,7 @@ class SnippetsFinder < UnionFinder Project.from("(#{union.to_sql}) AS #{Project.table_name}") end + # rubocop: enable CodeReuse/ActiveRecord def feature_available_projects # Don't return any project related snippets if the user cannot read cross project @@ -109,6 +115,7 @@ class SnippetsFinder < UnionFinder Snippet.arel_table end + # rubocop: disable CodeReuse/ActiveRecord def by_visibility(items) visibility = params[:visibility] || visibility_from_scope @@ -116,12 +123,15 @@ class SnippetsFinder < UnionFinder items.where(visibility_level: visibility) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_author(items) return items unless params[:author] items.where(author_id: params[:author].id) end + # rubocop: enable CodeReuse/ActiveRecord def visibility_from_scope case params[:scope].to_s diff --git a/app/finders/template_finder.rb b/app/finders/template_finder.rb index ea0251bffb6..7cdc7a32acc 100644 --- a/app/finders/template_finder.rb +++ b/app/finders/template_finder.rb @@ -8,7 +8,7 @@ class TemplateFinder class << self def build(type, params = {}) if type == :licenses - LicenseTemplateFinder.new(params) + LicenseTemplateFinder.new(params) # rubocop: disable CodeReuse/Finder else new(type, params) end diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 6e9c8ea6fde..6481893a195 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -120,6 +120,7 @@ class TodosFinder params[:sort] ? items.sort_by_attribute(params[:sort]) : items.order_id_desc end + # rubocop: disable CodeReuse/ActiveRecord def by_action(items) if action? items = items.where(action: to_action_id) @@ -127,7 +128,9 @@ class TodosFinder items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_action_id(items) if action_id? items = items.where(action: action_id) @@ -135,7 +138,9 @@ class TodosFinder items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_author(items) if author? items = items.where(author_id: author.try(:id)) @@ -143,7 +148,9 @@ class TodosFinder items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_project(items) if project? items = items.where(project: project) @@ -151,7 +158,9 @@ class TodosFinder items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_group(items) if group? groups = group.self_and_descendants @@ -164,6 +173,7 @@ class TodosFinder items end + # rubocop: enable CodeReuse/ActiveRecord def by_state(items) case params[:state].to_s @@ -174,6 +184,7 @@ class TodosFinder end end + # rubocop: disable CodeReuse/ActiveRecord def by_type(items) if type? items = items.where(target_type: type) @@ -181,4 +192,5 @@ class TodosFinder items end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/union_finder.rb b/app/finders/union_finder.rb index 33cd1a491f3..91b845871a8 100644 --- a/app/finders/union_finder.rb +++ b/app/finders/union_finder.rb @@ -1,4 +1,5 @@ class UnionFinder + # rubocop: disable CodeReuse/ActiveRecord def find_union(segments, klass) if segments.length > 1 union = Gitlab::SQL::Union.new(segments.map { |s| s.select(:id) }) @@ -8,4 +9,5 @@ class UnionFinder segments.first end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/finders/user_finder.rb b/app/finders/user_finder.rb index 484a93c9873..815388c894e 100644 --- a/app/finders/user_finder.rb +++ b/app/finders/user_finder.rb @@ -14,9 +14,11 @@ class UserFinder end # Tries to find a User, returning nil if none could be found. + # rubocop: disable CodeReuse/ActiveRecord def execute User.find_by(id: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord # Tries to find a User, raising a `ActiveRecord::RecordNotFound` if it could # not be found. diff --git a/app/finders/user_recent_events_finder.rb b/app/finders/user_recent_events_finder.rb index b874f6959c9..7405d6d27d9 100644 --- a/app/finders/user_recent_events_finder.rb +++ b/app/finders/user_recent_events_finder.rb @@ -21,6 +21,7 @@ class UserRecentEventsFinder @params = params end + # rubocop: disable CodeReuse/ActiveRecord def execute return Event.none unless can?(current_user, :read_user_profile, target_user) @@ -29,9 +30,11 @@ class UserRecentEventsFinder .with_associations .limit_recent(LIMIT, params[:offset]) end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def recent_events(offset) sql = <<~SQL (#{projects}) AS projects_for_join @@ -42,10 +45,13 @@ class UserRecentEventsFinder # Workaround for https://github.com/rails/rails/issues/24193 Event.from([Arel.sql(sql)]) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def target_events Event.where(author: target_user) end + # rubocop: enable CodeReuse/ActiveRecord def projects target_user.project_interactions.to_sql diff --git a/app/finders/users_finder.rb b/app/finders/users_finder.rb index 65824a51919..46672301851 100644 --- a/app/finders/users_finder.rb +++ b/app/finders/users_finder.rb @@ -41,11 +41,13 @@ class UsersFinder private + # rubocop: disable CodeReuse/ActiveRecord def by_username(users) return users unless params[:username] users.where(username: params[:username]) end + # rubocop: enable CodeReuse/ActiveRecord def by_search(users) return users unless params[:search].present? @@ -65,18 +67,22 @@ class UsersFinder users.active end + # rubocop: disable CodeReuse/ActiveRecord def by_external_identity(users) return users unless current_user&.admin? && params[:extern_uid] && params[:provider] users.joins(:identities).merge(Identity.with_extern_uid(params[:provider], params[:extern_uid])) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_external(users) return users = users.where.not(external: true) unless current_user&.admin? return users unless params[:external] users.external end + # rubocop: enable CodeReuse/ActiveRecord def by_2fa(users) case params[:two_factor] diff --git a/app/graphql/resolvers/merge_request_resolver.rb b/app/graphql/resolvers/merge_request_resolver.rb index 9f2d348e95f..6b7d0ce6e24 100644 --- a/app/graphql/resolvers/merge_request_resolver.rb +++ b/app/graphql/resolvers/merge_request_resolver.rb @@ -8,6 +8,7 @@ module Resolvers alias_method :project, :object + # rubocop: disable CodeReuse/ActiveRecord def resolve(iid:) return unless project.present? @@ -16,5 +17,6 @@ module Resolvers results.each { |mr| loader.call(mr.iid.to_s, mr) } end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bb7ae03313c..bb401b03709 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,9 +5,11 @@ require 'uri' module ApplicationHelper # See https://docs.gitlab.com/ee/development/ee_features.html#code-in-app-views + # rubocop: disable CodeReuse/ActiveRecord def render_if_exists(partial, locals = {}) render(partial, locals) if lookup_context.exists?(partial, [], true) end + # rubocop: enable CodeReuse/ActiveRecord # Check if a particular controller is the current one # @@ -51,6 +53,7 @@ module ApplicationHelper # Define whenever show last push event # with suggestion to create MR + # rubocop: disable CodeReuse/ActiveRecord def show_last_push_widget?(event) # Skip if event is not about added or modified non-master branch return false unless event && event.last_push_to_non_root? && !event.rm_ref? @@ -68,6 +71,7 @@ module ApplicationHelper true end + # rubocop: enable CodeReuse/ActiveRecord def hexdigest(string) Digest::SHA1.hexdigest string diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb index c17a54a6dff..c158cf20dd6 100644 --- a/app/helpers/auth_helper.rb +++ b/app/helpers/auth_helper.rb @@ -66,9 +66,11 @@ module AuthHelper end end + # rubocop: disable CodeReuse/ActiveRecord def auth_active?(provider) current_user.identities.exists?(provider: provider.to_s) end + # rubocop: enable CodeReuse/ActiveRecord def unlink_allowed?(provider) %w(saml cas3).exclude?(provider.to_s) diff --git a/app/helpers/auto_devops_helper.rb b/app/helpers/auto_devops_helper.rb index 62fc6fb279f..516c8a353ea 100644 --- a/app/helpers/auto_devops_helper.rb +++ b/app/helpers/auto_devops_helper.rb @@ -26,6 +26,7 @@ module AutoDevopsHelper end end + # rubocop: disable CodeReuse/ActiveRecord def cluster_ingress_ip(project) project .cluster_ingresses @@ -34,6 +35,7 @@ module AutoDevopsHelper .pluck(:external_ip) .first end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 7684734c014..b6844d36052 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -213,9 +213,11 @@ module DiffHelper params[:w] == '1' end + # rubocop: disable CodeReuse/ActiveRecord def params_with_whitespace hide_whitespace? ? request.query_parameters.except(:w) : request.query_parameters.merge(w: 1) end + # rubocop: enable CodeReuse/ActiveRecord def toggle_whitespace_link(url, options) options[:class] = [*options[:class], 'btn btn-default'].join(' ') diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 4b3ef2de701..2b7320817ed 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true module EnvironmentHelper + # rubocop: disable CodeReuse/ActiveRecord def environment_for_build(project, build) return unless build.environment project.environments.find_by(name: build.expanded_environment_name) end + # rubocop: enable CodeReuse/ActiveRecord def environment_link_for_build(project, build) environment = environment_for_build(project, build) diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 8396cfe0ac8..1f67c045d1c 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -107,6 +107,7 @@ module IssuablesHelper end end + # rubocop: disable CodeReuse/ActiveRecord def user_dropdown_label(user_id, default_label) return default_label if user_id.nil? return "Unassigned" if user_id == "0" @@ -119,7 +120,9 @@ module IssuablesHelper default_label end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def project_dropdown_label(project_id, default_label) return default_label if project_id.nil? return "Any project" if project_id == "0" @@ -132,7 +135,9 @@ module IssuablesHelper default_label end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group_dropdown_label(group_id, default_label) return default_label if group_id.nil? return "Any group" if group_id == "0" @@ -145,6 +150,7 @@ module IssuablesHelper default_label end end + # rubocop: enable CodeReuse/ActiveRecord def milestone_dropdown_label(milestone_title, default_label = "Milestone") title = @@ -191,11 +197,13 @@ module IssuablesHelper output.join.html_safe end + # rubocop: disable CodeReuse/ActiveRecord def issuable_todo(issuable) if current_user current_user.todos.find_by(target: issuable, state: :pending) end end + # rubocop: enable CodeReuse/ActiveRecord def issuable_labels_tooltip(labels, limit: 5) first, last = labels.partition.with_index { |_, i| i < limit } diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb index 999143002bb..94a030d9d57 100644 --- a/app/helpers/milestones_helper.rb +++ b/app/helpers/milestones_helper.rb @@ -53,6 +53,7 @@ module MilestonesHelper # Returns count of milestones for different states # Uses explicit hash keys as the 'opened' state URL params differs from the db value # and we need to add the total + # rubocop: disable CodeReuse/ActiveRecord def milestone_counts(milestones) counts = milestones.reorder(nil).group(:state).count @@ -62,6 +63,7 @@ module MilestonesHelper all: counts.values.sum || 0 } end + # rubocop: enable CodeReuse/ActiveRecord # Show 'active' class if provided GET param matches check # `or_blank` allows the function to return 'active' when given an empty param diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index e7537ca5733..6c65e573307 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -5,6 +5,7 @@ module NamespacesHelper params.dig(:project, :namespace_id) || params[:namespace_id] end + # rubocop: disable CodeReuse/ActiveRecord def namespaces_options(selected = :current_user, display_path: false, groups: nil, extra_group: nil, groups_only: false) groups ||= current_user.manageable_groups .eager_load(:route) @@ -42,6 +43,7 @@ module NamespacesHelper grouped_options_for_select(options, selected_id) end + # rubocop: enable CodeReuse/ActiveRecord def namespace_icon(namespace, size = 40) if namespace.is_a?(Group) @@ -55,6 +57,7 @@ module NamespacesHelper # Many importers create a temporary Group, so use the real # group if one exists by that name to prevent duplicates. + # rubocop: disable CodeReuse/ActiveRecord def dedup_extra_group(extra_group) unless extra_group.persisted? existing_group = Group.find_by(path: extra_group.path) @@ -63,6 +66,7 @@ module NamespacesHelper extra_group end + # rubocop: enable CodeReuse/ActiveRecord def options_for_group(namespaces, display_path:, type:) group_label = type.pluralize diff --git a/app/helpers/numbers_helper.rb b/app/helpers/numbers_helper.rb index f609b6c0cec..3c0b11c4d32 100644 --- a/app/helpers/numbers_helper.rb +++ b/app/helpers/numbers_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module NumbersHelper + # rubocop: disable CodeReuse/ActiveRecord def limited_counter_with_delimiter(resource, **options) limit = options.fetch(:limit, 1000).to_i count = resource.limit(limit + 1).count(:all) @@ -10,4 +11,5 @@ module NumbersHelper number_with_delimiter(count, options) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 89fee06ee77..8b17e6ef75d 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -222,6 +222,7 @@ module ProjectsHelper # # If no limit is applied we'll just issue a COUNT since the result set could # be too large to load into memory. + # rubocop: disable CodeReuse/ActiveRecord def any_projects?(projects) return projects.any? if projects.is_a?(Array) @@ -231,6 +232,7 @@ module ProjectsHelper projects.except(:offset).any? end end + # rubocop: enable CodeReuse/ActiveRecord def show_projects?(projects, params) !!(params[:personal] || params[:name] || any_projects?(projects)) diff --git a/app/helpers/safe_params_helper.rb b/app/helpers/safe_params_helper.rb index 72bf1377b02..18bbf3347a8 100644 --- a/app/helpers/safe_params_helper.rb +++ b/app/helpers/safe_params_helper.rb @@ -3,6 +3,7 @@ module SafeParamsHelper # Rails 5.0 requires to permit `params` if they're used in url helpers. # Use this helper when generating links with `params.merge(...)` + # rubocop: disable CodeReuse/ActiveRecord def safe_params if params.respond_to?(:permit!) params.except(:host, :port, :protocol).permit! @@ -10,4 +11,5 @@ module SafeParamsHelper params end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index c509cd592c4..4f9e1322b56 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -101,6 +101,7 @@ module SearchHelper end # Autocomplete results for the current user's groups + # rubocop: disable CodeReuse/ActiveRecord def groups_autocomplete(term, limit = 5) current_user.authorized_groups.order_id_desc.search(term).limit(limit).map do |group| { @@ -112,8 +113,10 @@ module SearchHelper } end end + # rubocop: enable CodeReuse/ActiveRecord # Autocomplete results for the current user's projects + # rubocop: disable CodeReuse/ActiveRecord def projects_autocomplete(term, limit = 5) current_user.authorized_projects.order_id_desc.search_by_title(term) .sorted_by_stars.non_archived.limit(limit).map do |p| @@ -127,6 +130,7 @@ module SearchHelper } end end + # rubocop: enable CodeReuse/ActiveRecord def search_result_sanitize(str) Sanitize.clean(str) diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 80f61a371fd..6d2da5699fb 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -7,6 +7,7 @@ module TreeHelper # their corresponding partials # # tree - A `Tree` object for the current tree + # rubocop: disable CodeReuse/ActiveRecord def render_tree(tree) # Sort submodules and folders together by name ahead of files folders, files, submodules = tree.trees, tree.blobs, tree.submodules @@ -22,6 +23,7 @@ module TreeHelper tree << render(partial: 'projects/tree/tree_row', collection: items) if items.present? tree.join.html_safe end + # rubocop: enable CodeReuse/ActiveRecord # Return an image icon depending on the file type and mode # @@ -124,6 +126,7 @@ module TreeHelper end # returns the relative path of the first subdir that doesn't have only one directory descendant + # rubocop: disable CodeReuse/ActiveRecord def flatten_tree(root_path, tree) return tree.flat_path.sub(%r{\A#{Regexp.escape(root_path)}/}, '') if tree.flat_path.present? @@ -134,6 +137,7 @@ module TreeHelper return tree.name end end + # rubocop: enable CodeReuse/ActiveRecord def selected_branch @branch_name || tree_edit_branch diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb index c8b1ab5033a..602e5afe26b 100644 --- a/app/mailers/emails/issues.rb +++ b/app/mailers/emails/issues.rb @@ -19,6 +19,7 @@ module Emails mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) end + # rubocop: disable CodeReuse/ActiveRecord def reassigned_issue_email(recipient_id, issue_id, previous_assignee_ids, updated_by_user_id, reason = nil) setup_issue_mail(issue_id, recipient_id) @@ -27,6 +28,7 @@ module Emails mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason)) end + # rubocop: enable CodeReuse/ActiveRecord def closed_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil) setup_issue_mail(issue_id, recipient_id) diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb index 70f65d4e58d..67af0a4eb98 100644 --- a/app/mailers/emails/merge_requests.rb +++ b/app/mailers/emails/merge_requests.rb @@ -22,12 +22,14 @@ module Emails mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) end + # rubocop: disable CodeReuse/ActiveRecord def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id, reason = nil) setup_merge_request_mail(merge_request_id, recipient_id) @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason)) end + # rubocop: enable CodeReuse/ActiveRecord def relabeled_merge_request_email(recipient_id, merge_request_id, label_names, updated_by_user_id, reason = nil) setup_merge_request_mail(merge_request_id, recipient_id) diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb index 40d7b9ccd7a..2ea1aea1f51 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -9,6 +9,7 @@ module Emails mail(to: @user.notification_email, subject: subject("Account was created for you")) end + # rubocop: disable CodeReuse/ActiveRecord def new_ssh_key_email(key_id) @key = Key.find_by(id: key_id) @@ -18,7 +19,9 @@ module Emails @target_url = user_url(@user) mail(to: @user.notification_email, subject: subject("SSH key was added to your account")) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def new_gpg_key_email(gpg_key_id) @gpg_key = GpgKey.find_by(id: gpg_key_id) @@ -28,5 +31,6 @@ module Emails @target_url = user_url(@user) mail(to: @user.notification_email, subject: subject("GPG key was added to your account")) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/mailers/repository_check_mailer.rb b/app/mailers/repository_check_mailer.rb index 4bcf371cfc0..145169be8a6 100644 --- a/app/mailers/repository_check_mailer.rb +++ b/app/mailers/repository_check_mailer.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class RepositoryCheckMailer < BaseMailer + # rubocop: disable CodeReuse/ActiveRecord def notify(failed_count) @message = if failed_count == 1 @@ -14,4 +15,5 @@ class RepositoryCheckMailer < BaseMailer subject: "GitLab Admin | #{@message}" ) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index cc1408cb397..ab738c2fad8 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -140,9 +140,11 @@ module Ci end def retry(build, current_user) + # rubocop: disable CodeReuse/ServiceClass Ci::RetryBuildService .new(build.project, current_user) .execute(build) + # rubocop: enable CodeReuse/ServiceClass end end @@ -225,11 +227,13 @@ module Ci self.when == 'manual' end + # rubocop: disable CodeReuse/ServiceClass def play(current_user) Ci::PlayBuildService .new(project, current_user) .execute(self) end + # rubocop: enable CodeReuse/ServiceClass def cancelable? active? || created? @@ -386,9 +390,11 @@ module Ci update(coverage: coverage) if coverage.present? end + # rubocop: disable CodeReuse/ServiceClass def parse_trace_sections! ExtractSectionsFromBuildTraceService.new(project, user).execute(self) end + # rubocop: enable CodeReuse/ServiceClass def trace Gitlab::Ci::Trace.new(self) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 8c075253400..6dac577c514 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -387,10 +387,12 @@ module Ci end end + # rubocop: disable CodeReuse/ServiceClass def retry_failed(current_user) Ci::RetryPipelineService.new(project, current_user) .execute(self) end + # rubocop: enable CodeReuse/ServiceClass def mark_as_processable_after_stage(stage_idx) builds.skipped.after_stage(stage_idx).find_each(&:process) @@ -525,9 +527,11 @@ module Ci project.notes.for_commit_id(sha) end + # rubocop: disable CodeReuse/ServiceClass def process! Ci::ProcessPipelineService.new(project, user).execute(self) end + # rubocop: enable CodeReuse/ServiceClass def update_status retry_optimistic_lock(self) do diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index b65d7672973..fe2f144ef03 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -58,9 +58,11 @@ class CommitStatus < ActiveRecord::Base # These are pages deployments and external statuses. # before_create unless: :importing? do + # rubocop: disable CodeReuse/ServiceClass Ci::EnsureStageService.new(project, user).execute(self) do |stage| self.run_after_commit { StageUpdateWorker.perform_async(stage.id) } end + # rubocop: enable CodeReuse/ServiceClass end state_machine :status do @@ -130,10 +132,12 @@ class CommitStatus < ActiveRecord::Base after_transition any => :failed do |commit_status| next unless commit_status.project + # rubocop: disable CodeReuse/ServiceClass commit_status.run_after_commit do MergeRequests::AddTodoWhenBuildFailsService .new(project, nil).execute(self) end + # rubocop: enable CodeReuse/ServiceClass end end diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 41413854d5c..93ca3a5daf4 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -10,6 +10,7 @@ class ContainerRepository < ActiveRecord::Base before_destroy :delete_tags! + # rubocop: disable CodeReuse/ServiceClass def registry @registry ||= begin token = Auth::ContainerRegistryAuthenticationService.full_access_token(path) @@ -20,6 +21,7 @@ class ContainerRepository < ActiveRecord::Base ContainerRegistry::Registry.new(url, token: token, path: host_port) end end + # rubocop: enable CodeReuse/ServiceClass def path @path ||= [project.full_path, name] diff --git a/app/models/dashboard_group_milestone.rb b/app/models/dashboard_group_milestone.rb index 13807d43265..4e39f60b0d2 100644 --- a/app/models/dashboard_group_milestone.rb +++ b/app/models/dashboard_group_milestone.rb @@ -13,7 +13,7 @@ class DashboardGroupMilestone < GlobalMilestone end def self.build_collection(groups) - MilestonesFinder.new(group_ids: groups.pluck(:id)).execute.map { |m| new(m) } + MilestonesFinder.new(group_ids: groups.pluck(:id)).execute.map { |m| new(m) } # rubocop: disable CodeReuse/Finder end override :group_milestone? diff --git a/app/models/environment.rb b/app/models/environment.rb index c8d1d378ae0..309bd4f37c9 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -158,9 +158,11 @@ class Environment < ActiveRecord::Base prometheus_adapter.query(:additional_metrics_environment, self) if has_metrics? end + # rubocop: disable CodeReuse/ServiceClass def prometheus_adapter @prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform).prometheus_adapter end + # rubocop: enable CodeReuse/ServiceClass def slug super.presence || generate_slug diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index 6e23e811b0e..a6cebabe089 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -17,7 +17,7 @@ class GlobalMilestone params = { project_ids: projects.map(&:id), state: params[:state] } - child_milestones = MilestonesFinder.new(params).execute + child_milestones = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder milestones = child_milestones.select(:id, :title).group_by(&:title).map do |title, grouped| milestones_relation = Milestone.where(id: grouped.map(&:id)) @@ -48,7 +48,7 @@ class GlobalMilestone params = { group_ids: [group.id], state: 'all' } - relation = MilestonesFinder.new(params).execute + relation = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder grouped_by_state = relation.reorder(nil).group(:state).count { @@ -64,7 +64,7 @@ class GlobalMilestone params = { project_ids: projects.map(&:id), state: 'all' } - relation = MilestonesFinder.new(params).execute + relation = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder project_milestones_by_state_and_title = relation.reorder(nil).group(:state, :title).count opened = count_by_state(project_milestones_by_state_and_title, 'active') diff --git a/app/models/group.rb b/app/models/group.rb index 106a1f4a94c..024e77188b8 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -236,14 +236,18 @@ class Group < Namespace system_hook_service.execute_hooks_for(self, :destroy) end + # rubocop: disable CodeReuse/ServiceClass def system_hook_service SystemHooksService.new end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def refresh_members_authorized_projects(blocking: true) UserProjectAccessChangedService.new(user_ids_for_project_authorizations) .execute(blocking: blocking) end + # rubocop: enable CodeReuse/ServiceClass def user_ids_for_project_authorizations members_with_parents.pluck(:user_id) diff --git a/app/models/hooks/service_hook.rb b/app/models/hooks/service_hook.rb index bda82a116a1..7d9f6d89d44 100644 --- a/app/models/hooks/service_hook.rb +++ b/app/models/hooks/service_hook.rb @@ -4,7 +4,9 @@ class ServiceHook < WebHook belongs_to :service validates :service, presence: true + # rubocop: disable CodeReuse/ServiceClass def execute(data) WebHookService.new(self, data, 'service_hook').execute end + # rubocop: enable CodeReuse/ServiceClass end diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index 20f15c15277..771a61b090f 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -11,13 +11,17 @@ class WebHook < ActiveRecord::Base validates :token, format: { without: /\n/ } validates :push_events_branch_filter, branch_filter: true + # rubocop: disable CodeReuse/ServiceClass def execute(data, hook_name) WebHookService.new(self, data, hook_name).execute end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def async_execute(data, hook_name) WebHookService.new(self, data, hook_name).async_execute end + # rubocop: enable CodeReuse/ServiceClass # Allow urls pointing localhost and the local network def allow_local_requests? diff --git a/app/models/issue.rb b/app/models/issue.rb index d0cd7461daa..d13fbcf002c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -172,6 +172,7 @@ class Issue < ActiveRecord::Base # All branches containing the current issue's ID, except for # those with a merge request open referencing the current issue. + # rubocop: disable CodeReuse/ServiceClass def related_branches(current_user) branches_with_iid = project.repository.branch_names.select do |branch| branch =~ /\A#{iid}-(?!\d+-stable)/i @@ -185,6 +186,7 @@ class Issue < ActiveRecord::Base branches_with_iid - branches_with_merge_request end + # rubocop: enable CodeReuse/ServiceClass def suggested_branch_name return to_branch_name unless project.repository.branch_exists?(to_branch_name) @@ -278,9 +280,11 @@ class Issue < ActiveRecord::Base true end + # rubocop: disable CodeReuse/ServiceClass def update_project_counter_caches Projects::OpenIssuesCountService.new(project).refresh_cache end + # rubocop: enable CodeReuse/ServiceClass private diff --git a/app/models/key.rb b/app/models/key.rb index 3bb0d2f6f9c..bdb83e12793 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -55,9 +55,11 @@ class Key < ActiveRecord::Base "key-#{id}" end + # rubocop: disable CodeReuse/ServiceClass def update_last_used_at Keys::LastUsedService.new(self).execute end + # rubocop: enable CodeReuse/ServiceClass def add_to_shell GitlabShellWorker.perform_async( @@ -67,9 +69,11 @@ class Key < ActiveRecord::Base ) end + # rubocop: disable CodeReuse/ServiceClass def post_create_hook SystemHooksService.new.execute_hooks_for(self, :create) end + # rubocop: enable CodeReuse/ServiceClass def remove_from_shell GitlabShellWorker.perform_async( @@ -79,15 +83,19 @@ class Key < ActiveRecord::Base ) end + # rubocop: disable CodeReuse/ServiceClass def refresh_user_cache return unless user Users::KeysCountService.new(user).refresh_cache end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def post_destroy_hook SystemHooksService.new.execute_hooks_for(self, :destroy) end + # rubocop: enable CodeReuse/ServiceClass def public_key @public_key ||= Gitlab::SSHPublicKey.new(key) diff --git a/app/models/member.rb b/app/models/member.rb index d9b4e8d2ac6..0696ea46c8b 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -145,6 +145,7 @@ class Member < ActiveRecord::Base end def add_user(source, user, access_level, existing_members: nil, current_user: nil, expires_at: nil, ldap: false) + # rubocop: disable CodeReuse/ServiceClass # `user` can be either a User object, User ID or an email to be invited member = retrieve_member(source, user, existing_members) access_level = retrieve_access_level(access_level) @@ -171,6 +172,7 @@ class Member < ActiveRecord::Base end member + # rubocop: enable CodeReuse/ServiceClass end def add_users(source, users, access_level, current_user: nil, expires_at: nil) @@ -339,12 +341,14 @@ class Member < ActiveRecord::Base @notification_setting ||= user&.notification_settings_for(source) end + # rubocop: disable CodeReuse/ServiceClass def notifiable?(type, opts = {}) # always notify when there isn't a user yet return true if user.blank? NotificationRecipientService.notifiable?(user, type, notifiable_options.merge(opts)) end + # rubocop: enable CodeReuse/ServiceClass private @@ -374,6 +378,7 @@ class Member < ActiveRecord::Base # in a transaction. Doing so can lead to the job running before the # transaction has been committed, resulting in the job either throwing an # error or not doing any meaningful work. + # rubocop: disable CodeReuse/ServiceClass def refresh_member_authorized_projects # If user/source is being destroyed, project access are going to be # destroyed eventually because of DB foreign keys, so we shouldn't bother @@ -382,6 +387,7 @@ class Member < ActiveRecord::Base UserProjectAccessChangedService.new(user_id).execute end + # rubocop: enable CodeReuse/ServiceClass def after_accept_invite post_create_hook @@ -395,13 +401,17 @@ class Member < ActiveRecord::Base post_create_hook end + # rubocop: disable CodeReuse/ServiceClass def system_hook_service SystemHooksService.new end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def notification_service NotificationService.new end + # rubocop: enable CodeReuse/ServiceClass def notifiable_options {} diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 0154fe5aeba..537f2a3a231 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -138,7 +138,9 @@ class ProjectMember < Member super end + # rubocop: disable CodeReuse/ServiceClass def event_service EventCreateService.new end + # rubocop: enable CodeReuse/ServiceClass end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 396647a14ae..e19bf62dcd0 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -137,12 +137,14 @@ class MergeRequest < ActiveRecord::Base Gitlab::Timeless.timeless(merge_request, &block) end + # rubocop: disable CodeReuse/ServiceClass after_transition unchecked: :cannot_be_merged do |merge_request, transition| if merge_request.notify_conflict? NotificationService.new.merge_request_unmergeable(merge_request) TodoService.new.merge_request_became_unmergeable(merge_request) end end + # rubocop: enable CodeReuse/ServiceClass def check_state?(merge_status) [:unchecked, :cannot_be_merged_recheck].include?(merge_status.to_sym) @@ -623,11 +625,13 @@ class MergeRequest < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def reload_diff(current_user = nil) return unless open? MergeRequests::ReloadDiffsService.new(self, current_user).execute end + # rubocop: enable CodeReuse/ServiceClass def check_if_can_be_merged return unless self.class.state_machines[:merge_status].check_state?(merge_status) && Gitlab::Database.read_write? @@ -1036,6 +1040,7 @@ class MergeRequest < ActiveRecord::Base actual_head_pipeline&.has_test_reports? end + # rubocop: disable CodeReuse/ServiceClass def compare_test_reports unless has_test_reports? return { status: :error, status_reason: 'This merge request does not have test reports' } @@ -1050,7 +1055,9 @@ class MergeRequest < ActiveRecord::Base data end || { status: :parsing } end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def calculate_reactive_cache(identifier, *args) case identifier.to_sym when :compare_test_results @@ -1060,6 +1067,7 @@ class MergeRequest < ActiveRecord::Base raise NotImplementedError, "Unknown identifier: #{identifier}" end end + # rubocop: enable CodeReuse/ServiceClass def all_commits # MySQL doesn't support LIMIT in a subquery. @@ -1125,6 +1133,7 @@ class MergeRequest < ActiveRecord::Base diff_refs && diff_refs.complete? end + # rubocop: disable CodeReuse/ServiceClass def update_diff_discussion_positions(old_diff_refs:, new_diff_refs:, current_user: nil) return unless has_complete_diff_refs? return if new_diff_refs == old_diff_refs @@ -1154,6 +1163,7 @@ class MergeRequest < ActiveRecord::Base .execute(self) end end + # rubocop: enable CodeReuse/ServiceClass def keep_around_commit project.repository.keep_around(self.merge_commit_sha) @@ -1189,9 +1199,11 @@ class MergeRequest < ActiveRecord::Base true end + # rubocop: disable CodeReuse/ServiceClass def update_project_counter_caches Projects::OpenMergeRequestsCountService.new(target_project).refresh_cache end + # rubocop: enable CodeReuse/ServiceClass def first_contribution? return false if project.team.max_member_access(author_id) > Gitlab::Access::GUEST diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index bbe4f6f7969..02c6b650f33 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -219,12 +219,14 @@ class MergeRequestDiff < ActiveRecord::Base self.id == merge_request.latest_merge_request_diff_id end + # rubocop: disable CodeReuse/ServiceClass def compare_with(sha) # When compare merge request versions we want diff A..B instead of A...B # so we handle cases when user does squash and rebase of the commits between versions. # For this reason we set straight to true by default. CompareService.new(project, head_commit_sha).execute(project, sha, straight: true) end + # rubocop: enable CodeReuse/ServiceClass private diff --git a/app/models/note.rb b/app/models/note.rb index 8f090cc31e6..4429c1dcb07 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -181,6 +181,7 @@ class Note < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def cross_reference? return unless system? @@ -190,6 +191,7 @@ class Note < ActiveRecord::Base SystemNoteService.cross_reference?(note) end end + # rubocop: enable CodeReuse/ServiceClass def diff_note? false diff --git a/app/models/pages_domain.rb b/app/models/pages_domain.rb index 7739a3894d3..7a33ade826b 100644 --- a/app/models/pages_domain.rb +++ b/app/models/pages_domain.rb @@ -140,9 +140,11 @@ class PagesDomain < ActiveRecord::Base self.verification_code = SecureRandom.hex(16) end + # rubocop: disable CodeReuse/ServiceClass def update_daemon ::Projects::UpdatePagesConfigurationService.new(project).execute end + # rubocop: enable CodeReuse/ServiceClass def pages_config_changed? project_id_changed? || diff --git a/app/models/project.rb b/app/models/project.rb index f057c63afdf..c37915e111f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1114,12 +1114,14 @@ class Project < ActiveRecord::Base find_or_initialize_services.find { |service| service.to_param == name } end + # rubocop: disable CodeReuse/ServiceClass def create_labels Label.templates.each do |label| params = label.attributes.except('id', 'template', 'created_at', 'updated_at') Labels::FindOrCreateService.new(nil, self, params).execute(skip_authorization: true) end end + # rubocop: enable CodeReuse/ServiceClass def find_service(list, name) list.find { |service| service.to_param == name } @@ -1167,6 +1169,7 @@ class Project < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def send_move_instructions(old_path_with_namespace) # New project path needs to be committed to the DB or notification will # retrieve stale information @@ -1174,6 +1177,7 @@ class Project < ActiveRecord::Base NotificationService.new.project_was_moved(self, old_path_with_namespace) end end + # rubocop: enable CodeReuse/ServiceClass def owner if group @@ -1183,6 +1187,7 @@ class Project < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def execute_hooks(data, hooks_scope = :push_hooks) run_after_commit_or_now do hooks.hooks_for(hooks_scope).select_active(hooks_scope, data).each do |hook| @@ -1191,6 +1196,7 @@ class Project < ActiveRecord::Base SystemHooksService.new.execute_hooks(data, hooks_scope) end end + # rubocop: enable CodeReuse/ServiceClass def execute_services(data, hooks_scope = :push_hooks) # Call only service hooks that are active for this scope @@ -1505,13 +1511,17 @@ class Project < ActiveRecord::Base self.runners_token && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.runners_token) end + # rubocop: disable CodeReuse/ServiceClass def open_issues_count(current_user = nil) Projects::OpenIssuesCountService.new(self, current_user).count end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def open_merge_requests_count Projects::OpenMergeRequestsCountService.new(self).count end + # rubocop: enable CodeReuse/ServiceClass def visibility_level_allowed_as_fork?(level = self.visibility_level) return true unless forked? @@ -1592,6 +1602,7 @@ class Project < ActiveRecord::Base end # TODO: what to do here when not using Legacy Storage? Do we still need to rename and delay removal? + # rubocop: disable CodeReuse/ServiceClass def remove_pages # Projects with a missing namespace cannot have their pages removed return unless namespace @@ -1607,6 +1618,7 @@ class Project < ActiveRecord::Base PagesWorker.perform_in(5.minutes, :remove, namespace.full_path, temp_path) end end + # rubocop: enable CodeReuse/ServiceClass def rename_repo path_before = previous_changes['path'].first @@ -1667,6 +1679,7 @@ class Project < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def after_create_default_branch return unless default_branch @@ -1687,6 +1700,7 @@ class Project < ActiveRecord::Base ProtectedBranches::CreateService.new(self, creator, params).execute(skip_authorization: true) end end + # rubocop: enable CodeReuse/ServiceClass def remove_import_jid return unless import_jid @@ -1917,9 +1931,11 @@ class Project < ActiveRecord::Base # @deprecated cannot remove yet because it has an index with its name in elasticsearch alias_method :path_with_namespace, :full_path + # rubocop: disable CodeReuse/ServiceClass def forks_count Projects::ForksCountService.new(self).count end + # rubocop: enable CodeReuse/ServiceClass def legacy_storage? [nil, 0].include?(self.storage_version) @@ -2070,6 +2086,7 @@ class Project < ActiveRecord::Base private + # rubocop: disable CodeReuse/ServiceClass def rename_or_migrate_repository! if Gitlab::CurrentSettings.hashed_storage_enabled? && storage_upgradable? && @@ -2079,6 +2096,7 @@ class Project < ActiveRecord::Base storage.rename_repo end end + # rubocop: enable CodeReuse/ServiceClass def storage_upgradable? storage_version != LATEST_STORAGE_VERSION @@ -2103,6 +2121,7 @@ class Project < ActiveRecord::Base self.project_feature.untrack_statistics_for_deletion! end + # rubocop: disable CodeReuse/ServiceClass def execute_rename_repository_hooks!(full_path_before) # When we import a project overwriting the original project, there # is a move operation. In that case we don't want to send the instructions. @@ -2113,6 +2132,7 @@ class Project < ActiveRecord::Base reload_repository! end + # rubocop: enable CodeReuse/ServiceClass def storage @storage ||= diff --git a/app/models/project_import_state.rb b/app/models/project_import_state.rb index 89ed09af96a..d59cb43dea4 100644 --- a/app/models/project_import_state.rb +++ b/app/models/project_import_state.rb @@ -48,9 +48,11 @@ class ProjectImportState < ActiveRecord::Base project.reset_cache_and_import_attrs if Gitlab::ImportSources.importer_names.include?(project.import_type) && project.repo_exists? + # rubocop: disable CodeReuse/ServiceClass state.run_after_commit do Projects::AfterImportService.new(project).execute end + # rubocop: enable CodeReuse/ServiceClass end end end diff --git a/app/models/project_services/slash_commands_service.rb b/app/models/project_services/slash_commands_service.rb index e3ab60adefd..bfabc6d262c 100644 --- a/app/models/project_services/slash_commands_service.rb +++ b/app/models/project_services/slash_commands_service.rb @@ -44,11 +44,15 @@ class SlashCommandsService < Service private + # rubocop: disable CodeReuse/ServiceClass def find_chat_user(params) ChatNames::FindUserService.new(self, params).execute end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def authorize_chat_name_url(params) ChatNames::AuthorizeUserService.new(self, params).execute end + # rubocop: enable CodeReuse/ServiceClass end diff --git a/app/models/user.rb b/app/models/user.rb index 568ec101016..dac8779488d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,6 +61,7 @@ class User < ActiveRecord::Base # Override Devise::Models::Trackable#update_tracked_fields! # to limit database writes to at most once every hour + # rubocop: disable CodeReuse/ServiceClass def update_tracked_fields!(request) return if Gitlab::Database.read_only? @@ -71,6 +72,7 @@ class User < ActiveRecord::Base Users::UpdateService.new(self, user: self).execute(validate: false) end + # rubocop: enable CodeReuse/ServiceClass attr_accessor :force_random_password @@ -455,7 +457,7 @@ class User < ActiveRecord::Base def find_by_personal_access_token(token_string) return unless token_string - PersonalAccessTokensFinder.new(state: 'active').find_by(token: token_string)&.user + PersonalAccessTokensFinder.new(state: 'active').find_by(token: token_string)&.user # rubocop: disable CodeReuse/Finder end # Returns a user for the given SSH key. @@ -627,6 +629,7 @@ class User < ActiveRecord::Base # hash and `_was` variables getting munged. # By using an `after_commit` instead of `after_update`, we avoid the recursive callback # scenario, though it then requires us to use the `previous_changes` hash + # rubocop: disable CodeReuse/ServiceClass def update_emails_with_primary_email(previous_email) primary_email_record = emails.find_by(email: email) Emails::DestroyService.new(self, user: self).execute(primary_email_record) if primary_email_record @@ -635,6 +638,7 @@ class User < ActiveRecord::Base # have access to the original confirmation values at this point, so just set confirmed_at Emails::CreateService.new(self, user: self, email: previous_email).execute(confirmed_at: confirmed_at) end + # rubocop: enable CodeReuse/ServiceClass def update_invalid_gpg_signatures gpg_keys.each(&:update_invalid_gpg_signatures) @@ -663,9 +667,11 @@ class User < ActiveRecord::Base all_expanded_groups.where(require_two_factor_authentication: true) end + # rubocop: disable CodeReuse/ServiceClass def refresh_authorized_projects Users::RefreshAuthorizedProjectsService.new(self).execute end + # rubocop: enable CodeReuse/ServiceClass def remove_project_authorizations(project_ids) project_authorizations.where(project_id: project_ids).delete_all @@ -718,11 +724,13 @@ class User < ActiveRecord::Base authorized_projects(Gitlab::Access::REPORTER).non_archived.with_issues_enabled end + # rubocop: disable CodeReuse/ServiceClass def require_ssh_key? count = Users::KeysCountService.new(self).count count.zero? && Gitlab::ProtocolAccess.allowed?('ssh') end + # rubocop: enable CodeReuse/ServiceClass def require_password_creation_for_web? allow_password_authentication_for_web? && password_automatically_set? @@ -786,6 +794,7 @@ class User < ActiveRecord::Base projects_limit - personal_projects_count end + # rubocop: disable CodeReuse/ServiceClass def recent_push(project = nil) service = Users::LastPushEventService.new(self) @@ -795,6 +804,7 @@ class User < ActiveRecord::Base service.last_event_for_user end end + # rubocop: enable CodeReuse/ServiceClass def several_namespaces? owned_groups.any? || maintainers_groups.any? @@ -932,9 +942,11 @@ class User < ActiveRecord::Base email.start_with?('temp-email-for-oauth') end + # rubocop: disable CodeReuse/ServiceClass def avatar_url(size: nil, scale: 2, **args) GravatarService.new.execute(email, size, scale, username: username) end + # rubocop: enable CodeReuse/ServiceClass def primary_email_verified? confirmed? && !temp_oauth_email? @@ -1000,26 +1012,32 @@ class User < ActiveRecord::Base system_hook_service.execute_hooks_for(self, :destroy) end + # rubocop: disable CodeReuse/ServiceClass def remove_key_cache Users::KeysCountService.new(self).delete_cache end + # rubocop: enable CodeReuse/ServiceClass def delete_async(deleted_by:, params: {}) block if params[:hard_delete] DeleteUserWorker.perform_async(deleted_by.id, id, params.to_h) end + # rubocop: disable CodeReuse/ServiceClass def notification_service NotificationService.new end + # rubocop: enable CodeReuse/ServiceClass def log_info(message) Gitlab::AppLogger.info message end + # rubocop: disable CodeReuse/ServiceClass def system_hook_service SystemHooksService.new end + # rubocop: enable CodeReuse/ServiceClass def starred?(project) starred_projects.exists?(project.id) @@ -1188,6 +1206,7 @@ class User < ActiveRecord::Base # See: # <https://github.com/plataformatec/devise/blob/v4.0.0/lib/devise/models/lockable.rb#L92> # + # rubocop: disable CodeReuse/ServiceClass def increment_failed_attempts! return if ::Gitlab::Database.read_only? @@ -1200,6 +1219,7 @@ class User < ActiveRecord::Base Users::UpdateService.new(self, user: self).execute(validate: false) end end + # rubocop: enable CodeReuse/ServiceClass def access_level if admin? @@ -1440,7 +1460,7 @@ class User < ActiveRecord::Base &creation_block ) - Users::UpdateService.new(user, user: user).execute(validate: false) + Users::UpdateService.new(user, user: user).execute(validate: false) # rubocop: disable CodeReuse/ServiceClass user ensure Gitlab::ExclusiveLease.cancel(lease_key, uuid) diff --git a/app/policies/application_setting/term_policy.rb b/app/policies/application_setting/term_policy.rb index 17f00f33d35..c0d2ceaa349 100644 --- a/app/policies/application_setting/term_policy.rb +++ b/app/policies/application_setting/term_policy.rb @@ -19,6 +19,7 @@ class ApplicationSetting rule { terms_accepted }.prevent :accept_terms + # rubocop: disable CodeReuse/ActiveRecord def agreement strong_memoize(:agreement) do next nil if @user.nil? || @subject.nil? @@ -26,5 +27,6 @@ class ApplicationSetting @user.term_agreements.find_by(term: @subject) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/policies/ci/runner_policy.rb b/app/policies/ci/runner_policy.rb index c44f22b6ad3..de76b7b2b5b 100644 --- a/app/policies/ci/runner_policy.rb +++ b/app/policies/ci/runner_policy.rb @@ -5,7 +5,9 @@ module Ci with_options scope: :subject, score: 0 condition(:locked, scope: :subject) { @subject.locked? } + # rubocop: disable CodeReuse/ActiveRecord condition(:owned_runner) { @user.ci_owned_runners.exists?(@subject.id) } + # rubocop: enable CodeReuse/ActiveRecord rule { anonymous }.prevent_all diff --git a/app/policies/deploy_key_policy.rb b/app/policies/deploy_key_policy.rb index 204c54a5b20..7f0ec011e79 100644 --- a/app/policies/deploy_key_policy.rb +++ b/app/policies/deploy_key_policy.rb @@ -4,7 +4,9 @@ class DeployKeyPolicy < BasePolicy with_options scope: :subject, score: 0 condition(:private_deploy_key) { @subject.private? } + # rubocop: disable CodeReuse/ActiveRecord condition(:has_deploy_key) { @user.project_deploy_keys.exists?(id: @subject.id) } + # rubocop: enable CodeReuse/ActiveRecord rule { anonymous }.prevent_all diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb index 273a93a1423..d0e84b1aa38 100644 --- a/app/policies/project_policy.rb +++ b/app/policies/project_policy.rb @@ -398,6 +398,7 @@ class ProjectPolicy < BasePolicy end end + # rubocop: disable CodeReuse/ActiveRecord def project_group_member? return false if @user.nil? @@ -407,6 +408,7 @@ class ProjectPolicy < BasePolicy project.group.requesters.exists?(user_id: @user.id) ) end + # rubocop: enable CodeReuse/ActiveRecord def team_access_level return -1 if @user.nil? diff --git a/app/presenters/conversational_development_index/metric_presenter.rb b/app/presenters/conversational_development_index/metric_presenter.rb index e0312c6f431..9639b84cf56 100644 --- a/app/presenters/conversational_development_index/metric_presenter.rb +++ b/app/presenters/conversational_development_index/metric_presenter.rb @@ -139,8 +139,10 @@ module ConversationalDevelopmentIndex ] end + # rubocop: disable CodeReuse/ActiveRecord def average_percentage_score cards.sum(&:percentage_score) / cards.size.to_f end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/presenters/merge_request_presenter.rb b/app/presenters/merge_request_presenter.rb index 8c4eac3c31d..3f565b826dd 100644 --- a/app/presenters/merge_request_presenter.rb +++ b/app/presenters/merge_request_presenter.rb @@ -142,6 +142,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated end def assign_to_closing_issues_link + # rubocop: disable CodeReuse/ServiceClass issues = MergeRequests::AssignIssuesService.new(project, current_user, merge_request: merge_request, @@ -152,6 +153,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated pluralize_this_issue = issues.count > 1 ? "these issues" : "this issue" link_to "Assign yourself to #{pluralize_this_issue}", path, method: :post end + # rubocop: enable CodeReuse/ServiceClass end def can_revert_on_current_merge_request? @@ -202,7 +204,9 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated end def conflicts + # rubocop: disable CodeReuse/ServiceClass @conflicts ||= MergeRequests::Conflicts::ListService.new(merge_request) + # rubocop: enable CodeReuse/ServiceClass end def closing_issues diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb index 6a54054badc..d2434d96fd7 100644 --- a/app/presenters/project_presenter.rb +++ b/app/presenters/project_presenter.rb @@ -319,7 +319,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated end def tags_to_show - project.tag_list.take(MAX_TAGS_TO_SHOW) + project.tag_list.take(MAX_TAGS_TO_SHOW) # rubocop: disable CodeReuse/ActiveRecord end def count_of_extra_tags_not_shown diff --git a/app/presenters/projects/settings/deploy_keys_presenter.rb b/app/presenters/projects/settings/deploy_keys_presenter.rb index 28eaef00a12..85518c9a3a4 100644 --- a/app/presenters/projects/settings/deploy_keys_presenter.rb +++ b/app/presenters/projects/settings/deploy_keys_presenter.rb @@ -12,9 +12,11 @@ module Projects @key ||= DeployKey.new.tap { |dk| dk.deploy_keys_projects.build } end + # rubocop: disable CodeReuse/ActiveRecord def enabled_keys @enabled_keys ||= project.deploy_keys.includes(:projects) end + # rubocop: enable CodeReuse/ActiveRecord def any_keys_enabled? enabled_keys.any? @@ -24,14 +26,17 @@ module Projects @available_keys ||= current_user.accessible_deploy_keys - enabled_keys end + # rubocop: disable CodeReuse/ActiveRecord def available_project_keys @available_project_keys ||= current_user.project_deploy_keys.includes(:projects) - enabled_keys end + # rubocop: enable CodeReuse/ActiveRecord def key_available?(deploy_key) available_keys.include?(deploy_key) end + # rubocop: disable CodeReuse/ActiveRecord def available_public_keys return @available_public_keys if defined?(@available_public_keys) @@ -41,9 +46,10 @@ module Projects # in @available_project_keys. @available_public_keys -= available_project_keys end + # rubocop: enable CodeReuse/ActiveRecord def as_json - serializer = DeployKeySerializer.new + serializer = DeployKeySerializer.new # rubocop: disable CodeReuse/Serializer opts = { user: current_user } { diff --git a/app/serializers/commit_entity.rb b/app/serializers/commit_entity.rb index b3287c66554..ce76659fa46 100644 --- a/app/serializers/commit_entity.rb +++ b/app/serializers/commit_entity.rb @@ -6,7 +6,7 @@ class CommitEntity < API::Entities::Commit expose :author, using: UserEntity expose :author_gravatar_url do |commit| - GravatarService.new.execute(commit.author_email) + GravatarService.new.execute(commit.author_email) # rubocop: disable CodeReuse/ServiceClass end expose :commit_url do |commit| diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index f75ace14d9c..878cc5290bd 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -35,13 +35,17 @@ class DiffsEntity < Grape::Entity diffs_project_merge_request_path(merge_request&.project, merge_request) end + # rubocop: disable CodeReuse/ActiveRecord expose :added_lines do |diffs| diffs.diff_files.sum(&:added_lines) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord expose :removed_lines do |diffs| diffs.diff_files.sum(&:removed_lines) end + # rubocop: enable CodeReuse/ActiveRecord expose :render_overflow_warning do |diffs| render_overflow_warning?(diffs.diff_files) diff --git a/app/serializers/environment_serializer.rb b/app/serializers/environment_serializer.rb index dc1686c30c4..598ce5f9e4f 100644 --- a/app/serializers/environment_serializer.rb +++ b/app/serializers/environment_serializer.rb @@ -29,6 +29,7 @@ class EnvironmentSerializer < BaseSerializer private + # rubocop: disable CodeReuse/ActiveRecord def itemize(resource) items = resource.order('folder ASC') .group('COALESCE(environment_type, name)') @@ -46,4 +47,5 @@ class EnvironmentSerializer < BaseSerializer Item.new(item.folder, item.size, environments[item.last_id]) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/serializers/group_child_entity.rb b/app/serializers/group_child_entity.rb index f6804fe7f6a..20d7032c970 100644 --- a/app/serializers/group_child_entity.rb +++ b/app/serializers/group_child_entity.rb @@ -66,11 +66,13 @@ class GroupChildEntity < Grape::Entity private + # rubocop: disable CodeReuse/ActiveRecord def membership return unless request.current_user @membership ||= request.current_user.members.find_by(source: object) end + # rubocop: enable CodeReuse/ActiveRecord def project? object.is_a?(Project) diff --git a/app/serializers/group_entity.rb b/app/serializers/group_entity.rb index c46c342ee5d..0e1bc9a6b3d 100644 --- a/app/serializers/group_entity.rb +++ b/app/serializers/group_entity.rb @@ -17,9 +17,11 @@ class GroupEntity < Grape::Entity end expose :permissions do + # rubocop: disable CodeReuse/ActiveRecord expose :human_group_access do |group, options| group.group_members.find_by(user_id: request.current_user)&.human_access end + # rubocop: enable CodeReuse/ActiveRecord end expose :edit_path do |group| diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index f55d448235a..380e8804f51 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -243,7 +243,7 @@ class MergeRequestWidgetEntity < IssuableEntity def presenter(merge_request) @presenters ||= {} - @presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) + @presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter end # Once SchedulePopulateMergeRequestMetricsWithEventsData fully runs, diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index 3205578b83e..4f31af3c46d 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -4,6 +4,7 @@ class PipelineSerializer < BaseSerializer include WithPagination entity PipelineDetailsEntity + # rubocop: disable CodeReuse/ActiveRecord def represent(resource, opts = {}) if resource.is_a?(ActiveRecord::Relation) resource = resource.preload([ @@ -33,6 +34,7 @@ class PipelineSerializer < BaseSerializer super(resource, opts) end + # rubocop: enable CodeReuse/ActiveRecord def represent_status(resource) return {} unless resource.present? diff --git a/app/services/applications/create_service.rb b/app/services/applications/create_service.rb index 7db90c0b3c6..3d88c4f064e 100644 --- a/app/services/applications/create_service.rb +++ b/app/services/applications/create_service.rb @@ -2,10 +2,12 @@ module Applications class CreateService + # rubocop: disable CodeReuse/ActiveRecord def initialize(current_user, params) @current_user = current_user @params = params.except(:ip_address) end + # rubocop: enable CodeReuse/ActiveRecord def execute(request) Doorkeeper::Application.create(@params) diff --git a/app/services/boards/issues/list_service.rb b/app/services/boards/issues/list_service.rb index 0db1418b37a..4e352f2dc63 100644 --- a/app/services/boards/issues/list_service.rb +++ b/app/services/boards/issues/list_service.rb @@ -9,6 +9,7 @@ module Boards fetch_issues.order_by_position_and_priority end + # rubocop: disable CodeReuse/ActiveRecord def metadata keys = metadata_fields.keys columns = metadata_fields.values_at(*keys).join(', ') @@ -16,6 +17,7 @@ module Boards Hash[keys.zip(results.flatten)] end + # rubocop: enable CodeReuse/ActiveRecord private @@ -24,6 +26,7 @@ module Boards end # We memoize the query here since the finder methods we use are quite complex. This does not memoize the result of the query. + # rubocop: disable CodeReuse/ActiveRecord def fetch_issues strong_memoize(:fetch_issues) do issues = IssuesFinder.new(current_user, filter_params).execute @@ -31,6 +34,7 @@ module Boards filter(issues).reorder(nil) end end + # rubocop: enable CodeReuse/ActiveRecord def filter(issues) issues = without_board_labels(issues) unless list&.movable? || list&.closed? @@ -72,24 +76,32 @@ module Boards params[:include_subgroups] = board.group_board? end + # rubocop: disable CodeReuse/ActiveRecord def board_label_ids @board_label_ids ||= board.lists.movable.pluck(:label_id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def without_board_labels(issues) return issues unless board_label_ids.any? issues.where.not('EXISTS (?)', issues_label_links.limit(1)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def issues_label_links LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id").where(label_id: board_label_ids) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def with_list_label(issues) issues.where('EXISTS (?)', LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id") .where("label_links.label_id = ?", list.label_id).limit(1)) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/boards/issues/move_service.rb b/app/services/boards/issues/move_service.rb index 6fd8a23b2a1..7dd87034410 100644 --- a/app/services/boards/issues/move_service.rb +++ b/app/services/boards/issues/move_service.rb @@ -21,13 +21,17 @@ module Boards moving_from_list != moving_to_list end + # rubocop: disable CodeReuse/ActiveRecord def moving_from_list @moving_from_list ||= board.lists.find_by(id: params[:from_list_id]) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def moving_to_list @moving_to_list ||= board.lists.find_by(id: params[:to_list_id]) end + # rubocop: enable CodeReuse/ActiveRecord def update(issue) ::Issues::UpdateService.new(issue.project, current_user, issue_params(issue)).execute(issue) @@ -61,6 +65,7 @@ module Boards [moving_to_list.label_id].compact end + # rubocop: disable CodeReuse/ActiveRecord def remove_label_ids label_ids = if moving_to_list.movable? @@ -73,6 +78,7 @@ module Boards Array(label_ids).compact end + # rubocop: enable CodeReuse/ActiveRecord def move_between_ids return unless params[:move_after_id] || params[:move_before_id] diff --git a/app/services/boards/lists/destroy_service.rb b/app/services/boards/lists/destroy_service.rb index e12d4f46e19..609c430caed 100644 --- a/app/services/boards/lists/destroy_service.rb +++ b/app/services/boards/lists/destroy_service.rb @@ -18,10 +18,12 @@ module Boards attr_reader :board + # rubocop: disable CodeReuse/ActiveRecord def decrement_higher_lists(list) board.lists.movable.where('position > ?', list.position) .update_all('position = position - 1') end + # rubocop: enable CodeReuse/ActiveRecord def remove_list(list) list.destroy diff --git a/app/services/boards/lists/move_service.rb b/app/services/boards/lists/move_service.rb index 27a36051662..93f81837d1a 100644 --- a/app/services/boards/lists/move_service.rb +++ b/app/services/boards/lists/move_service.rb @@ -34,17 +34,21 @@ module Boards end end + # rubocop: disable CodeReuse/ActiveRecord def decrement_intermediate_lists board.lists.movable.where('position > ?', old_position) .where('position <= ?', new_position) .update_all('position = position - 1') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def increment_intermediate_lists board.lists.movable.where('position >= ?', new_position) .where('position < ?', old_position) .update_all('position = position + 1') end + # rubocop: enable CodeReuse/ActiveRecord def update_list_position(list) list.update_attribute(:position, new_position) diff --git a/app/services/chat_names/find_user_service.rb b/app/services/chat_names/find_user_service.rb index 854b191c45c..c91738fa4c7 100644 --- a/app/services/chat_names/find_user_service.rb +++ b/app/services/chat_names/find_user_service.rb @@ -17,6 +17,7 @@ module ChatNames private + # rubocop: disable CodeReuse/ActiveRecord def find_chat_name ChatName.find_by( service: @service, @@ -24,5 +25,6 @@ module ChatNames chat_id: @params[:user_id] ) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/ci/compare_test_reports_service.rb b/app/services/ci/compare_test_reports_service.rb index ec25e934a27..2293f95f56b 100644 --- a/app/services/ci/compare_test_reports_service.rb +++ b/app/services/ci/compare_test_reports_service.rb @@ -3,6 +3,7 @@ module Ci class CompareTestReportsService < ::BaseService def execute(base_pipeline, head_pipeline) + # rubocop: disable CodeReuse/Serializer comparer = Gitlab::Ci::Reports::TestReportsComparer .new(base_pipeline&.test_reports, head_pipeline.test_reports) @@ -19,6 +20,7 @@ module Ci key: key(base_pipeline, head_pipeline), status_reason: e.message } + # rubocop: enable CodeReuse/Serializer end def latest?(base_pipeline, head_pipeline, data) diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 85df8bcff8c..92a8438ab2f 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -65,6 +65,7 @@ module Ci end end + # rubocop: disable CodeReuse/ActiveRecord def auto_cancelable_pipelines project.pipelines .where(ref: pipeline.ref) @@ -72,6 +73,7 @@ module Ci .where.not(sha: project.commit(pipeline.ref).try(:id)) .created_or_pending end + # rubocop: enable CodeReuse/ActiveRecord def pipeline_created_counter @pipeline_created_counter ||= Gitlab::Metrics @@ -84,8 +86,10 @@ module Ci end end + # rubocop: disable CodeReuse/ActiveRecord def related_merge_requests pipeline.project.source_of_merge_requests.opened.where(source_branch: pipeline.ref) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/ci/ensure_stage_service.rb b/app/services/ci/ensure_stage_service.rb index 3d0e39d1b9f..cbb3a2e4709 100644 --- a/app/services/ci/ensure_stage_service.rb +++ b/app/services/ci/ensure_stage_service.rb @@ -38,9 +38,11 @@ module Ci EOS end + # rubocop: disable CodeReuse/ActiveRecord def find_stage @build.pipeline.stages.find_by(name: @build.stage) end + # rubocop: enable CodeReuse/ActiveRecord def create_stage Ci::Stage.create!(name: @build.stage, diff --git a/app/services/ci/extract_sections_from_build_trace_service.rb b/app/services/ci/extract_sections_from_build_trace_service.rb index 693f6d55be3..97f9918fdb7 100644 --- a/app/services/ci/extract_sections_from_build_trace_service.rb +++ b/app/services/ci/extract_sections_from_build_trace_service.rb @@ -11,11 +11,13 @@ module Ci private + # rubocop: disable CodeReuse/ActiveRecord def find_or_create_name(name) project.build_trace_section_names.find_or_create_by!(name: name) rescue ActiveRecord::RecordInvalid project.build_trace_section_names.find_by!(name: name) end + # rubocop: enable CodeReuse/ActiveRecord def extract_sections(build) build.trace.extract_sections.map do |attr| diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb index cafee76a33c..69341a6c263 100644 --- a/app/services/ci/process_pipeline_service.rb +++ b/app/services/ci/process_pipeline_service.rb @@ -60,17 +60,23 @@ module Ci end end + # rubocop: disable CodeReuse/ActiveRecord def status_for_prior_stages(index) pipeline.builds.where('stage_idx < ?', index).latest.status || 'success' end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def stage_indexes_of_created_builds created_builds.order(:stage_idx).pluck('distinct stage_idx') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def created_builds_in_stage(index) created_builds.where(stage_idx: index) end + # rubocop: enable CodeReuse/ActiveRecord def created_builds pipeline.builds.created @@ -80,6 +86,7 @@ module Ci # This replicates what is db/post_migrate/20170416103934_upate_retried_for_ci_build.rb # and ensures that functionality will not be broken before migration is run # this updates only when there are data that needs to be updated, there are two groups with no retried flag + # rubocop: disable CodeReuse/ActiveRecord def update_retried # find the latest builds for each name latest_statuses = pipeline.statuses.latest @@ -93,6 +100,7 @@ module Ci .where.not(id: latest_statuses.map(&:first)) .update_all(retried: true) if latest_statuses.any? end + # rubocop: enable CodeReuse/ActiveRecord def enqueue_build(build) Ci::EnqueueBuildService.new(project, @user).execute(build) diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb index 11f85627faf..5a7be921389 100644 --- a/app/services/ci/register_job_service.rb +++ b/app/services/ci/register_job_service.rb @@ -15,6 +15,7 @@ module Ci @runner = runner end + # rubocop: disable CodeReuse/ActiveRecord def execute(params = {}) builds = if runner.instance_type? @@ -63,6 +64,7 @@ module Ci register_failure Result.new(nil, valid) end + # rubocop: enable CodeReuse/ActiveRecord private @@ -84,6 +86,7 @@ module Ci true end + # rubocop: disable CodeReuse/ActiveRecord def builds_for_shared_runner new_builds. # don't run projects which have not enabled shared runners and builds @@ -97,11 +100,15 @@ module Ci joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id") .order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def builds_for_project_runner new_builds.where(project: runner.projects.without_deleted.with_builds_enabled).order('id ASC') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def builds_for_group_runner # Workaround for weird Rails bug, that makes `runner.groups.to_sql` to return `runner_id = NULL` groups = ::Group.joins(:runner_namespaces).merge(runner.runner_namespaces) @@ -113,11 +120,14 @@ module Ci .without_deleted new_builds.where(project: projects).order('id ASC') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def running_builds_for_shared_runners Ci::Build.running.where(runner: Ci::Runner.instance_type) .group(:project_id).select(:project_id, 'count(*) AS running_builds') end + # rubocop: enable CodeReuse/ActiveRecord def new_builds builds = Ci::Build.pending.unstarted @@ -138,6 +148,7 @@ module Ci attempt_counter.increment end + # rubocop: disable CodeReuse/ActiveRecord def jobs_running_for_project(job) return '+Inf' unless runner.instance_type? @@ -146,6 +157,7 @@ module Ci .limit(JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET + 1).count - 1 running_jobs_count < JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET ? running_jobs_count : "#{JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET}+" end + # rubocop: enable CodeReuse/ActiveRecord def failed_attempt_counter @failed_attempt_counter ||= Gitlab::Metrics.counter(:job_register_attempts_failed_total, "Counts the times a runner tries to register a job") diff --git a/app/services/ci/retry_build_service.rb b/app/services/ci/retry_build_service.rb index 6ceb59e4780..218f1e63d08 100644 --- a/app/services/ci/retry_build_service.rb +++ b/app/services/ci/retry_build_service.rb @@ -19,6 +19,7 @@ module Ci end end + # rubocop: disable CodeReuse/ActiveRecord def reprocess!(build) unless can?(current_user, :update_build, build) raise Gitlab::Access::AccessDeniedError @@ -41,5 +42,6 @@ module Ci project.builds.create!(Hash[attributes]) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/cohorts_service.rb b/app/services/cohorts_service.rb index 7a14e97f749..6d466c2fc9c 100644 --- a/app/services/cohorts_service.rb +++ b/app/services/cohorts_service.rb @@ -78,6 +78,7 @@ class CohortsService # created_at_month can never be nil, but last_activity_on_month can (when a # user has never logged in, just been created). This covers the last # MONTHS_INCLUDED months. + # rubocop: disable CodeReuse/ActiveRecord def counts_by_month @counts_by_month ||= begin @@ -91,6 +92,7 @@ class CohortsService .count end end + # rubocop: enable CodeReuse/ActiveRecord def column_to_date(column) if Gitlab::Database.postgresql? diff --git a/app/services/concerns/issues/resolve_discussions.rb b/app/services/concerns/issues/resolve_discussions.rb index 1563ed965df..f0e9862ca30 100644 --- a/app/services/concerns/issues/resolve_discussions.rb +++ b/app/services/concerns/issues/resolve_discussions.rb @@ -13,12 +13,14 @@ module Issues end # rubocop:enable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def merge_request_to_resolve_discussions_of strong_memoize(:merge_request_to_resolve_discussions_of) do MergeRequestsFinder.new(current_user, project_id: project.id) .find_by(iid: merge_request_to_resolve_discussions_of_iid) end end + # rubocop: enable CodeReuse/ActiveRecord def discussions_to_resolve return [] unless merge_request_to_resolve_discussions_of diff --git a/app/services/create_release_service.rb b/app/services/create_release_service.rb index 09c68390007..8d1fdbe11c3 100644 --- a/app/services/create_release_service.rb +++ b/app/services/create_release_service.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class CreateReleaseService < BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(tag_name, release_description) repository = project.repository existing_tag = repository.find_tag(tag_name) @@ -21,6 +22,7 @@ class CreateReleaseService < BaseService error('Tag does not exist', 404) end end + # rubocop: enable CodeReuse/ActiveRecord def success(release) super().merge(release: release) diff --git a/app/services/delete_merged_branches_service.rb b/app/services/delete_merged_branches_service.rb index ff3e4783fe3..ced87a1c37a 100644 --- a/app/services/delete_merged_branches_service.rb +++ b/app/services/delete_merged_branches_service.rb @@ -21,10 +21,12 @@ class DeleteMergedBranchesService < BaseService private + # rubocop: disable CodeReuse/ActiveRecord def merge_request_branch_names # reorder(nil) is necessary for SELECT DISTINCT because default scope adds an ORDER BY source_names = project.origin_merge_requests.opened.reorder(nil).uniq.pluck(:source_branch) target_names = project.merge_requests.opened.reorder(nil).uniq.pluck(:target_branch) (source_names + target_names).uniq end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 26e90e8cf8c..f1883877d56 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -94,6 +94,7 @@ class GitPushService < BaseService ProjectCacheWorker.perform_async(project.id, types, [:commit_count, :repository_size]) end + # rubocop: disable CodeReuse/ActiveRecord def update_signatures commit_shas = last_pushed_commits.map(&:sha) @@ -108,6 +109,7 @@ class GitPushService < BaseService CreateGpgSignatureWorker.perform_async(commit_shas, project.id) end + # rubocop: enable CodeReuse/ActiveRecord # Schedules processing of commit messages. def process_commit_messages diff --git a/app/services/groups/destroy_service.rb b/app/services/groups/destroy_service.rb index 93d84bd8a9c..641111aeadc 100644 --- a/app/services/groups/destroy_service.rb +++ b/app/services/groups/destroy_service.rb @@ -9,6 +9,7 @@ module Groups Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}") end + # rubocop: disable CodeReuse/ActiveRecord def execute group.prepare_for_destroy @@ -30,5 +31,6 @@ module Groups group.destroy end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/groups/transfer_service.rb b/app/services/groups/transfer_service.rb index ea7576077f3..5efa746dfb9 100644 --- a/app/services/groups/transfer_service.rb +++ b/app/services/groups/transfer_service.rb @@ -64,9 +64,11 @@ module Groups end end + # rubocop: disable CodeReuse/ActiveRecord def namespace_with_same_path? Namespace.exists?(path: @group.path, parent: @new_parent_group) end + # rubocop: enable CodeReuse/ActiveRecord def update_group_attributes if @new_parent_group && @new_parent_group.visibility_level < @group.visibility_level @@ -78,6 +80,7 @@ module Groups @group.save! end + # rubocop: disable CodeReuse/ActiveRecord def update_children_and_projects_visibility descendants = @group.descendants.where("visibility_level > ?", @new_parent_group.visibility_level) @@ -90,6 +93,7 @@ module Groups .where("visibility_level > ?", @new_parent_group.visibility_level) .update_all(visibility_level: @new_parent_group.visibility_level) end + # rubocop: enable CodeReuse/ActiveRecord def raise_transfer_error(message) raise TransferError, ERROR_MESSAGES[message] diff --git a/app/services/import_export_clean_up_service.rb b/app/services/import_export_clean_up_service.rb index e75a951944e..3ecb51b60d0 100644 --- a/app/services/import_export_clean_up_service.rb +++ b/app/services/import_export_clean_up_service.rb @@ -26,10 +26,12 @@ class ImportExportCleanUpService Gitlab::Popen.popen(%W(find #{path} -not -path #{path} -mmin +#{mmin} -delete)) end + # rubocop: disable CodeReuse/ActiveRecord def clean_up_export_object_files ImportExportUpload.where('updated_at < ?', mmin.minutes.ago).each do |upload| upload.remove_export_file! upload.save! end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/services/issuable/bulk_update_service.rb b/app/services/issuable/bulk_update_service.rb index 051d5ba881d..c4beddf2294 100644 --- a/app/services/issuable/bulk_update_service.rb +++ b/app/services/issuable/bulk_update_service.rb @@ -2,6 +2,7 @@ module Issuable class BulkUpdateService < IssuableBaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(type) model_class = type.classify.constantize update_class = type.classify.pluralize.constantize::UpdateService @@ -28,6 +29,7 @@ module Issuable success: !items.count.zero? } end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 1259c2c2b3d..3e8b9f84042 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -68,11 +68,13 @@ class IssuableBaseService < BaseService find_or_create_label_ids end + # rubocop: disable CodeReuse/ActiveRecord def filter_labels_in_param(key) return if params[key].to_a.empty? params[key] = available_labels.where(id: params[key]).pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord def find_or_create_label_ids labels = params.delete(:labels) @@ -247,6 +249,7 @@ class IssuableBaseService < BaseService end end + # rubocop: disable CodeReuse/ActiveRecord def change_todo(issuable) case params.delete(:todo_event) when 'add' @@ -256,6 +259,7 @@ class IssuableBaseService < BaseService todo_service.mark_todos_as_done_by_ids(todo, current_user) if todo end end + # rubocop: enable CodeReuse/ActiveRecord def toggle_award(issuable) award = params.delete(:emoji_award) diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index 25389a946bb..ef08adf4f92 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -31,6 +31,7 @@ module Issues issue.project.execute_services(issue_data, hooks_scope) end + # rubocop: disable CodeReuse/ActiveRecord def filter_assignee(issuable) return if params[:assignee_ids].blank? @@ -48,6 +49,7 @@ module Issues params.delete(:assignee_ids) end end + # rubocop: enable CodeReuse/ActiveRecord def update_project_counter_caches?(issue) super || issue.confidential_changed? diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb index ec9d8944e4e..d2bdba1e627 100644 --- a/app/services/issues/move_service.rb +++ b/app/services/issues/move_service.rb @@ -58,6 +58,7 @@ module Issues CreateService.new(@new_project, @current_user, new_params).execute end + # rubocop: disable CodeReuse/ActiveRecord def cloneable_label_ids params = { project_id: @new_project.id, @@ -67,6 +68,7 @@ module Issues LabelsFinder.new(current_user, params).execute.pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord def cloneable_milestone_id title = @old_issue.milestone&.title @@ -97,6 +99,7 @@ module Issues end end + # rubocop: disable CodeReuse/ActiveRecord def copy_resource_label_events @old_issue.resource_label_events.find_in_batches do |batch| events = batch.map do |event| @@ -108,6 +111,7 @@ module Issues Gitlab::Database.bulk_insert(ResourceLabelEvent.table_name, events) end end + # rubocop: enable CodeReuse/ActiveRecord def rewrite_issue_award_emoji rewrite_award_emoji(@old_issue, @new_issue) diff --git a/app/services/issues/referenced_merge_requests_service.rb b/app/services/issues/referenced_merge_requests_service.rb index 40d78502697..a69cd324b1e 100644 --- a/app/services/issues/referenced_merge_requests_service.rb +++ b/app/services/issues/referenced_merge_requests_service.rb @@ -2,6 +2,7 @@ module Issues class ReferencedMergeRequestsService < Issues::BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(issue) referenced = referenced_merge_requests(issue) closed_by = closed_by_merge_requests(issue) @@ -12,6 +13,7 @@ module Issues [sort_by_iid(referenced), sort_by_iid(closed_by)] end + # rubocop: enable CodeReuse/ActiveRecord def referenced_merge_requests(issue) merge_requests = extract_merge_requests(issue) @@ -29,6 +31,7 @@ module Issues ) end + # rubocop: disable CodeReuse/ActiveRecord def closed_by_merge_requests(issue) return [] unless issue.open? @@ -39,6 +42,7 @@ module Issues ids = MergeRequestsClosingIssues.where(merge_request_id: merge_requests.map(&:id), issue_id: issue.id).pluck(:merge_request_id) merge_requests.select { |mr| mr.id.in?(ids) } end + # rubocop: enable CodeReuse/ActiveRecord private @@ -54,10 +58,12 @@ module Issues ext.merge_requests end + # rubocop: disable CodeReuse/ActiveRecord def issue_notes(issue) @issue_notes ||= {} @issue_notes[issue] ||= issue.notes.includes(:author) end + # rubocop: enable CodeReuse/ActiveRecord def sort_by_iid(merge_requests) Gitlab::IssuableSorter.sort(project, merge_requests) { |mr| mr.iid.to_s } diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index faa4c8a5a4f..b54b0bf6ef6 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -67,6 +67,7 @@ module Issues issue.move_between(issue_before, issue_after) end + # rubocop: disable CodeReuse/ActiveRecord def change_issue_duplicate(issue) canonical_issue_id = params.delete(:canonical_issue_id) canonical_issue = IssuesFinder.new(current_user).find_by(id: canonical_issue_id) @@ -75,6 +76,7 @@ module Issues Issues::DuplicateService.new(project, current_user).execute(issue, canonical_issue) end end + # rubocop: enable CodeReuse/ActiveRecord def move_issue_to_new_project(issue) target_project = params.delete(:target_project) @@ -89,6 +91,7 @@ module Issues private + # rubocop: disable CodeReuse/ActiveRecord def get_issue_if_allowed(id, board_group_id = nil) return unless id @@ -101,6 +104,7 @@ module Issues issue if can?(current_user, :update_issue, issue) end + # rubocop: enable CodeReuse/ActiveRecord def create_confidentiality_note(issue) SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user) diff --git a/app/services/labels/find_or_create_service.rb b/app/services/labels/find_or_create_service.rb index e4486764a4d..628873519d7 100644 --- a/app/services/labels/find_or_create_service.rb +++ b/app/services/labels/find_or_create_service.rb @@ -29,6 +29,7 @@ module Labels # Only creates the label if current_user can do so, if the label does not exist # and the user can not create the label, nil is returned + # rubocop: disable CodeReuse/ActiveRecord def find_or_create_label new_label = available_labels.find_by(title: title) @@ -39,6 +40,7 @@ module Labels new_label end + # rubocop: enable CodeReuse/ActiveRecord def title params[:title] || params[:name] diff --git a/app/services/labels/promote_service.rb b/app/services/labels/promote_service.rb index fcdcea2d0ea..f30ad706c63 100644 --- a/app/services/labels/promote_service.rb +++ b/app/services/labels/promote_service.rb @@ -4,6 +4,7 @@ module Labels class PromoteService < BaseService BATCH_SIZE = 1000 + # rubocop: disable CodeReuse/ActiveRecord def execute(label) return unless project.group && label.is_a?(ProjectLabel) @@ -27,9 +28,11 @@ module Labels new_label end end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def subscribe_users(new_label, label_ids) # users can be subscribed to multiple labels that will be merged into the group one # we want to keep only one subscription / user @@ -38,7 +41,9 @@ module Labels .pluck('MAX(id)') Subscription.where(id: ids_to_update).update_all(subscribable_id: new_label.id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def label_ids_for_merge(new_label) LabelsFinder .new(current_user, title: new_label.title, group_id: project.group.id) @@ -46,34 +51,45 @@ module Labels .where.not(id: new_label) .select(:id) # Can't use pluck() to avoid object-creation because of the batching end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_issuables(new_label, label_ids) LabelLink .where(label: label_ids) .update_all(label_id: new_label) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_resource_label_events(new_label, label_ids) ResourceLabelEvent .where(label: label_ids) .update_all(label_id: new_label) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_issue_board_lists(new_label, label_ids) List .where(label: label_ids) .update_all(label_id: new_label) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_priorities(new_label, label_ids) LabelPriority .where(label: label_ids) .update_all(label_id: new_label) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_project_labels(label_ids) Label.where(id: label_ids).destroy_all # rubocop: disable DestroyAll end + # rubocop: enable CodeReuse/ActiveRecord def clone_label_to_group_label(label) params = label.attributes.slice('title', 'description', 'color') diff --git a/app/services/labels/transfer_service.rb b/app/services/labels/transfer_service.rb index 1bd8d9fc325..aec0282b31b 100644 --- a/app/services/labels/transfer_service.rb +++ b/app/services/labels/transfer_service.rb @@ -32,6 +32,7 @@ module Labels attr_reader :current_user, :old_group, :project + # rubocop: disable CodeReuse/ActiveRecord def labels_to_transfer label_ids = [] label_ids << group_labels_applied_to_issues.select(:id) @@ -41,7 +42,9 @@ module Labels Label.where("labels.id IN (#{union.to_sql})").reorder(nil).uniq # rubocop:disable GitlabSecurity/SqlInjection end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group_labels_applied_to_issues Label.joins(:issues) .where( @@ -49,7 +52,9 @@ module Labels labels: { type: 'GroupLabel', group_id: old_group.id } ) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group_labels_applied_to_merge_requests Label.joins(:merge_requests) .where( @@ -57,6 +62,7 @@ module Labels labels: { type: 'GroupLabel', group_id: old_group.id } ) end + # rubocop: enable CodeReuse/ActiveRecord def find_or_create_label!(label) params = label.attributes.slice('title', 'description', 'color') @@ -65,6 +71,7 @@ module Labels new_label.id end + # rubocop: disable CodeReuse/ActiveRecord def update_label_links(labels, old_label_id:, new_label_id:) # use 'labels' relation to get label_link ids only of issues/MRs # in the project being transferred. @@ -76,10 +83,13 @@ module Labels LabelLink.where(id: link_ids, label_id: old_label_id) .update_all(label_id: new_label_id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_label_priorities(old_label_id:, new_label_id:) LabelPriority.where(project_id: project.id, label_id: old_label_id) .update_all(label_id: new_label_id) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/lfs/file_transformer.rb b/app/services/lfs/file_transformer.rb index c8eccb8e6cd..6ecf583cb6a 100644 --- a/app/services/lfs/file_transformer.rb +++ b/app/services/lfs/file_transformer.rb @@ -55,11 +55,13 @@ module Lfs @cached_attributes ||= Gitlab::Git::AttributesAtRefParser.new(repository, branch_name) end + # rubocop: disable CodeReuse/ActiveRecord def create_lfs_object!(lfs_pointer_file, file_content) LfsObject.find_or_create_by(oid: lfs_pointer_file.sha256, size: lfs_pointer_file.size) do |lfs_object| lfs_object.file = CarrierWaveStringFile.new(file_content) end end + # rubocop: enable CodeReuse/ActiveRecord def link_lfs_object!(lfs_object) project.lfs_objects << lfs_object diff --git a/app/services/lfs/lock_file_service.rb b/app/services/lfs/lock_file_service.rb index 78434909d68..c7730d24bdc 100644 --- a/app/services/lfs/lock_file_service.rb +++ b/app/services/lfs/lock_file_service.rb @@ -18,9 +18,11 @@ module Lfs private + # rubocop: disable CodeReuse/ActiveRecord def current_lock project.lfs_file_locks.find_by(path: params[:path]) end + # rubocop: enable CodeReuse/ActiveRecord def create_lock! lock = project.lfs_file_locks.create!(user: current_user, diff --git a/app/services/lfs/locks_finder_service.rb b/app/services/lfs/locks_finder_service.rb index d52cf0e3cc4..4a5b2a52921 100644 --- a/app/services/lfs/locks_finder_service.rb +++ b/app/services/lfs/locks_finder_service.rb @@ -10,10 +10,12 @@ module Lfs private + # rubocop: disable CodeReuse/ActiveRecord def find_locks options = params.slice(:id, :path).compact.symbolize_keys project.lfs_file_locks.where(options) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/lfs/unlock_file_service.rb b/app/services/lfs/unlock_file_service.rb index 4d1443bf772..a42916d86bb 100644 --- a/app/services/lfs/unlock_file_service.rb +++ b/app/services/lfs/unlock_file_service.rb @@ -32,6 +32,7 @@ module Lfs end end + # rubocop: disable CodeReuse/ActiveRecord def lock return @lock if defined?(@lock) @@ -41,5 +42,6 @@ module Lfs project.lfs_file_locks.find_by!(path: params[:path]) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index e6dd0e12a3a..aa5d8406d0f 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -55,6 +55,7 @@ module MergeRequests end # Returns all origin and fork merge requests from `@project` satisfying passed arguments. + # rubocop: disable CodeReuse/ActiveRecord def merge_requests_for(source_branch, mr_states: [:opened]) MergeRequest .with_state(mr_states) @@ -62,6 +63,7 @@ module MergeRequests .preload(:source_project) # we don't need a #includes since we're just preloading for the #select .select(&:source_project) end + # rubocop: enable CodeReuse/ActiveRecord def pipeline_merge_requests(pipeline) merge_requests_for(pipeline.ref).each do |merge_request| diff --git a/app/services/merge_requests/create_from_issue_service.rb b/app/services/merge_requests/create_from_issue_service.rb index d9a29693987..020af0bb950 100644 --- a/app/services/merge_requests/create_from_issue_service.rb +++ b/app/services/merge_requests/create_from_issue_service.rb @@ -32,9 +32,11 @@ module MergeRequests private + # rubocop: disable CodeReuse/ActiveRecord def issue @issue ||= IssuesFinder.new(current_user, project_id: project.id).find_by(iid: @issue_iid) end + # rubocop: enable CodeReuse/ActiveRecord def branch_name @branch ||= @branch_name || issue.to_branch_name diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb index c36a2ecbfe3..6081a7d1de0 100644 --- a/app/services/merge_requests/create_service.rb +++ b/app/services/merge_requests/create_service.rb @@ -49,6 +49,7 @@ module MergeRequests merge_request.update(head_pipeline_id: pipeline.id) if pipeline end + # rubocop: disable CodeReuse/ActiveRecord def head_pipeline_for(merge_request) return unless merge_request.source_project @@ -59,6 +60,7 @@ module MergeRequests pipelines.order(id: :desc).first end + # rubocop: enable CodeReuse/ActiveRecord def set_projects! # @project is used to determine whether the user can set the merge request's diff --git a/app/services/merge_requests/delete_non_latest_diffs_service.rb b/app/services/merge_requests/delete_non_latest_diffs_service.rb index 2a8ea316921..d5929446122 100644 --- a/app/services/merge_requests/delete_non_latest_diffs_service.rb +++ b/app/services/merge_requests/delete_non_latest_diffs_service.rb @@ -8,6 +8,7 @@ module MergeRequests @merge_request = merge_request end + # rubocop: disable CodeReuse/ActiveRecord def execute diffs = @merge_request.non_latest_diffs.with_files @@ -16,5 +17,6 @@ module MergeRequests DeleteDiffFilesWorker.bulk_perform_in(index * 5.minutes, ids) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index 48da796505f..bcdd752ddc4 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -51,6 +51,7 @@ module MergeRequests # and close if push to master include last commit from merge request # We need this to close(as merged) merge requests that were merged into # target branch manually + # rubocop: disable CodeReuse/ActiveRecord def post_merge_manually_merged commit_ids = @commits.map(&:id) merge_requests = @project.merge_requests.preload(:latest_merge_request_diff).opened.where(target_branch: @branch_name).to_a @@ -67,6 +68,7 @@ module MergeRequests .execute(merge_request) end end + # rubocop: enable CodeReuse/ActiveRecord def force_push? Gitlab::Checks::ForcePush.force_push?(@project, @oldrev, @newrev) @@ -74,6 +76,7 @@ module MergeRequests # Refresh merge request diff if we push to source or target branch of merge request # Note: we should update merge requests from forks too + # rubocop: disable CodeReuse/ActiveRecord def reload_merge_requests merge_requests = @project.merge_requests.opened .by_source_or_target_branch(@branch_name).to_a @@ -101,6 +104,7 @@ module MergeRequests # @source_merge_requests diffs (for MergeRequest#commit_shas for instance). merge_requests_for_source_branch(reload: true) end + # rubocop: enable CodeReuse/ActiveRecord def reset_merge_when_pipeline_succeeds merge_requests_for_source_branch.each(&:reset_merge_when_pipeline_succeeds) @@ -197,11 +201,13 @@ module MergeRequests # If the merge requests closes any issues, save this information in the # `MergeRequestsClosingIssues` model (as a performance optimization). + # rubocop: disable CodeReuse/ActiveRecord def cache_merge_requests_closing_issues @project.merge_requests.where(source_branch: @branch_name).each do |merge_request| merge_request.cache_merge_request_closes_issues!(@current_user) end end + # rubocop: enable CodeReuse/ActiveRecord def filter_merge_requests(merge_requests) merge_requests.uniq.select(&:source_project) diff --git a/app/services/merge_requests/reload_diffs_service.rb b/app/services/merge_requests/reload_diffs_service.rb index 1390ae0e199..c350b14d12b 100644 --- a/app/services/merge_requests/reload_diffs_service.rb +++ b/app/services/merge_requests/reload_diffs_service.rb @@ -27,6 +27,7 @@ module MergeRequests current_user: current_user) end + # rubocop: disable CodeReuse/ActiveRecord def clear_cache(new_diff) # Executing the iteration we cache highlighted diffs for each diff file of # MergeRequestDiff. @@ -41,5 +42,6 @@ module MergeRequests merge_request_diff.diffs_collection.clear_cache end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/milestones/promote_service.rb b/app/services/milestones/promote_service.rb index 660b4faaec0..39071b5dc14 100644 --- a/app/services/milestones/promote_service.rb +++ b/app/services/milestones/promote_service.rb @@ -26,6 +26,7 @@ module Milestones private + # rubocop: disable CodeReuse/ActiveRecord def milestone_ids_for_merge(group_milestone) # Pluck need to be used here instead of select so the array of ids # is persistent after old milestones gets deleted. @@ -35,6 +36,7 @@ module Milestones milestones.pluck(:id) end end + # rubocop: enable CodeReuse/ActiveRecord def move_children_to_group_milestone(group_milestone) milestone_ids_for_merge(group_milestone).in_groups_of(100, false) do |milestone_ids| @@ -59,6 +61,7 @@ module Milestones milestone end + # rubocop: disable CodeReuse/ActiveRecord def update_children(group_milestone, milestone_ids) issues = Issue.where(project_id: group_project_ids, milestone_id: milestone_ids) merge_requests = MergeRequest.where(source_project_id: group_project_ids, milestone_id: milestone_ids) @@ -67,18 +70,23 @@ module Milestones issuable_collection.update_all(milestone_id: group_milestone.id) end end + # rubocop: enable CodeReuse/ActiveRecord def group @group ||= parent.group || raise_error('Project does not belong to a group.') end + # rubocop: disable CodeReuse/ActiveRecord def destroy_old_milestones(milestone) Milestone.where(id: milestone_ids_for_merge(milestone)).destroy_all # rubocop: disable DestroyAll end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group_project_ids @group_project_ids ||= group.projects.pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord def raise_error(message) raise PromoteMilestoneError, "Promotion failed - #{message}" diff --git a/app/services/milestones/update_service.rb b/app/services/milestones/update_service.rb index 81b20943bab..01ab8b37bac 100644 --- a/app/services/milestones/update_service.rb +++ b/app/services/milestones/update_service.rb @@ -2,6 +2,7 @@ module Milestones class UpdateService < Milestones::BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(milestone) state = params[:state_event] @@ -18,5 +19,6 @@ module Milestones milestone end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/notification_recipient_service.rb b/app/services/notification_recipient_service.rb index 5c0e8a35cb0..9c236d7f41d 100644 --- a/app/services/notification_recipient_service.rb +++ b/app/services/notification_recipient_service.rb @@ -58,6 +58,7 @@ module NotificationRecipientService @recipients ||= [] end + # rubocop: disable CodeReuse/ActiveRecord def add_recipients(users, type, reason) if users.is_a?(ActiveRecord::Relation) users = users.includes(:notification_settings) @@ -66,10 +67,13 @@ module NotificationRecipientService users = Array(users).compact recipients.concat(users.map { |u| make_recipient(u, type, reason) }) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def user_scope User.includes(:notification_settings) end + # rubocop: enable CodeReuse/ActiveRecord def make_recipient(user, type, reason) NotificationRecipient.new( @@ -112,6 +116,7 @@ module NotificationRecipientService end # Get project/group users with CUSTOM notification level + # rubocop: disable CodeReuse/ActiveRecord def add_custom_notifications user_ids = [] @@ -128,6 +133,7 @@ module NotificationRecipientService add_recipients(user_scope.where(id: user_ids), :watch, nil) end + # rubocop: enable CodeReuse/ActiveRecord def add_project_watchers add_recipients(project_watchers, :watch, nil) if project @@ -138,6 +144,7 @@ module NotificationRecipientService end # Get project users with WATCH notification level + # rubocop: disable CodeReuse/ActiveRecord def project_watchers project_members_ids = user_ids_notifiable_on(project) @@ -151,7 +158,9 @@ module NotificationRecipientService user_scope.where(id: user_ids_with_project_setting.concat(user_ids_with_group_setting).uniq) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group_watchers user_ids_with_group_global = user_ids_notifiable_on(group, :global) user_ids = user_ids_with_global_level_watch(user_ids_with_group_global) @@ -159,6 +168,7 @@ module NotificationRecipientService user_scope.where(id: user_ids_with_group_setting) end + # rubocop: enable CodeReuse/ActiveRecord def add_subscribed_users return unless target.respond_to? :subscribers @@ -166,6 +176,7 @@ module NotificationRecipientService add_recipients(target.subscribers(project), :subscription, nil) end + # rubocop: disable CodeReuse/ActiveRecord def user_ids_notifiable_on(resource, notification_level = nil) return [] unless resource @@ -177,6 +188,7 @@ module NotificationRecipientService scope.pluck(:user_id) end + # rubocop: enable CodeReuse/ActiveRecord # Build a list of user_ids based on project notification settings def select_project_members_ids(global_setting, user_ids_global_level_watch) @@ -194,14 +206,19 @@ module NotificationRecipientService uids + (global_setting & user_ids_global_level_watch) - project_members end + # rubocop: disable CodeReuse/ActiveRecord def user_ids_with_global_level_watch(ids) settings_with_global_level_of(:watch, ids).pluck(:user_id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def user_ids_with_global_level_custom(ids, action) settings_with_global_level_of(:custom, ids).pluck(:user_id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def settings_with_global_level_of(level, ids) NotificationSetting.where( user_id: ids, @@ -209,6 +226,7 @@ module NotificationRecipientService level: NotificationSetting.levels[level] ) end + # rubocop: enable CodeReuse/ActiveRecord def add_labels_subscribers(labels: nil) return unless target.respond_to? :labels diff --git a/app/services/projects/auto_devops/disable_service.rb b/app/services/projects/auto_devops/disable_service.rb index 9745ab67dbd..1b578a3c5ce 100644 --- a/app/services/projects/auto_devops/disable_service.rb +++ b/app/services/projects/auto_devops/disable_service.rb @@ -21,10 +21,12 @@ module Projects # is an expensive operation. See # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21172#note_99037378 # for more context. + # rubocop: disable CodeReuse/ActiveRecord def first_pipeline_failure? auto_devops_pipelines.success.limit(1).count.zero? && auto_devops_pipelines.failed.limit(1).count.nonzero? end + # rubocop: enable CodeReuse/ActiveRecord def disable_auto_devops project.auto_devops_attributes = { enabled: false } diff --git a/app/services/projects/base_move_relations_service.rb b/app/services/projects/base_move_relations_service.rb index 78cc2869b72..24dec1f3a45 100644 --- a/app/services/projects/base_move_relations_service.rb +++ b/app/services/projects/base_move_relations_service.rb @@ -13,6 +13,7 @@ module Projects private + # rubocop: disable CodeReuse/ActiveRecord def prepare_relation(relation, id_param = :id) if Gitlab::Database.postgresql? relation @@ -20,5 +21,6 @@ module Projects relation.model.where("#{id_param}": relation.pluck(id_param)) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/batch_forks_count_service.rb b/app/services/projects/batch_forks_count_service.rb index 9bf369df999..6467744a435 100644 --- a/app/services/projects/batch_forks_count_service.rb +++ b/app/services/projects/batch_forks_count_service.rb @@ -5,6 +5,7 @@ # because the service use maps to retrieve the project ids module Projects class BatchForksCountService < Projects::BatchCountService + # rubocop: disable CodeReuse/ActiveRecord def global_count @global_count ||= begin count_service.query(project_ids) @@ -12,6 +13,7 @@ module Projects .count end end + # rubocop: enable CodeReuse/ActiveRecord def count_service ::Projects::ForksCountService diff --git a/app/services/projects/batch_open_issues_count_service.rb b/app/services/projects/batch_open_issues_count_service.rb index d375fcf9dbd..d6ff2291af8 100644 --- a/app/services/projects/batch_open_issues_count_service.rb +++ b/app/services/projects/batch_open_issues_count_service.rb @@ -5,11 +5,13 @@ # because the service use maps to retrieve the project ids module Projects class BatchOpenIssuesCountService < Projects::BatchCountService + # rubocop: disable CodeReuse/ActiveRecord def global_count @global_count ||= begin count_service.query(project_ids).group(:project_id).count end end + # rubocop: enable CodeReuse/ActiveRecord def count_service ::Projects::OpenIssuesCountService diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 02a3a3eb096..0e6a7e8da54 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -79,17 +79,21 @@ module Projects @project.errors.add(:namespace, "is not valid") end + # rubocop: disable CodeReuse/ActiveRecord def allowed_fork?(source_project_id) return true if source_project_id.nil? source_project = Project.find_by(id: source_project_id) current_user.can?(:fork_project, source_project) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def allowed_namespace?(user, namespace_id) namespace = Namespace.find_by(id: namespace_id) current_user.can?(:create_projects, namespace) end + # rubocop: enable CodeReuse/ActiveRecord def after_create_actions log_info("#{@project.owner.name} created a new project \"#{@project.full_name}\"") @@ -167,12 +171,14 @@ module Projects @project end + # rubocop: disable CodeReuse/ActiveRecord def create_services_from_active_templates(project) Service.where(template: true, active: true).each do |template| service = Service.build_from_template(project.id, template) service.save! end end + # rubocop: enable CodeReuse/ActiveRecord def set_project_name_from_path # Set project name from path diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb index 01de6afcd8e..5090ebf8f51 100644 --- a/app/services/projects/destroy_service.rb +++ b/app/services/projects/destroy_service.rb @@ -107,15 +107,19 @@ module Projects mv_repository(old_path, new_path) end + # rubocop: disable CodeReuse/ActiveRecord def repo_exists?(path) gitlab_shell.exists?(project.repository_storage, path + '.git') end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def mv_repository(from_path, to_path) return true unless gitlab_shell.exists?(project.repository_storage, from_path + '.git') gitlab_shell.mv_repository(project.repository_storage, from_path, to_path) end + # rubocop: enable CodeReuse/ActiveRecord def attempt_rollback(project, message) return unless project diff --git a/app/services/projects/detect_repository_languages_service.rb b/app/services/projects/detect_repository_languages_service.rb index 3488b9ce47e..4a837a4fb6a 100644 --- a/app/services/projects/detect_repository_languages_service.rb +++ b/app/services/projects/detect_repository_languages_service.rb @@ -4,6 +4,7 @@ module Projects class DetectRepositoryLanguagesService < BaseService attr_reader :detected_repository_languages, :programming_languages + # rubocop: disable CodeReuse/ActiveRecord def execute repository_languages = project.repository_languages detection = Gitlab::LanguageDetection.new(repository, repository_languages) @@ -28,9 +29,11 @@ module Projects project.repository_languages.reload end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def ensure_programming_languages(detection) existing_languages = ProgrammingLanguage.where(name: detection.languages) return existing_languages if detection.languages.size == existing_languages.size @@ -42,7 +45,9 @@ module Projects existing_languages + created_languages end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def create_language(name, color) ProgrammingLanguage.transaction do ProgrammingLanguage.where(name: name).first_or_create(color: color) @@ -50,5 +55,6 @@ module Projects rescue ActiveRecord::RecordNotUnique retry end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/enable_deploy_key_service.rb b/app/services/projects/enable_deploy_key_service.rb index b7c172028e9..102088e9557 100644 --- a/app/services/projects/enable_deploy_key_service.rb +++ b/app/services/projects/enable_deploy_key_service.rb @@ -2,6 +2,7 @@ module Projects class EnableDeployKeyService < BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute key = accessible_keys.find_by(id: params[:key_id] || params[:id]) return unless key @@ -12,6 +13,7 @@ module Projects key end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/services/projects/forks_count_service.rb b/app/services/projects/forks_count_service.rb index b570c6d4754..00e73148358 100644 --- a/app/services/projects/forks_count_service.rb +++ b/app/services/projects/forks_count_service.rb @@ -7,11 +7,13 @@ module Projects 'forks_count' end + # rubocop: disable CodeReuse/ActiveRecord def self.query(project_ids) # We can't directly change ForkedProjectLink to ForkNetworkMember here # Nowadays, when a call using v3 to projects/:id/fork is made, # the relationship to ForkNetworkMember is not updated ForkedProjectLink.where(forked_from_project: project_ids) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/gitlab_projects_import_service.rb b/app/services/projects/gitlab_projects_import_service.rb index 044afa1d5e1..a315adf42f0 100644 --- a/app/services/projects/gitlab_projects_import_service.rb +++ b/app/services/projects/gitlab_projects_import_service.rb @@ -32,11 +32,13 @@ module Projects Project.find_by_full_path("#{current_namespace.full_path}/#{params[:path]}").present? end + # rubocop: disable CodeReuse/ActiveRecord def current_namespace strong_memoize(:current_namespace) do Namespace.find_by(id: params[:namespace_id]) end end + # rubocop: enable CodeReuse/ActiveRecord def overwrite? strong_memoize(:overwrite) do diff --git a/app/services/projects/hashed_storage/migrate_repository_service.rb b/app/services/projects/hashed_storage/migrate_repository_service.rb index 641d46e6591..4462d504071 100644 --- a/app/services/projects/hashed_storage/migrate_repository_service.rb +++ b/app/services/projects/hashed_storage/migrate_repository_service.rb @@ -47,10 +47,13 @@ module Projects private + # rubocop: disable CodeReuse/ActiveRecord def has_wiki? gitlab_shell.exists?(project.repository_storage, "#{old_wiki_disk_path}.git") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def move_repository(from_name, to_name) from_exists = gitlab_shell.exists?(project.repository_storage, "#{from_name}.git") to_exists = gitlab_shell.exists?(project.repository_storage, "#{to_name}.git") @@ -67,6 +70,7 @@ module Projects gitlab_shell.mv_repository(project.repository_storage, from_name, to_name) end + # rubocop: enable CodeReuse/ActiveRecord def rollback_folder_move move_repository(new_disk_path, old_disk_path) diff --git a/app/services/projects/lfs_pointers/lfs_download_service.rb b/app/services/projects/lfs_pointers/lfs_download_service.rb index 7d4fa4e08df..1c4a8d05be6 100644 --- a/app/services/projects/lfs_pointers/lfs_download_service.rb +++ b/app/services/projects/lfs_pointers/lfs_download_service.rb @@ -4,6 +4,7 @@ module Projects module LfsPointers class LfsDownloadService < BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(oid, url) return unless project&.lfs_enabled? && oid.present? && url.present? @@ -20,6 +21,7 @@ module Projects rescue StandardError => e Rails.logger.error("LFS file with oid #{oid} could't be downloaded from #{sanitized_uri.sanitized_url}: #{e.message}") end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/services/projects/lfs_pointers/lfs_import_service.rb b/app/services/projects/lfs_pointers/lfs_import_service.rb index 97ce681a911..9215fa0a7bf 100644 --- a/app/services/projects/lfs_pointers/lfs_import_service.rb +++ b/app/services/projects/lfs_pointers/lfs_import_service.rb @@ -41,6 +41,7 @@ module Projects project.update(lfs_enabled: false) end + # rubocop: disable CodeReuse/ActiveRecord def get_download_links existent_lfs = LfsListService.new(project).execute linked_oids = LfsLinkService.new(project).execute(existent_lfs.keys) @@ -50,6 +51,7 @@ module Projects LfsDownloadLinkListService.new(project, remote_uri: current_endpoint_uri).execute(not_linked_lfs) end + # rubocop: enable CodeReuse/ActiveRecord def lfsconfig_endpoint_uri strong_memoize(:lfsconfig_endpoint_uri) do diff --git a/app/services/projects/lfs_pointers/lfs_link_service.rb b/app/services/projects/lfs_pointers/lfs_link_service.rb index a2eba8e124e..8401f3d1d89 100644 --- a/app/services/projects/lfs_pointers/lfs_link_service.rb +++ b/app/services/projects/lfs_pointers/lfs_link_service.rb @@ -16,6 +16,7 @@ module Projects private + # rubocop: disable CodeReuse/ActiveRecord def link_existing_lfs_objects(oids) existent_lfs_objects = LfsObject.where(oid: oids) @@ -26,6 +27,7 @@ module Projects existent_lfs_objects.pluck(:oid) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/projects/move_deploy_keys_projects_service.rb b/app/services/projects/move_deploy_keys_projects_service.rb index 9f3f44f30ea..b6a3af8c7b8 100644 --- a/app/services/projects/move_deploy_keys_projects_service.rb +++ b/app/services/projects/move_deploy_keys_projects_service.rb @@ -20,11 +20,13 @@ module Projects .update_all(project_id: @project.id) end + # rubocop: disable CodeReuse/ActiveRecord def non_existent_deploy_keys_projects source_project.deploy_keys_projects .joins(:deploy_key) .where.not(keys: { fingerprint: @project.deploy_keys.select(:fingerprint) }) end + # rubocop: enable CodeReuse/ActiveRecord def remove_remaining_deploy_keys_projects source_project.deploy_keys_projects.destroy_all # rubocop: disable DestroyAll diff --git a/app/services/projects/move_forks_service.rb b/app/services/projects/move_forks_service.rb index 076a7a50aa9..2948555a17c 100644 --- a/app/services/projects/move_forks_service.rb +++ b/app/services/projects/move_forks_service.rb @@ -17,6 +17,7 @@ module Projects private + # rubocop: disable CodeReuse/ActiveRecord def move_forked_project_links # Update ancestor ForkedProjectLink.where(forked_to_project: source_project) @@ -26,16 +27,21 @@ module Projects ForkedProjectLink.where(forked_from_project: source_project) .update_all(forked_from_project_id: @project.id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def move_fork_network_members ForkNetworkMember.where(project: source_project).update_all(project_id: @project.id) ForkNetworkMember.where(forked_from_project: source_project).update_all(forked_from_project_id: @project.id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_root_project # Update root network project ForkNetwork.where(root_project: source_project).update_all(root_project_id: @project.id) end + # rubocop: enable CodeReuse/ActiveRecord def refresh_forks_count Projects::ForksCountService.new(@project).refresh_cache diff --git a/app/services/projects/move_lfs_objects_projects_service.rb b/app/services/projects/move_lfs_objects_projects_service.rb index f78546a1e9c..308a54ad06e 100644 --- a/app/services/projects/move_lfs_objects_projects_service.rb +++ b/app/services/projects/move_lfs_objects_projects_service.rb @@ -24,8 +24,10 @@ module Projects source_project.lfs_objects_projects.destroy_all # rubocop: disable DestroyAll end + # rubocop: disable CodeReuse/ActiveRecord def non_existent_lfs_objects_projects source_project.lfs_objects_projects.where.not(lfs_object: @project.lfs_objects) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/move_notification_settings_service.rb b/app/services/projects/move_notification_settings_service.rb index 109a00dd6d9..e740c44bd26 100644 --- a/app/services/projects/move_notification_settings_service.rb +++ b/app/services/projects/move_notification_settings_service.rb @@ -31,10 +31,12 @@ module Projects end # Look for notification_settings in source_project that are not in the target project + # rubocop: disable CodeReuse/ActiveRecord def non_existent_notifications source_project.notification_settings .select(:id) .where.not(user_id: users_in_target_project) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/move_project_authorizations_service.rb b/app/services/projects/move_project_authorizations_service.rb index 60f2af88e99..2060a263751 100644 --- a/app/services/projects/move_project_authorizations_service.rb +++ b/app/services/projects/move_project_authorizations_service.rb @@ -33,10 +33,12 @@ module Projects end # Look for authorizations in source_project that are not in the target project + # rubocop: disable CodeReuse/ActiveRecord def non_existent_authorization source_project.project_authorizations .select(:user_id) .where.not(user: @project.authorized_users) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/move_project_group_links_service.rb b/app/services/projects/move_project_group_links_service.rb index 1efafdce36d..fb395ecb9a1 100644 --- a/app/services/projects/move_project_group_links_service.rb +++ b/app/services/projects/move_project_group_links_service.rb @@ -34,9 +34,11 @@ module Projects end # Look for groups in source_project that are not in the target project + # rubocop: disable CodeReuse/ActiveRecord def non_existent_group_links source_project.project_group_links .where.not(group_id: group_links_in_target_project) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/move_project_members_service.rb b/app/services/projects/move_project_members_service.rb index ec983582d94..f28f44adc03 100644 --- a/app/services/projects/move_project_members_service.rb +++ b/app/services/projects/move_project_members_service.rb @@ -33,10 +33,12 @@ module Projects end # Look for members in source_project that are not in the target project + # rubocop: disable CodeReuse/ActiveRecord def non_existent_members source_project.members .select(:id) .where.not(user_id: @project.project_members.select(:user_id)) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/open_issues_count_service.rb b/app/services/projects/open_issues_count_service.rb index 5d6620c3c54..ee9884e9042 100644 --- a/app/services/projects/open_issues_count_service.rb +++ b/app/services/projects/open_issues_count_service.rb @@ -42,6 +42,7 @@ module Projects cache_key(TOTAL_COUNT_KEY) end + # rubocop: disable CodeReuse/ActiveRecord def refresh_cache(&block) if block_given? super(&block) @@ -59,11 +60,13 @@ module Projects end end end + # rubocop: enable CodeReuse/ActiveRecord # We only show total issues count for reporters # which are allowed to view confidential issues # This will still show a discrepancy on issues number but should be less than before. # Check https://gitlab.com/gitlab-org/gitlab-ce/issues/38418 description. + # rubocop: disable CodeReuse/ActiveRecord def self.query(projects, public_only: true) if public_only Issue.opened.public_only.where(project: projects) @@ -71,5 +74,6 @@ module Projects Issue.opened.where(project: projects) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/projects/propagate_service_template.rb b/app/services/projects/propagate_service_template.rb index fdfa91801ab..633a263af7b 100644 --- a/app/services/projects/propagate_service_template.rb +++ b/app/services/projects/propagate_service_template.rb @@ -70,6 +70,7 @@ module Projects ) end + # rubocop: disable CodeReuse/ActiveRecord def service_hash @service_hash ||= begin @@ -83,7 +84,9 @@ module Projects end end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def run_callbacks(batch) if active_external_issue_tracker? Project.where(id: batch).update_all(has_external_issue_tracker: true) @@ -93,6 +96,7 @@ module Projects Project.where(id: batch).update_all(has_external_wiki: true) end end + # rubocop: enable CodeReuse/ActiveRecord def active_external_issue_tracker? @template.issue_tracker? && !@template.default diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 3746cfef702..9d40ab166ff 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -37,6 +37,7 @@ module Projects private + # rubocop: disable CodeReuse/ActiveRecord def transfer(project) @old_path = project.full_path @old_group = project.group @@ -54,6 +55,7 @@ module Projects attempt_transfer_transaction end + # rubocop: enable CodeReuse/ActiveRecord def attempt_transfer_transaction Project.transaction do diff --git a/app/services/projects/unlink_fork_service.rb b/app/services/projects/unlink_fork_service.rb index 2c0d91fe34f..a8b7c7f136a 100644 --- a/app/services/projects/unlink_fork_service.rb +++ b/app/services/projects/unlink_fork_service.rb @@ -2,6 +2,7 @@ module Projects class UnlinkForkService < BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute return unless @project.forked? @@ -26,6 +27,7 @@ module Projects @project.fork_network_member.destroy @project.forked_project_link.destroy end + # rubocop: enable CodeReuse/ActiveRecord def refresh_forks_count(project) Projects::ForksCountService.new(project).refresh_cache diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb index e390d7a04c3..d6d9bacf232 100644 --- a/app/services/projects/update_service.rb +++ b/app/services/projects/update_service.rb @@ -6,6 +6,7 @@ module Projects ValidationError = Class.new(StandardError) + # rubocop: disable CodeReuse/ActiveRecord def execute validate! @@ -26,6 +27,7 @@ module Projects rescue ValidationError => e error(e.message) end + # rubocop: enable CodeReuse/ActiveRecord def run_auto_devops_pipeline? return false if project.repository.gitlab_ci_yml || !project.auto_devops&.previous_changes&.include?('enabled') diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index be9d1e48435..02d68c3add3 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -111,10 +111,12 @@ module QuickActions end desc 'Assign' + # rubocop: disable CodeReuse/ActiveRecord explanation do |users| users = issuable.allows_multiple_assignees? ? users : users.take(1) "Assigns #{users.map(&:to_reference).to_sentence}." end + # rubocop: enable CodeReuse/ActiveRecord params do issuable.allows_multiple_assignees? ? '@user1 @user2' : '@user' end @@ -124,6 +126,7 @@ module QuickActions parse_params do |assignee_param| extract_users(assignee_param) end + # rubocop: disable CodeReuse/ActiveRecord command :assign do |users| next if users.empty? @@ -134,6 +137,7 @@ module QuickActions [users.first.id] end end + # rubocop: enable CodeReuse/ActiveRecord desc do if issuable.allows_multiple_assignees? @@ -160,6 +164,7 @@ module QuickActions # When multiple users are assigned, all will be unassigned if multiple assignees are no longer allowed extract_users(unassign_param) if issuable.allows_multiple_assignees? end + # rubocop: disable CodeReuse/ActiveRecord command :unassign do |users = nil| @updates[:assignee_ids] = if users&.any? @@ -168,6 +173,7 @@ module QuickActions [] end end + # rubocop: enable CodeReuse/ActiveRecord desc 'Set milestone' explanation do |milestone| @@ -546,6 +552,7 @@ module QuickActions current_user.can?(:"update_#{issuable.to_ability_name}", issuable) && issuable.project.boards.count == 1 end + # rubocop: disable CodeReuse/ActiveRecord command :board_move do |target_list_name| label_ids = find_label_ids(target_list_name) @@ -560,6 +567,7 @@ module QuickActions @updates[:add_label_ids] = [label_id] end end + # rubocop: enable CodeReuse/ActiveRecord desc 'Mark this issue as a duplicate of another issue' explanation do |duplicate_reference| @@ -625,6 +633,7 @@ module QuickActions @updates[:tag_message] = message end + # rubocop: disable CodeReuse/ActiveRecord def extract_users(params) return [] if params.nil? @@ -641,6 +650,7 @@ module QuickActions users end + # rubocop: enable CodeReuse/ActiveRecord def find_milestones(project, params = {}) MilestonesFinder.new(params.merge(project_ids: [project.id], group_ids: [project.group&.id])).execute @@ -677,6 +687,7 @@ module QuickActions end end + # rubocop: disable CodeReuse/ActiveRecord def extract_references(arg, type) ext = Gitlab::ReferenceExtractor.new(project, current_user) @@ -684,5 +695,6 @@ module QuickActions ext.references(type) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/quick_actions/target_service.rb b/app/services/quick_actions/target_service.rb index d8ba52c6e50..69464c3c1ae 100644 --- a/app/services/quick_actions/target_service.rb +++ b/app/services/quick_actions/target_service.rb @@ -15,13 +15,17 @@ module QuickActions private + # rubocop: disable CodeReuse/ActiveRecord def issue(type_id) IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def merge_request(type_id) MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build end + # rubocop: enable CodeReuse/ActiveRecord def commit(type_id) project.commit(type_id) diff --git a/app/services/resource_events/merge_into_notes_service.rb b/app/services/resource_events/merge_into_notes_service.rb index 1b02a1602e2..596c0105ea0 100644 --- a/app/services/resource_events/merge_into_notes_service.rb +++ b/app/services/resource_events/merge_into_notes_service.rb @@ -30,6 +30,7 @@ module ResourceEvents end end + # rubocop: disable CodeReuse/ActiveRecord def label_events_by_discussion_id return [] unless resource.respond_to?(:resource_label_events) @@ -38,6 +39,7 @@ module ResourceEvents events.group_by { |event| event.discussion_id } end + # rubocop: enable CodeReuse/ActiveRecord def since_fetch_at(events) return events unless params[:last_fetched_at].present? diff --git a/app/services/search/group_service.rb b/app/services/search/group_service.rb index 34803d005e3..00372887985 100644 --- a/app/services/search/group_service.rb +++ b/app/services/search/group_service.rb @@ -11,11 +11,13 @@ module Search @group = group end + # rubocop: disable CodeReuse/ActiveRecord def projects return Project.none unless group return @projects if defined? @projects @projects = super.inside_path(group.full_path) end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 1b707d79b43..e0cbfac2420 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -8,6 +8,7 @@ class SearchService @params = params.dup end + # rubocop: disable CodeReuse/ActiveRecord def project return @project if defined?(@project) @@ -19,7 +20,9 @@ class SearchService nil end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def group return @group if defined?(@group) @@ -31,6 +34,7 @@ class SearchService nil end end + # rubocop: enable CodeReuse/ActiveRecord def show_snippets? return @show_snippets if defined?(@show_snippets) diff --git a/app/services/spam_check_service.rb b/app/services/spam_check_service.rb index 895261925ba..51d300d4f1d 100644 --- a/app/services/spam_check_service.rb +++ b/app/services/spam_check_service.rb @@ -22,6 +22,7 @@ module SpamCheckService # a dirty instance, which means it should be already assigned with the new # attribute values. # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def spam_check(spammable, user) spam_service = SpamService.new(spammable, @request) @@ -29,5 +30,6 @@ module SpamCheckService user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true) end end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables end diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index c5d05992575..575678da1fa 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -580,6 +580,7 @@ module SystemNoteService private + # rubocop: disable CodeReuse/ActiveRecord def notes_for_mentioner(mentioner, noteable, notes) if mentioner.is_a?(Commit) text = "#{cross_reference_note_prefix}%#{mentioner.to_reference(nil)}" @@ -590,6 +591,7 @@ module SystemNoteService notes.where(note: [text, text.capitalize]) end end + # rubocop: enable CodeReuse/ActiveRecord def create_note(note_summary) note = Note.create(note_summary.note.merge(system: true)) diff --git a/app/services/tags/destroy_service.rb b/app/services/tags/destroy_service.rb index 800268485a4..6bfef09ac54 100644 --- a/app/services/tags/destroy_service.rb +++ b/app/services/tags/destroy_service.rb @@ -2,6 +2,7 @@ module Tags class DestroyService < BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(tag_name) repository = project.repository tag = repository.find_tag(tag_name) @@ -26,6 +27,7 @@ module Tags rescue Gitlab::Git::PreReceiveError => ex error(ex.message) end + # rubocop: enable CodeReuse/ActiveRecord def error(message, return_code = 400) super(message).merge(return_code: return_code) diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index 0df61ad3bce..4fe6c1ec986 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -41,6 +41,7 @@ class TodoService # collects the todo users before the todos themselves are deleted, then # updates the todo counts for those users. # + # rubocop: disable CodeReuse/ActiveRecord def destroy_target(target) todo_users = User.where(id: target.todos.pending.select(:user_id)).to_a @@ -48,6 +49,7 @@ class TodoService todo_users.each(&:update_todos_count_cache) end + # rubocop: enable CodeReuse/ActiveRecord # When we reassign an issue we should: # @@ -198,16 +200,21 @@ class TodoService create_todos(current_user, attributes) end + # rubocop: disable CodeReuse/ActiveRecord def todo_exist?(issuable, current_user) TodosFinder.new(current_user).execute.exists?(target: issuable) end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def todos_by_ids(ids, current_user) current_user.todos.where(id: Array(ids)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def update_todos_state(todos, current_user, state) # Only update those that are not really on that state todos = todos.where.not(state: state) @@ -216,6 +223,7 @@ class TodoService current_user.update_todos_count_cache todos_ids end + # rubocop: enable CodeReuse/ActiveRecord def create_todos(users, attributes) Array(users).map do |user| @@ -340,8 +348,10 @@ class TodoService end end + # rubocop: disable CodeReuse/ActiveRecord def pending_todos(user, criteria = {}) valid_keys = [:project_id, :target_id, :target_type, :commit_id] user.todos.pending.where(criteria.slice(*valid_keys)) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/services/todos/destroy/base_service.rb b/app/services/todos/destroy/base_service.rb index aeb60e50c64..f3f1dbb5698 100644 --- a/app/services/todos/destroy/base_service.rb +++ b/app/services/todos/destroy/base_service.rb @@ -11,13 +11,17 @@ module Todos private + # rubocop: disable CodeReuse/ActiveRecord def without_authorized(items) items.where('user_id NOT IN (?)', authorized_users) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def authorized_users ProjectAuthorization.select(:user_id).where(project_id: project_ids) end + # rubocop: enable CodeReuse/ActiveRecord def todos raise NotImplementedError diff --git a/app/services/todos/destroy/confidential_issue_service.rb b/app/services/todos/destroy/confidential_issue_service.rb index efec0f22da5..6276e332448 100644 --- a/app/services/todos/destroy/confidential_issue_service.rb +++ b/app/services/todos/destroy/confidential_issue_service.rb @@ -7,18 +7,22 @@ module Todos attr_reader :issue + # rubocop: disable CodeReuse/ActiveRecord def initialize(issue_id) @issue = Issue.find_by(id: issue_id) end + # rubocop: enable CodeReuse/ActiveRecord private override :todos + # rubocop: disable CodeReuse/ActiveRecord def todos Todo.where(target: issue) .where('user_id != ?', issue.author_id) .where('user_id NOT IN (?)', issue.assignees.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord override :todos_to_remove? def todos_to_remove? @@ -31,11 +35,13 @@ module Todos end override :authorized_users + # rubocop: disable CodeReuse/ActiveRecord def authorized_users ProjectAuthorization.select(:user_id) .where(project_id: project_ids) .where('access_level >= ?', Gitlab::Access::REPORTER) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/entity_leave_service.rb b/app/services/todos/destroy/entity_leave_service.rb index 4cb9d08713d..e8d1bcdd142 100644 --- a/app/services/todos/destroy/entity_leave_service.rb +++ b/app/services/todos/destroy/entity_leave_service.rb @@ -7,6 +7,7 @@ module Todos attr_reader :user, :entity + # rubocop: disable CodeReuse/ActiveRecord def initialize(user_id, entity_id, entity_type) unless %w(Group Project).include?(entity_type) raise ArgumentError.new("#{entity_type} is not an entity user can leave") @@ -15,6 +16,7 @@ module Todos @user = User.find_by(id: user_id) @entity = entity_type.constantize.find_by(id: entity_id) end + # rubocop: enable CodeReuse/ActiveRecord def execute return unless entity && user @@ -40,21 +42,28 @@ module Todos end end + # rubocop: disable CodeReuse/ActiveRecord def remove_confidential_issue_todos Todo.where( target_id: confidential_issues.select(:id), target_type: Issue, user_id: user.id ).delete_all end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def remove_project_todos Todo.where(project_id: non_authorized_projects, user_id: user.id).delete_all end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def remove_group_todos Todo.where(group_id: non_authorized_groups, user_id: user.id).delete_all end + # rubocop: enable CodeReuse/ActiveRecord override :project_ids + # rubocop: disable CodeReuse/ActiveRecord def project_ids condition = case entity when Project @@ -65,22 +74,29 @@ module Todos Project.where(condition).select(:id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def non_authorized_projects project_ids.where('id NOT IN (?)', user.authorized_projects.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def non_authorized_groups return [] unless entity.is_a?(Namespace) entity.self_and_descendants.select(:id) .where('id NOT IN (?)', GroupsFinder.new(user).execute.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def non_member_groups entity.self_and_descendants.select(:id) .where('id NOT IN (?)', user.membership_groups.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord def user_has_reporter_access? return unless entity.is_a?(Namespace) @@ -88,6 +104,7 @@ module Todos entity.member?(User.find(user.id), Gitlab::Access::REPORTER) end + # rubocop: disable CodeReuse/ActiveRecord def confidential_issues assigned_ids = IssueAssignee.select(:issue_id).where(user_id: user.id) authorized_reporter_projects = user @@ -98,6 +115,7 @@ module Todos .where('author_id != ?', user.id) .where('id NOT IN (?)', assigned_ids) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/group_private_service.rb b/app/services/todos/destroy/group_private_service.rb index f67f1d40597..d7ecbb952aa 100644 --- a/app/services/todos/destroy/group_private_service.rb +++ b/app/services/todos/destroy/group_private_service.rb @@ -7,16 +7,20 @@ module Todos attr_reader :group + # rubocop: disable CodeReuse/ActiveRecord def initialize(group_id) @group = Group.find_by(id: group_id) end + # rubocop: enable CodeReuse/ActiveRecord private override :todos + # rubocop: disable CodeReuse/ActiveRecord def todos Todo.where(group_id: group.id) end + # rubocop: enable CodeReuse/ActiveRecord override :authorized_users def authorized_users diff --git a/app/services/todos/destroy/private_features_service.rb b/app/services/todos/destroy/private_features_service.rb index 7e204885b31..a8c3fe0ef5a 100644 --- a/app/services/todos/destroy/private_features_service.rb +++ b/app/services/todos/destroy/private_features_service.rb @@ -10,6 +10,7 @@ module Todos @user_id = user_id end + # rubocop: disable CodeReuse/ActiveRecord def execute ProjectFeature.where(project_id: project_ids).each do |project_features| target_types = [] @@ -22,6 +23,7 @@ module Todos remove_todos(project_features.project_id, target_types) end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -29,6 +31,7 @@ module Todos feature_level == ProjectFeature::PRIVATE end + # rubocop: disable CodeReuse/ActiveRecord def remove_todos(project_id, target_types) items = Todo.where(project_id: project_id) items = items.where(user_id: user_id) if user_id @@ -37,6 +40,7 @@ module Todos .where(target_type: target_types) .delete_all end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/project_private_service.rb b/app/services/todos/destroy/project_private_service.rb index ae8fab3ffca..e00d10c3780 100644 --- a/app/services/todos/destroy/project_private_service.rb +++ b/app/services/todos/destroy/project_private_service.rb @@ -7,16 +7,20 @@ module Todos attr_reader :project + # rubocop: disable CodeReuse/ActiveRecord def initialize(project_id) @project = Project.find_by(id: project_id) end + # rubocop: enable CodeReuse/ActiveRecord private override :todos + # rubocop: disable CodeReuse/ActiveRecord def todos Todo.where(project_id: project.id) end + # rubocop: enable CodeReuse/ActiveRecord override :project_ids def project_ids diff --git a/app/services/update_release_service.rb b/app/services/update_release_service.rb index 422ba668e35..e2228ca026c 100644 --- a/app/services/update_release_service.rb +++ b/app/services/update_release_service.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class UpdateReleaseService < BaseService + # rubocop: disable CodeReuse/ActiveRecord def execute(tag_name, release_description) repository = project.repository existing_tag = repository.find_tag(tag_name) @@ -19,6 +20,7 @@ class UpdateReleaseService < BaseService error('Tag does not exist', 404) end end + # rubocop: enable CodeReuse/ActiveRecord def success(release) super().merge(release: release) diff --git a/app/services/users/last_push_event_service.rb b/app/services/users/last_push_event_service.rb index a9c9497520b..b3980b8e32c 100644 --- a/app/services/users/last_push_event_service.rb +++ b/app/services/users/last_push_event_service.rb @@ -58,11 +58,13 @@ module Users private + # rubocop: disable CodeReuse/ActiveRecord def find_event_in_database(id) PushEvent .without_existing_merge_requests .find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord def user_cache_key "last-push-event/#{@user.id}" diff --git a/app/services/users/migrate_to_ghost_user_service.rb b/app/services/users/migrate_to_ghost_user_service.rb index 4d47078bf43..04fd6e37501 100644 --- a/app/services/users/migrate_to_ghost_user_service.rb +++ b/app/services/users/migrate_to_ghost_user_service.rb @@ -54,15 +54,19 @@ module Users migrate_award_emoji end + # rubocop: disable CodeReuse/ActiveRecord def migrate_issues user.issues.update_all(author_id: ghost_user.id) Issue.where(last_edited_by_id: user.id).update_all(last_edited_by_id: ghost_user.id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def migrate_merge_requests user.merge_requests.update_all(author_id: ghost_user.id) MergeRequest.where(merge_user_id: user.id).update_all(merge_user_id: ghost_user.id) end + # rubocop: enable CodeReuse/ActiveRecord def migrate_notes user.notes.update_all(author_id: ghost_user.id) diff --git a/app/services/users/respond_to_terms_service.rb b/app/services/users/respond_to_terms_service.rb index 9efa3b285a8..254480304f9 100644 --- a/app/services/users/respond_to_terms_service.rb +++ b/app/services/users/respond_to_terms_service.rb @@ -6,6 +6,7 @@ module Users @user, @term = user, term end + # rubocop: disable CodeReuse/ActiveRecord def execute(accepted:) agreement = @user.term_agreements.find_or_initialize_by(term: @term) agreement.accepted = accepted @@ -16,6 +17,7 @@ module Users agreement end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/uploaders/records_uploads.rb b/app/uploaders/records_uploads.rb index 5795065ae11..0efca895a50 100644 --- a/app/uploaders/records_uploads.rb +++ b/app/uploaders/records_uploads.rb @@ -18,6 +18,7 @@ module RecordsUploads # `Tempfile` object the callback gets. # # Called `after :store` + # rubocop: disable CodeReuse/ActiveRecord def record_upload(_tempfile = nil) return unless model return unless file && file.exists? @@ -29,6 +30,7 @@ module RecordsUploads self.upload = build_upload.tap(&:save!) end end + # rubocop: enable CodeReuse/ActiveRecord def upload_path File.join(store_dir, filename.to_s) @@ -36,9 +38,11 @@ module RecordsUploads private + # rubocop: disable CodeReuse/ActiveRecord def uploads Upload.order(id: :desc).where(uploader: self.class.to_s) end + # rubocop: enable CodeReuse/ActiveRecord def build_upload Upload.new( @@ -53,11 +57,13 @@ module RecordsUploads # Before removing an attachment, destroy any Upload records at the same path # # Called `before :remove` + # rubocop: disable CodeReuse/ActiveRecord def destroy_upload(*args) return unless file && file.exists? self.upload = nil uploads.where(path: upload_path).delete_all end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/validators/variable_duplicates_validator.rb b/app/validators/variable_duplicates_validator.rb index 90193e85f2a..d36a56e81b9 100644 --- a/app/validators/variable_duplicates_validator.rb +++ b/app/validators/variable_duplicates_validator.rb @@ -21,6 +21,7 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator private + # rubocop: disable CodeReuse/ActiveRecord def validate_duplicates(record, attribute, values) duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first) if duplicates.any? @@ -29,4 +30,5 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator record.errors.add(attribute, error_message) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/views/admin/users/projects.html.haml b/app/views/admin/users/projects.html.haml index 3d39c1da408..e6da81831ab 100644 --- a/app/views/admin/users/projects.html.haml +++ b/app/views/admin/users/projects.html.haml @@ -7,7 +7,7 @@ .card .card-header Group projects %ul.hover-list - - @user.group_members.includes(:source).each do |group_member| + - @user.group_members.includes(:source).each do |group_member| # rubocop: disable CodeReuse/ActiveRecord - group = group_member.group %li.group_member %strong= link_to group.name, admin_group_path(group) diff --git a/app/views/dashboard/issues.atom.builder b/app/views/dashboard/issues.atom.builder index d7b6fb9a4a1..6034389b897 100644 --- a/app/views/dashboard/issues.atom.builder +++ b/app/views/dashboard/issues.atom.builder @@ -1,3 +1,4 @@ +# rubocop: disable CodeReuse/ActiveRecord xml.title "#{current_user.name} issues" xml.link href: url_for(safe_params), rel: "self", type: "application/atom+xml" xml.link href: issues_dashboard_url, rel: "alternate", type: "text/html" @@ -5,3 +6,4 @@ xml.id issues_dashboard_url xml.updated @issues.first.updated_at.xmlschema if @issues.reorder(nil).any? xml << render(partial: 'issues/issue', collection: @issues) if @issues.reorder(nil).any? +# rubocop: enable CodeReuse/ActiveRecord diff --git a/app/views/doorkeeper/applications/index.html.haml b/app/views/doorkeeper/applications/index.html.haml index ab3a1b100ce..b11f441b3ba 100644 --- a/app/views/doorkeeper/applications/index.html.haml +++ b/app/views/doorkeeper/applications/index.html.haml @@ -62,7 +62,7 @@ %th %tbody - @authorized_apps.each do |app| - - token = app.authorized_tokens.order('created_at desc').first + - token = app.authorized_tokens.order('created_at desc').first # rubocop: disable CodeReuse/ActiveRecord %tr{ id: "application_#{app.id}" } %td= app.name %td= token.created_at diff --git a/app/views/groups/issues.atom.builder b/app/views/groups/issues.atom.builder index 2a385b661e5..2fd96c9d158 100644 --- a/app/views/groups/issues.atom.builder +++ b/app/views/groups/issues.atom.builder @@ -1,3 +1,4 @@ +# rubocop: disable CodeReuse/ActiveRecord xml.title "#{@group.name} issues" xml.link href: url_for(safe_params), rel: "self", type: "application/atom+xml" xml.link href: issues_group_url, rel: "alternate", type: "text/html" @@ -5,3 +6,4 @@ xml.id issues_group_url xml.updated @issues.first.updated_at.xmlschema if @issues.reorder(nil).any? xml << render(partial: 'issues/issue', collection: @issues) if @issues.reorder(nil).any? +# rubocop: enable CodeReuse/ActiveRecord diff --git a/app/views/issues/_issues_calendar.ics.ruby b/app/views/issues/_issues_calendar.ics.ruby index 3563635d33d..73ab8489e0c 100644 --- a/app/views/issues/_issues_calendar.ics.ruby +++ b/app/views/issues/_issues_calendar.ics.ruby @@ -2,6 +2,7 @@ cal = Icalendar::Calendar.new cal.prodid = '-//GitLab//NONSGML GitLab//EN' cal.x_wr_calname = 'GitLab Issues' +# rubocop: disable CodeReuse/ActiveRecord @issues.includes(project: :namespace).each do |issue| cal.event do |event| event.dtstart = Icalendar::Values::Date.new(issue.due_date) @@ -11,5 +12,6 @@ cal.x_wr_calname = 'GitLab Issues' event.transp = 'TRANSPARENT' end end +# rubocop: enable CodeReuse/ActiveRecord cal.to_ical diff --git a/app/views/projects/diffs/_stats.html.haml b/app/views/projects/diffs/_stats.html.haml index aa1112c3313..229a4574eeb 100644 --- a/app/views/projects/diffs/_stats.html.haml +++ b/app/views/projects/diffs/_stats.html.haml @@ -1,5 +1,5 @@ -- sum_added_lines = diff_files.sum(&:added_lines) -- sum_removed_lines = diff_files.sum(&:removed_lines) +- sum_added_lines = diff_files.sum(&:added_lines) # rubocop: disable CodeReuse/ActiveRecord +- sum_removed_lines = diff_files.sum(&:removed_lines) # rubocop: disable CodeReuse/ActiveRecord .commit-stat-summary.dropdown Showing %button.diff-stats-summary-toggler.js-diff-stats-dropdown{ type: "button", data: { toggle: "dropdown", display: "static" } }< diff --git a/app/views/projects/issues/index.atom.builder b/app/views/projects/issues/index.atom.builder index 6330245954e..6566866be82 100644 --- a/app/views/projects/issues/index.atom.builder +++ b/app/views/projects/issues/index.atom.builder @@ -1,3 +1,4 @@ +# rubocop: disable CodeReuse/ActiveRecord xml.title "#{@project.name} issues" xml.link href: url_for(safe_params), rel: "self", type: "application/atom+xml" xml.link href: project_issues_url(@project), rel: "alternate", type: "text/html" @@ -5,3 +6,4 @@ xml.id project_issues_url(@project) xml.updated @issues.first.updated_at.xmlschema if @issues.reorder(nil).any? xml << render(partial: 'issues/issue', collection: @issues) if @issues.reorder(nil).any? +# rubocop: enable CodeReuse/ActiveRecord diff --git a/app/views/projects/jobs/index.html.haml b/app/views/projects/jobs/index.html.haml index fe1c338b634..59592abcf6a 100644 --- a/app/views/projects/jobs/index.html.haml +++ b/app/views/projects/jobs/index.html.haml @@ -8,7 +8,7 @@ .nav-controls - if can?(current_user, :update_build, @project) - - if @all_builds.running_or_pending.limit(1).any? + - if @all_builds.running_or_pending.limit(1).any? # rubocop: disable CodeReuse/ActiveRecord = link_to 'Cancel running', cancel_all_project_jobs_path(@project), data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', method: :post diff --git a/app/views/projects/runners/_runner.html.haml b/app/views/projects/runners/_runner.html.haml index 6ee83fae25e..548977d6a80 100644 --- a/app/views/projects/runners/_runner.html.haml +++ b/app/views/projects/runners/_runner.html.haml @@ -24,7 +24,7 @@ - if runner.belongs_to_one_project? = link_to _('Remove Runner'), project_runner_path(@project, runner), data: { confirm: _("Are you sure?") }, method: :delete, class: 'btn btn-danger btn-sm' - else - - runner_project = @project.runner_projects.find_by(runner_id: runner) + - runner_project = @project.runner_projects.find_by(runner_id: runner) # rubocop: disable CodeReuse/ActiveRecord = link_to _('Disable for this project'), project_runner_project_path(@project, runner_project), data: { confirm: _("Are you sure?") }, method: :delete, class: 'btn btn-danger btn-sm' - elsif runner.project_type? = form_for [@project.namespace.becomes(Namespace), @project, @project.runner_projects.new] do |f| diff --git a/app/views/shared/issuable/_assignees.html.haml b/app/views/shared/issuable/_assignees.html.haml index fc86f855865..ef3d44a9241 100644 --- a/app/views/shared/issuable/_assignees.html.haml +++ b/app/views/shared/issuable/_assignees.html.haml @@ -3,7 +3,7 @@ - render_count = assignees_rendering_overflow ? max_render - 1 : max_render - more_assignees_count = issue.assignees.size - render_count -- issue.assignees.take(render_count).each do |assignee| +- issue.assignees.take(render_count).each do |assignee| # rubocop: disable CodeReuse/ActiveRecord = link_to_member(@project, assignee, name: false, title: "Assigned to :name") - if more_assignees_count.positive? diff --git a/app/views/shared/members/_access_request_buttons.html.haml b/app/views/shared/members/_access_request_buttons.html.haml index 40224cec9e8..ebae58f28ba 100644 --- a/app/views/shared/members/_access_request_buttons.html.haml +++ b/app/views/shared/members/_access_request_buttons.html.haml @@ -1,13 +1,13 @@ - model_name = source.model_name.to_s.downcase -- if can?(current_user, :"destroy_#{model_name}_member", source.members.find_by(user_id: current_user.id)) +- if can?(current_user, :"destroy_#{model_name}_member", source.members.find_by(user_id: current_user.id)) # rubocop: disable CodeReuse/ActiveRecord .project-action-button.inline - link_text = source.is_a?(Group) ? _('Leave group') : _('Leave project') = link_to link_text, polymorphic_path([:leave, source, :members]), method: :delete, data: { confirm: leave_confirmation_message(source) }, class: 'btn' -- elsif requester = source.requesters.find_by(user_id: current_user.id) +- elsif requester = source.requesters.find_by(user_id: current_user.id) # rubocop: disable CodeReuse/ActiveRecord .project-action-button.inline = link_to _('Withdraw Access Request'), polymorphic_path([:leave, source, :members]), method: :delete, diff --git a/app/workers/admin_email_worker.rb b/app/workers/admin_email_worker.rb index 06324575ffc..f69e74b2674 100644 --- a/app/workers/admin_email_worker.rb +++ b/app/workers/admin_email_worker.rb @@ -10,10 +10,12 @@ class AdminEmailWorker private + # rubocop: disable CodeReuse/ActiveRecord def send_repository_check_mail repository_check_failed_count = Project.where(last_repository_check_failed: true).count return if repository_check_failed_count.zero? RepositoryCheckMailer.notify(repository_check_failed_count).deliver_now end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/archive_trace_worker.rb b/app/workers/archive_trace_worker.rb index c6f89a17729..c1283e9b2fc 100644 --- a/app/workers/archive_trace_worker.rb +++ b/app/workers/archive_trace_worker.rb @@ -4,9 +4,11 @@ class ArchiveTraceWorker include ApplicationWorker include PipelineBackgroundQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(job_id) Ci::Build.without_archived_trace.find_by(id: job_id).try do |job| job.trace.archive! end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/authorized_projects_worker.rb b/app/workers/authorized_projects_worker.rb index dd62bb0f33d..c9ddeb08613 100644 --- a/app/workers/authorized_projects_worker.rb +++ b/app/workers/authorized_projects_worker.rb @@ -12,9 +12,11 @@ class AuthorizedProjectsWorker end end + # rubocop: disable CodeReuse/ActiveRecord def perform(user_id) user = User.find_by(id: user_id) user&.refresh_authorized_projects end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_coverage_worker.rb b/app/workers/build_coverage_worker.rb index 53d77dc4524..912c53e11f8 100644 --- a/app/workers/build_coverage_worker.rb +++ b/app/workers/build_coverage_worker.rb @@ -4,7 +4,9 @@ class BuildCoverageWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id)&.update_coverage end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_finished_worker.rb b/app/workers/build_finished_worker.rb index 9dc2c7f3601..51cbbe8882e 100644 --- a/app/workers/build_finished_worker.rb +++ b/app/workers/build_finished_worker.rb @@ -6,6 +6,7 @@ class BuildFinishedWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| # We execute that in sync as this access the files in order to access local file, and reduce IO @@ -17,4 +18,5 @@ class BuildFinishedWorker ArchiveTraceWorker.perform_async(build.id) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_hooks_worker.rb b/app/workers/build_hooks_worker.rb index f1f71dc589c..b0c3676714c 100644 --- a/app/workers/build_hooks_worker.rb +++ b/app/workers/build_hooks_worker.rb @@ -6,8 +6,10 @@ class BuildHooksWorker queue_namespace :pipeline_hooks + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id) .try(:execute_hooks) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_queue_worker.rb b/app/workers/build_queue_worker.rb index 1b3f1fd3c2a..67d5b0f5f5b 100644 --- a/app/workers/build_queue_worker.rb +++ b/app/workers/build_queue_worker.rb @@ -6,9 +6,11 @@ class BuildQueueWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| Ci::UpdateBuildQueueService.new.execute(build) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_success_worker.rb b/app/workers/build_success_worker.rb index e1c1cc24a94..c17608f7378 100644 --- a/app/workers/build_success_worker.rb +++ b/app/workers/build_success_worker.rb @@ -6,11 +6,13 @@ class BuildSuccessWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| create_deployment(build) if build.has_environment? end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/build_trace_sections_worker.rb b/app/workers/build_trace_sections_worker.rb index f4114b3353c..0641130fd64 100644 --- a/app/workers/build_trace_sections_worker.rb +++ b/app/workers/build_trace_sections_worker.rb @@ -4,7 +4,9 @@ class BuildTraceSectionsWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id)&.parse_trace_sections! end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/ci/archive_traces_cron_worker.rb b/app/workers/ci/archive_traces_cron_worker.rb index 7d4e9660a4e..7443aad1380 100644 --- a/app/workers/ci/archive_traces_cron_worker.rb +++ b/app/workers/ci/archive_traces_cron_worker.rb @@ -5,6 +5,7 @@ module Ci include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform # Archive stale live traces which still resides in redis or database # This could happen when ArchiveTraceWorker sidekiq jobs were lost by receiving SIGKILL @@ -19,6 +20,7 @@ module Ci end end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/ci/build_trace_chunk_flush_worker.rb b/app/workers/ci/build_trace_chunk_flush_worker.rb index 9dbf2e5e1ac..23a11c28f9b 100644 --- a/app/workers/ci/build_trace_chunk_flush_worker.rb +++ b/app/workers/ci/build_trace_chunk_flush_worker.rb @@ -5,10 +5,12 @@ module Ci include ApplicationWorker include PipelineBackgroundQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(build_trace_chunk_id) ::Ci::BuildTraceChunk.find_by(id: build_trace_chunk_id).try do |build_trace_chunk| build_trace_chunk.persist_data! end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb b/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb index 692ca6b7f42..1c6413674a0 100644 --- a/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb +++ b/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb @@ -8,6 +8,7 @@ module Gitlab # project_id - The ID of the GitLab project to import the note into. # hash - A Hash containing the details of the GitHub object to imoprt. # notify_key - The Redis key to notify upon completion, if any. + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, hash, notify_key = nil) project = Project.find_by(id: project_id) @@ -24,6 +25,7 @@ module Gitlab .perform_in(client.rate_limit_resets_in, project.id, hash, notify_key) end end + # rubocop: enable CodeReuse/ActiveRecord def try_import(*args) import(*args) diff --git a/app/workers/concerns/gitlab/github_import/stage_methods.rb b/app/workers/concerns/gitlab/github_import/stage_methods.rb index 147c8c8d683..59e6bc2c97d 100644 --- a/app/workers/concerns/gitlab/github_import/stage_methods.rb +++ b/app/workers/concerns/gitlab/github_import/stage_methods.rb @@ -20,11 +20,13 @@ module Gitlab self.class.perform_in(client.rate_limit_resets_in, project.id) end + # rubocop: disable CodeReuse/ActiveRecord def find_project(id) # If the project has been marked as failed we want to bail out # automatically. Project.import_started.find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/workers/concerns/new_issuable.rb b/app/workers/concerns/new_issuable.rb index 7735dec5e6b..a89451a4475 100644 --- a/app/workers/concerns/new_issuable.rb +++ b/app/workers/concerns/new_issuable.rb @@ -10,17 +10,21 @@ module NewIssuable user && issuable end + # rubocop: disable CodeReuse/ActiveRecord def set_user(user_id) @user = User.find_by(id: user_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables log_error(User, user_id) unless @user # rubocop:disable Gitlab/ModuleWithInstanceVariables end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def set_issuable(issuable_id) @issuable = issuable_class.find_by(id: issuable_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables log_error(issuable_class, issuable_id) unless @issuable # rubocop:disable Gitlab/ModuleWithInstanceVariables end + # rubocop: enable CodeReuse/ActiveRecord def log_error(record_class, record_id) Rails.logger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job") diff --git a/app/workers/create_gpg_signature_worker.rb b/app/workers/create_gpg_signature_worker.rb index a1aeeb7c4fc..49c7a403838 100644 --- a/app/workers/create_gpg_signature_worker.rb +++ b/app/workers/create_gpg_signature_worker.rb @@ -3,6 +3,7 @@ class CreateGpgSignatureWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(commit_shas, project_id) # Older versions of GitPushService may push a single commit ID on the stack. # We need this to be backwards compatible. @@ -26,4 +27,5 @@ class CreateGpgSignatureWorker end end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/delete_container_repository_worker.rb b/app/workers/delete_container_repository_worker.rb index b703530d3a0..e8fe9d82797 100644 --- a/app/workers/delete_container_repository_worker.rb +++ b/app/workers/delete_container_repository_worker.rb @@ -8,6 +8,7 @@ class DeleteContainerRepositoryWorker attr_reader :container_repository + # rubocop: disable CodeReuse/ActiveRecord def perform(current_user_id, container_repository_id) current_user = User.find_by(id: current_user_id) @container_repository = ContainerRepository.find_by(id: container_repository_id) @@ -21,6 +22,7 @@ class DeleteContainerRepositoryWorker Projects::ContainerRepository::DestroyService.new(project, current_user).execute(container_repository) end end + # rubocop: enable CodeReuse/ActiveRecord # For ExclusiveLeaseGuard concern def lease_key diff --git a/app/workers/delete_diff_files_worker.rb b/app/workers/delete_diff_files_worker.rb index 0874a0b75e8..f518dfe871c 100644 --- a/app/workers/delete_diff_files_worker.rb +++ b/app/workers/delete_diff_files_worker.rb @@ -3,6 +3,7 @@ class DeleteDiffFilesWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(merge_request_diff_id) merge_request_diff = MergeRequestDiff.find(merge_request_diff_id) @@ -16,4 +17,5 @@ class DeleteDiffFilesWorker .delete_all end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/detect_repository_languages_worker.rb b/app/workers/detect_repository_languages_worker.rb index 854b74b884a..64bc9776d48 100644 --- a/app/workers/detect_repository_languages_worker.rb +++ b/app/workers/detect_repository_languages_worker.rb @@ -11,6 +11,7 @@ class DetectRepositoryLanguagesWorker attr_reader :project + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id) @project = Project.find_by(id: project_id) user = User.find_by(id: user_id) @@ -20,6 +21,7 @@ class DetectRepositoryLanguagesWorker ::Projects::DetectRepositoryLanguagesService.new(project, user).execute end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/expire_build_artifacts_worker.rb b/app/workers/expire_build_artifacts_worker.rb index 5d3a9a39b93..dce812d1ae2 100644 --- a/app/workers/expire_build_artifacts_worker.rb +++ b/app/workers/expire_build_artifacts_worker.rb @@ -4,6 +4,7 @@ class ExpireBuildArtifactsWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform Rails.logger.info 'Scheduling removal of build artifacts' @@ -12,4 +13,5 @@ class ExpireBuildArtifactsWorker ExpireBuildInstanceArtifactsWorker.bulk_perform_async(build_ids) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/expire_build_instance_artifacts_worker.rb b/app/workers/expire_build_instance_artifacts_worker.rb index 3b57ecb36e3..4fcd1e5bd24 100644 --- a/app/workers/expire_build_instance_artifacts_worker.rb +++ b/app/workers/expire_build_instance_artifacts_worker.rb @@ -3,6 +3,7 @@ class ExpireBuildInstanceArtifactsWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) build = Ci::Build .with_expired_artifacts @@ -14,4 +15,5 @@ class ExpireBuildInstanceArtifactsWorker Rails.logger.info "Removing artifacts for build #{build.id}..." build.erase_artifacts! end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/expire_job_cache_worker.rb b/app/workers/expire_job_cache_worker.rb index 14a57b90114..b09d0a5d121 100644 --- a/app/workers/expire_job_cache_worker.rb +++ b/app/workers/expire_job_cache_worker.rb @@ -6,6 +6,7 @@ class ExpireJobCacheWorker queue_namespace :pipeline_cache + # rubocop: disable CodeReuse/ActiveRecord def perform(job_id) job = CommitStatus.joins(:pipeline, :project).find_by(id: job_id) return unless job @@ -18,6 +19,7 @@ class ExpireJobCacheWorker store.touch(project_job_path(project, job)) end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/expire_pipeline_cache_worker.rb b/app/workers/expire_pipeline_cache_worker.rb index 992fc63c451..c96e8a0379b 100644 --- a/app/workers/expire_pipeline_cache_worker.rb +++ b/app/workers/expire_pipeline_cache_worker.rb @@ -6,6 +6,7 @@ class ExpirePipelineCacheWorker queue_namespace :pipeline_cache + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) pipeline = Ci::Pipeline.find_by(id: pipeline_id) return unless pipeline @@ -23,6 +24,7 @@ class ExpirePipelineCacheWorker Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline) end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/gitlab/github_import/advance_stage_worker.rb b/app/workers/gitlab/github_import/advance_stage_worker.rb index be0b6c180b0..cd2ceb8dcdf 100644 --- a/app/workers/gitlab/github_import/advance_stage_worker.rb +++ b/app/workers/gitlab/github_import/advance_stage_worker.rb @@ -63,12 +63,14 @@ module Gitlab end end + # rubocop: disable CodeReuse/ActiveRecord def find_project(id) # TODO: Only select the JID # This is due to the fact that the JID could be present in either the project record or # its associated import_state record Project.import_started.find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/workers/gitlab/github_import/refresh_import_jid_worker.rb b/app/workers/gitlab/github_import/refresh_import_jid_worker.rb index 68d2c5c4331..65473026b4c 100644 --- a/app/workers/gitlab/github_import/refresh_import_jid_worker.rb +++ b/app/workers/gitlab/github_import/refresh_import_jid_worker.rb @@ -30,12 +30,14 @@ module Gitlab # stage, if it died there's nothing we can do anyway. end + # rubocop: disable CodeReuse/ActiveRecord def find_project(id) # TODO: Only select the JID # This is due to the fact that the JID could be present in either the project record or # its associated import_state record Project.import_started.find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/workers/invalid_gpg_signature_update_worker.rb b/app/workers/invalid_gpg_signature_update_worker.rb index 4724ab7ad98..fc8a731b427 100644 --- a/app/workers/invalid_gpg_signature_update_worker.rb +++ b/app/workers/invalid_gpg_signature_update_worker.rb @@ -3,6 +3,7 @@ class InvalidGpgSignatureUpdateWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(gpg_key_id) gpg_key = GpgKey.find_by(id: gpg_key_id) @@ -10,4 +11,5 @@ class InvalidGpgSignatureUpdateWorker Gitlab::Gpg::InvalidGpgSignatureUpdater.new(gpg_key).run end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/issue_due_scheduler_worker.rb b/app/workers/issue_due_scheduler_worker.rb index c04a2d75e0b..476cba47ad7 100644 --- a/app/workers/issue_due_scheduler_worker.rb +++ b/app/workers/issue_due_scheduler_worker.rb @@ -4,9 +4,11 @@ class IssueDueSchedulerWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform project_ids = Issue.opened.due_tomorrow.group(:project_id).pluck(:project_id).map { |id| [id] } MailScheduler::IssueDueWorker.bulk_perform_async(project_ids) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/mail_scheduler/issue_due_worker.rb b/app/workers/mail_scheduler/issue_due_worker.rb index 8794ad7a82c..1e1dde1e829 100644 --- a/app/workers/mail_scheduler/issue_due_worker.rb +++ b/app/workers/mail_scheduler/issue_due_worker.rb @@ -5,10 +5,12 @@ module MailScheduler include ApplicationWorker include MailSchedulerQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id) Issue.opened.due_tomorrow.in_projects(project_id).preload(:project).find_each do |issue| notification_service.issue_due(issue) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/workers/new_note_worker.rb b/app/workers/new_note_worker.rb index 74f34dcf9aa..42f5b945a75 100644 --- a/app/workers/new_note_worker.rb +++ b/app/workers/new_note_worker.rb @@ -5,6 +5,7 @@ class NewNoteWorker # Keep extra parameter to preserve backwards compatibility with # old `NewNoteWorker` jobs (can remove later) + # rubocop: disable CodeReuse/ActiveRecord def perform(note_id, _params = {}) if note = Note.find_by(id: note_id) NotificationService.new.new_note(note) @@ -13,4 +14,5 @@ class NewNoteWorker Rails.logger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job") end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/object_storage/migrate_uploads_worker.rb b/app/workers/object_storage/migrate_uploads_worker.rb index 01d03ec7888..fe5d27b087d 100644 --- a/app/workers/object_storage/migrate_uploads_worker.rb +++ b/app/workers/object_storage/migrate_uploads_worker.rb @@ -57,11 +57,13 @@ module ObjectStorage include Report + # rubocop: disable CodeReuse/ActiveRecord def self.enqueue!(uploads, model_class, mounted_as, to_store) sanity_check!(uploads, model_class, mounted_as) perform_async(uploads.ids, model_class.to_s, mounted_as, to_store) end + # rubocop: enable CodeReuse/ActiveRecord # We need to be sure all the uploads are for the same uploader and model type # and that the mount point exists if provided. @@ -78,6 +80,7 @@ module ObjectStorage raise(SanityCheckError, "Mount point #{mounted_as} not found in #{model_class}.") unless model_has_mount end + # rubocop: disable CodeReuse/ActiveRecord def perform(*args) args_check!(args) @@ -97,6 +100,7 @@ module ObjectStorage # do not retry: the job is insane Rails.logger.warn "#{self.class}: Sanity check error (#{e.message})" end + # rubocop: enable CodeReuse/ActiveRecord def sanity_check!(uploads) self.class.sanity_check!(uploads, @model_class, @mounted_as) diff --git a/app/workers/pages_domain_verification_worker.rb b/app/workers/pages_domain_verification_worker.rb index 4610b688189..b3319ff5a13 100644 --- a/app/workers/pages_domain_verification_worker.rb +++ b/app/workers/pages_domain_verification_worker.rb @@ -3,6 +3,7 @@ class PagesDomainVerificationWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(domain_id) domain = PagesDomain.find_by(id: domain_id) @@ -10,4 +11,5 @@ class PagesDomainVerificationWorker VerifyPagesDomainService.new(domain).execute end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pages_worker.rb b/app/workers/pages_worker.rb index 13a6576a301..fa0dfa2ff4b 100644 --- a/app/workers/pages_worker.rb +++ b/app/workers/pages_worker.rb @@ -9,6 +9,7 @@ class PagesWorker send(action, *arg) # rubocop:disable GitlabSecurity/PublicSend end + # rubocop: disable CodeReuse/ActiveRecord def deploy(build_id) build = Ci::Build.find_by(id: build_id) result = Projects::UpdatePagesService.new(build.project, build).execute @@ -18,6 +19,7 @@ class PagesWorker result end + # rubocop: enable CodeReuse/ActiveRecord def remove(namespace_path, project_path) full_path = File.join(Settings.pages.path, namespace_path, project_path) diff --git a/app/workers/pipeline_hooks_worker.rb b/app/workers/pipeline_hooks_worker.rb index 58023e0af1b..eae1115e60c 100644 --- a/app/workers/pipeline_hooks_worker.rb +++ b/app/workers/pipeline_hooks_worker.rb @@ -6,8 +6,10 @@ class PipelineHooksWorker queue_namespace :pipeline_hooks + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id) .try(:execute_hooks) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_metrics_worker.rb b/app/workers/pipeline_metrics_worker.rb index a97019b100a..c2fbfd2b3a5 100644 --- a/app/workers/pipeline_metrics_worker.rb +++ b/app/workers/pipeline_metrics_worker.rb @@ -4,12 +4,14 @@ class PipelineMetricsWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| update_metrics_for_active_pipeline(pipeline) if pipeline.active? update_metrics_for_succeeded_pipeline(pipeline) if pipeline.success? end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -21,9 +23,11 @@ class PipelineMetricsWorker metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id) end + # rubocop: disable CodeReuse/ActiveRecord def metrics(pipeline) MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline)) end + # rubocop: enable CodeReuse/ActiveRecord def merge_requests(pipeline) pipeline.merge_requests.map(&:id) diff --git a/app/workers/pipeline_notification_worker.rb b/app/workers/pipeline_notification_worker.rb index 3a8846b3747..e4a18573d20 100644 --- a/app/workers/pipeline_notification_worker.rb +++ b/app/workers/pipeline_notification_worker.rb @@ -4,6 +4,7 @@ class PipelineNotificationWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id, recipients = nil) pipeline = Ci::Pipeline.find_by(id: pipeline_id) @@ -11,4 +12,5 @@ class PipelineNotificationWorker NotificationService.new.pipeline_finished(pipeline, recipients) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_process_worker.rb b/app/workers/pipeline_process_worker.rb index 83744c5338a..f2aa17acb51 100644 --- a/app/workers/pipeline_process_worker.rb +++ b/app/workers/pipeline_process_worker.rb @@ -6,8 +6,10 @@ class PipelineProcessWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id) .try(:process!) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_schedule_worker.rb b/app/workers/pipeline_schedule_worker.rb index a1815757735..85d1ffe0fa9 100644 --- a/app/workers/pipeline_schedule_worker.rb +++ b/app/workers/pipeline_schedule_worker.rb @@ -4,6 +4,7 @@ class PipelineScheduleWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now) .preload(:owner, :project).find_each do |schedule| @@ -21,4 +22,5 @@ class PipelineScheduleWorker end end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_success_worker.rb b/app/workers/pipeline_success_worker.rb index 68e9af6a619..4f349ed922c 100644 --- a/app/workers/pipeline_success_worker.rb +++ b/app/workers/pipeline_success_worker.rb @@ -6,6 +6,7 @@ class PipelineSuccessWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| MergeRequests::MergeWhenPipelineSucceedsService @@ -13,4 +14,5 @@ class PipelineSuccessWorker .trigger(pipeline) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_update_worker.rb b/app/workers/pipeline_update_worker.rb index c33468c1f14..13a748e1551 100644 --- a/app/workers/pipeline_update_worker.rb +++ b/app/workers/pipeline_update_worker.rb @@ -6,8 +6,10 @@ class PipelineUpdateWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id) .try(:update_status) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/process_commit_worker.rb b/app/workers/process_commit_worker.rb index c9f6df9b56d..7b167c95c29 100644 --- a/app/workers/process_commit_worker.rb +++ b/app/workers/process_commit_worker.rb @@ -14,6 +14,7 @@ class ProcessCommitWorker # commit_hash - Hash containing commit details to use for constructing a # Commit object without having to use the Git repository. # default - The data was pushed to the default branch. + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id, commit_hash, default = false) project = Project.find_by(id: project_id) @@ -30,6 +31,7 @@ class ProcessCommitWorker process_commit_message(project, commit, user, author, default) update_issue_metrics(commit, author) end + # rubocop: enable CodeReuse/ActiveRecord def process_commit_message(project, commit, user, author, default = false) # Ignore closing references from GitLab-generated commit messages. @@ -50,6 +52,7 @@ class ProcessCommitWorker end end + # rubocop: disable CodeReuse/ActiveRecord def update_issue_metrics(commit, author) mentioned_issues = commit.all_references(author).issues @@ -58,6 +61,7 @@ class ProcessCommitWorker Issue::Metrics.where(issue_id: mentioned_issues.map(&:id), first_mentioned_in_commit_at: nil) .update_all(first_mentioned_in_commit_at: commit.committed_date) end + # rubocop: enable CodeReuse/ActiveRecord def build_commit(project, hash) date_suffix = '_date' diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb index b0e1d8837d9..d27b5e62574 100644 --- a/app/workers/project_cache_worker.rb +++ b/app/workers/project_cache_worker.rb @@ -12,6 +12,7 @@ class ProjectCacheWorker # CHANGELOG. # statistics - An Array containing columns from ProjectStatistics to # refresh, if empty all columns will be refreshed + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, files = [], statistics = []) project = Project.find_by(id: project_id) @@ -23,6 +24,7 @@ class ProjectCacheWorker project.cleanup end + # rubocop: enable CodeReuse/ActiveRecord def update_statistics(project, statistics = []) return unless try_obtain_lease_for(project.id, :update_statistics) diff --git a/app/workers/project_migrate_hashed_storage_worker.rb b/app/workers/project_migrate_hashed_storage_worker.rb index ad0003e7bff..4c6339f7701 100644 --- a/app/workers/project_migrate_hashed_storage_worker.rb +++ b/app/workers/project_migrate_hashed_storage_worker.rb @@ -5,6 +5,7 @@ class ProjectMigrateHashedStorageWorker LEASE_TIMEOUT = 30.seconds.to_i + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, old_disk_path = nil) project = Project.find_by(id: project_id) return if project.nil? || project.pending_delete? @@ -19,6 +20,7 @@ class ProjectMigrateHashedStorageWorker cancel_lease_for(project_id, uuid) if uuid raise ex end + # rubocop: enable CodeReuse/ActiveRecord def lease_for(project_id) Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT) diff --git a/app/workers/propagate_service_template_worker.rb b/app/workers/propagate_service_template_worker.rb index c9da1cae255..3ccd7615697 100644 --- a/app/workers/propagate_service_template_worker.rb +++ b/app/workers/propagate_service_template_worker.rb @@ -6,11 +6,13 @@ class PropagateServiceTemplateWorker LEASE_TIMEOUT = 4.hours.to_i + # rubocop: disable CodeReuse/ActiveRecord def perform(template_id) return unless try_obtain_lease_for(template_id) Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id)) end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/prune_old_events_worker.rb b/app/workers/prune_old_events_worker.rb index c1d05ebbcfd..d44ad0d8030 100644 --- a/app/workers/prune_old_events_worker.rb +++ b/app/workers/prune_old_events_worker.rb @@ -4,6 +4,7 @@ class PruneOldEventsWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform # Contribution calendar shows maximum 12 months of events. # Double nested query is used because MySQL doesn't allow DELETE subqueries @@ -17,4 +18,5 @@ class PruneOldEventsWorker .limit(10_000)) .delete_all end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/prune_web_hook_logs_worker.rb b/app/workers/prune_web_hook_logs_worker.rb index 45c7d32f7eb..38054069f4e 100644 --- a/app/workers/prune_web_hook_logs_worker.rb +++ b/app/workers/prune_web_hook_logs_worker.rb @@ -9,6 +9,7 @@ class PruneWebHookLogsWorker # The maximum number of rows to remove in a single job. DELETE_LIMIT = 50_000 + # rubocop: disable CodeReuse/ActiveRecord def perform # MySQL doesn't allow "DELETE FROM ... WHERE id IN ( ... )" if the inner # query refers to the same table. To work around this we wrap the IN body in @@ -23,4 +24,5 @@ class PruneWebHookLogsWorker ) .delete_all end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/reactive_caching_worker.rb b/app/workers/reactive_caching_worker.rb index 9b331f15dc5..96ff8cd6222 100644 --- a/app/workers/reactive_caching_worker.rb +++ b/app/workers/reactive_caching_worker.rb @@ -3,6 +3,7 @@ class ReactiveCachingWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(class_name, id, *args) klass = begin Kernel.const_get(class_name) @@ -13,4 +14,5 @@ class ReactiveCachingWorker klass.find_by(id: id).try(:exclusively_update_reactive_cache!, *args) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/repository_check/batch_worker.rb b/app/workers/repository_check/batch_worker.rb index 07559ea479b..c1bb1adc9cc 100644 --- a/app/workers/repository_check/batch_worker.rb +++ b/app/workers/repository_check/batch_worker.rb @@ -59,22 +59,28 @@ module RepositoryCheck never_checked_project_ids(BATCH_SIZE) + old_checked_project_ids(BATCH_SIZE) end + # rubocop: disable CodeReuse/ActiveRecord def never_checked_project_ids(batch_size) projects_on_shard.where(last_repository_check_at: nil) .where('created_at < ?', 24.hours.ago) .limit(batch_size).pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def old_checked_project_ids(batch_size) projects_on_shard.where.not(last_repository_check_at: nil) .where('last_repository_check_at < ?', 1.month.ago) .reorder(last_repository_check_at: :asc) .limit(batch_size).pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def projects_on_shard Project.where(repository_storage: shard_name) end + # rubocop: enable CodeReuse/ActiveRecord def try_obtain_lease_for_project(id) # Use a 24-hour timeout because on servers/projects where 'git fsck' is diff --git a/app/workers/repository_check/clear_worker.rb b/app/workers/repository_check/clear_worker.rb index 81e1a4b63bb..01964c69fb2 100644 --- a/app/workers/repository_check/clear_worker.rb +++ b/app/workers/repository_check/clear_worker.rb @@ -5,6 +5,7 @@ module RepositoryCheck include ApplicationWorker include RepositoryCheckQueue + # rubocop: disable CodeReuse/ActiveRecord def perform # Do small batched updates because these updates will be slow and locking Project.select(:id).find_in_batches(batch_size: 100) do |batch| @@ -14,5 +15,6 @@ module RepositoryCheck ) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/workers/repository_check/single_repository_worker.rb b/app/workers/repository_check/single_repository_worker.rb index f44e5693b25..a8097af321f 100644 --- a/app/workers/repository_check/single_repository_worker.rb +++ b/app/workers/repository_check/single_repository_worker.rb @@ -48,9 +48,11 @@ module RepositoryCheck false end + # rubocop: disable CodeReuse/ActiveRecord def has_changes?(project) Project.with_push.exists?(project.id) end + # rubocop: enable CodeReuse/ActiveRecord def has_wiki_changes?(project) return false unless project.wiki_enabled? diff --git a/app/workers/run_pipeline_schedule_worker.rb b/app/workers/run_pipeline_schedule_worker.rb index 1f6cb18c812..f72331c003a 100644 --- a/app/workers/run_pipeline_schedule_worker.rb +++ b/app/workers/run_pipeline_schedule_worker.rb @@ -6,6 +6,7 @@ class RunPipelineScheduleWorker queue_namespace :pipeline_creation + # rubocop: disable CodeReuse/ActiveRecord def perform(schedule_id, user_id) schedule = Ci::PipelineSchedule.find_by(id: schedule_id) user = User.find_by(id: user_id) @@ -14,6 +15,7 @@ class RunPipelineScheduleWorker run_pipeline_schedule(schedule, user) end + # rubocop: enable CodeReuse/ActiveRecord def run_pipeline_schedule(schedule, user) Ci::CreatePipelineService.new(schedule.project, diff --git a/app/workers/stage_update_worker.rb b/app/workers/stage_update_worker.rb index ec8c8e3689f..ea587789d03 100644 --- a/app/workers/stage_update_worker.rb +++ b/app/workers/stage_update_worker.rb @@ -6,9 +6,11 @@ class StageUpdateWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(stage_id) Ci::Stage.find_by(id: stage_id).try do |stage| stage.update_status end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb index c78b7fac589..f6bca1176d1 100644 --- a/app/workers/stuck_ci_jobs_worker.rb +++ b/app/workers/stuck_ci_jobs_worker.rb @@ -46,6 +46,7 @@ class StuckCiJobsWorker end end + # rubocop: disable CodeReuse/ActiveRecord def search(status, timeout) loop do jobs = Ci::Build.where(status: status) @@ -60,6 +61,7 @@ class StuckCiJobsWorker end end end + # rubocop: enable CodeReuse/ActiveRecord def drop_build(type, build, status, timeout) Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout})" diff --git a/app/workers/stuck_import_jobs_worker.rb b/app/workers/stuck_import_jobs_worker.rb index 79ce06dd66e..de92f3eca6a 100644 --- a/app/workers/stuck_import_jobs_worker.rb +++ b/app/workers/stuck_import_jobs_worker.rb @@ -23,6 +23,7 @@ class StuckImportJobsWorker end.count end + # rubocop: disable CodeReuse/ActiveRecord def mark_projects_with_jid_as_failed! # TODO: Rollback this change to use SQL through #pluck jids_and_ids = enqueued_projects_with_jid.map { |project| [project.import_jid, project.id] }.to_h @@ -43,18 +44,25 @@ class StuckImportJobsWorker project.mark_import_as_failed(error_message) end.count end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def enqueued_projects Project.joins_import_state.where("(import_state.status = 'scheduled' OR import_state.status = 'started') OR (projects.import_status = 'scheduled' OR projects.import_status = 'started')") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def enqueued_projects_with_jid enqueued_projects.where.not("import_state.jid IS NULL AND projects.import_jid IS NULL") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def enqueued_projects_without_jid enqueued_projects.where("import_state.jid IS NULL AND projects.import_jid IS NULL") end + # rubocop: enable CodeReuse/ActiveRecord def error_message "Import timed out. Import took longer than #{IMPORT_JOBS_EXPIRATION} seconds" diff --git a/app/workers/stuck_merge_jobs_worker.rb b/app/workers/stuck_merge_jobs_worker.rb index b0a62f76e94..98c81956cba 100644 --- a/app/workers/stuck_merge_jobs_worker.rb +++ b/app/workers/stuck_merge_jobs_worker.rb @@ -4,6 +4,7 @@ class StuckMergeJobsWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform stuck_merge_requests.find_in_batches(batch_size: 100) do |group| jids = group.map(&:merge_jid) @@ -18,9 +19,11 @@ class StuckMergeJobsWorker end end end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def apply_current_state!(completed_jids, completed_ids) merge_requests = MergeRequest.where(id: completed_ids) @@ -34,8 +37,11 @@ class StuckMergeJobsWorker Rails.logger.info("Updated state of locked merge jobs. JIDs: #{completed_jids.join(', ')}") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def stuck_merge_requests MergeRequest.select('id, merge_jid').with_state(:locked).where.not(merge_jid: nil).reorder(nil) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/update_head_pipeline_for_merge_request_worker.rb b/app/workers/update_head_pipeline_for_merge_request_worker.rb index 0487a393566..9ce51662969 100644 --- a/app/workers/update_head_pipeline_for_merge_request_worker.rb +++ b/app/workers/update_head_pipeline_for_merge_request_worker.rb @@ -6,6 +6,7 @@ class UpdateHeadPipelineForMergeRequestWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(merge_request_id) merge_request = MergeRequest.find(merge_request_id) pipeline = Ci::Pipeline.where(project: merge_request.source_project, ref: merge_request.source_branch).last @@ -20,6 +21,7 @@ class UpdateHeadPipelineForMergeRequestWorker merge_request.update_attribute(:head_pipeline_id, pipeline.id) end + # rubocop: enable CodeReuse/ActiveRecord def log_error_message_for(merge_request) Rails.logger.error( diff --git a/app/workers/update_merge_requests_worker.rb b/app/workers/update_merge_requests_worker.rb index 742841219b3..c7213df652a 100644 --- a/app/workers/update_merge_requests_worker.rb +++ b/app/workers/update_merge_requests_worker.rb @@ -5,6 +5,7 @@ class UpdateMergeRequestsWorker LOG_TIME_THRESHOLD = 90 # seconds + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id, oldrev, newrev, ref) project = Project.find_by(id: project_id) return unless project @@ -28,4 +29,5 @@ class UpdateMergeRequestsWorker Rails.logger.info("UpdateMergeRequestsWorker#perform #{args_log}") if time.real > LOG_TIME_THRESHOLD end + # rubocop: enable CodeReuse/ActiveRecord end |