From 204a0865e0e69d740abcaa85a689218140678a49 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Fri, 17 Feb 2017 07:09:24 +1100 Subject: Add merge request count to each issue on issues list --- app/models/concerns/issuable.rb | 4 ++-- app/models/merge_requests_closing_issues.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 5f53c48fc88..c9c6bd24d75 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -16,9 +16,9 @@ module Issuable include TimeTrackable # This object is used to gather issuable meta data for displaying - # upvotes, downvotes and notes count for issues and merge requests + # upvotes, downvotes, notes and closing merge requests count for issues and merge requests # lists avoiding n+1 queries and improving performance. - IssuableMeta = Struct.new(:upvotes, :downvotes, :notes_count) + IssuableMeta = Struct.new(:upvotes, :downvotes, :notes_count, :merge_requests_count) included do cache_markdown_field :title, pipeline: :single_line diff --git a/app/models/merge_requests_closing_issues.rb b/app/models/merge_requests_closing_issues.rb index ab597c37947..1ecdfd1dfdb 100644 --- a/app/models/merge_requests_closing_issues.rb +++ b/app/models/merge_requests_closing_issues.rb @@ -4,4 +4,12 @@ class MergeRequestsClosingIssues < ActiveRecord::Base validates :merge_request_id, uniqueness: { scope: :issue_id }, presence: true validates :issue_id, presence: true + + class << self + def count_for_collection(ids) + select('issue_id', 'COUNT(*) as count'). + group(:issue_id). + where(issue_id: ids) + end + end end -- cgit v1.2.1 From d38fb942e188021d7def5eb577a73c82b8e5e66d Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 16 Feb 2017 21:08:47 +0800 Subject: Optimize Ci::Pipeline.latest query Since we already know which ref we want, we could filter it out first. Feedback: https://gitlab.com/gitlab-org/gitlab-ce/issues/26570#note_23423376 Closes #26570 --- app/models/ci/pipeline.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index dc4590a9923..2a987bfa87b 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -91,6 +91,7 @@ module Ci scope :latest, ->(ref = nil) do max_id = unscope(:select) .select("max(#{quoted_table_name}.id)") + .where(ref: ref) .group(:ref, :sha) relation = ref ? where(ref: ref) : self -- cgit v1.2.1 From 3750b06b8cdc02bc87eba27dd8e4ab5f1f24802f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 16 Feb 2017 22:17:42 +0800 Subject: Consider the case where we don't specify ref for pipeline --- app/models/ci/pipeline.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 2a987bfa87b..6e89b18aee5 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -91,11 +91,13 @@ module Ci scope :latest, ->(ref = nil) do max_id = unscope(:select) .select("max(#{quoted_table_name}.id)") - .where(ref: ref) .group(:ref, :sha) - relation = ref ? where(ref: ref) : self - relation.where(id: max_id) + if ref + where(ref: ref, id: max_id.where(ref: ref)) + else + where(id: max_id) + end end def self.latest_status(ref = nil) -- cgit v1.2.1 From 1eb72a71f54da310b2277e5890dce27c15e11036 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Tue, 21 Feb 2017 12:45:08 +1100 Subject: Refactored count_for_collection() for using pluck instead of select --- app/models/merge_requests_closing_issues.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/merge_requests_closing_issues.rb b/app/models/merge_requests_closing_issues.rb index 1ecdfd1dfdb..97210900bd5 100644 --- a/app/models/merge_requests_closing_issues.rb +++ b/app/models/merge_requests_closing_issues.rb @@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base class << self def count_for_collection(ids) - select('issue_id', 'COUNT(*) as count'). - group(:issue_id). - where(issue_id: ids) + group(:issue_id). + where(issue_id: ids). + pluck('issue_id', 'COUNT(*) as count') end end end -- cgit v1.2.1 From 2ace39f2420abf018ceef6aaad52e4917bcbab7d Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Tue, 14 Feb 2017 17:07:11 -0200 Subject: Spam check and reCAPTCHA improvements --- app/models/concerns/spammable.rb | 2 +- app/models/project_snippet.rb | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/spammable.rb b/app/models/concerns/spammable.rb index 79adc77c9e4..107e6764ba2 100644 --- a/app/models/concerns/spammable.rb +++ b/app/models/concerns/spammable.rb @@ -13,7 +13,7 @@ module Spammable attr_accessor :spam attr_accessor :spam_log - after_validation :check_for_spam, on: :create + after_validation :check_for_spam, on: [:create, :update] cattr_accessor :spammable_attrs, instance_accessor: false do [] diff --git a/app/models/project_snippet.rb b/app/models/project_snippet.rb index 9bb456eee24..25b5d777641 100644 --- a/app/models/project_snippet.rb +++ b/app/models/project_snippet.rb @@ -9,8 +9,4 @@ class ProjectSnippet < Snippet participant :author participant :notes_with_associations - - def check_for_spam? - super && project.public? - end end -- cgit v1.2.1 From 93e3cfec3abc7c0eed741ba94779bf014cd9bcb7 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Wed, 22 Feb 2017 08:52:49 +1100 Subject: Added space indentation in models/merge_requests_closing_issues.rb --- app/models/merge_requests_closing_issues.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/merge_requests_closing_issues.rb b/app/models/merge_requests_closing_issues.rb index 97210900bd5..daafb137be4 100644 --- a/app/models/merge_requests_closing_issues.rb +++ b/app/models/merge_requests_closing_issues.rb @@ -8,8 +8,8 @@ class MergeRequestsClosingIssues < ActiveRecord::Base class << self def count_for_collection(ids) group(:issue_id). - where(issue_id: ids). - pluck('issue_id', 'COUNT(*) as count') + where(issue_id: ids). + pluck('issue_id', 'COUNT(*) as count') end end end -- cgit v1.2.1 From f40716f48a25809d197ba2abf32ce150b7b73efa Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 16:31:14 -0600 Subject: No more and/or --- app/models/project.rb | 2 +- app/models/project_services/drone_ci_service.rb | 2 +- app/models/project_services/irker_service.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/project.rb b/app/models/project.rb index fc5b1a66910..411299eef63 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -552,7 +552,7 @@ class Project < ActiveRecord::Base end def check_limit - unless creator.can_create_project? or namespace.kind == 'group' + unless creator.can_create_project? || namespace.kind == 'group' projects_limit = creator.projects_limit if projects_limit == 0 diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb index 942ec9371e5..1ad9efac196 100644 --- a/app/models/project_services/drone_ci_service.rb +++ b/app/models/project_services/drone_ci_service.rb @@ -52,7 +52,7 @@ class DroneCiService < CiService response = HTTParty.get(commit_status_path(sha, ref), verify: enable_ssl_verification) status = - if response.code == 200 and response['status'] + if response.code == 200 && response['status'] case response['status'] when 'killed' :canceled diff --git a/app/models/project_services/irker_service.rb b/app/models/project_services/irker_service.rb index 5d93064f9b3..5d6862d9faa 100644 --- a/app/models/project_services/irker_service.rb +++ b/app/models/project_services/irker_service.rb @@ -96,7 +96,7 @@ class IrkerService < Service rescue URI::InvalidURIError end - unless uri.present? and default_irc_uri.nil? + unless uri.present? && default_irc_uri.nil? begin new_recipient = URI.join(default_irc_uri, '/', recipient).to_s uri = consider_uri(URI.parse(new_recipient)) -- cgit v1.2.1 From 2f0599b6c851c208b5332f37509df0ada52e6d6a Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Feb 2017 12:36:23 +0100 Subject: Disable unused tags count cache for Projects, Builds and Runners + remove complete leftover when Issues were tagged using acts_as_taggable --- app/models/issue.rb | 2 -- app/models/project.rb | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/issue.rb b/app/models/issue.rb index d8826b65fcc..de90f19f854 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -15,8 +15,6 @@ class Issue < ActiveRecord::Base DueThisWeek = DueDateStruct.new('Due This Week', 'week').freeze DueThisMonth = DueDateStruct.new('Due This Month', 'month').freeze - ActsAsTaggableOn.strict_case_match = true - belongs_to :project belongs_to :moved_to, class_name: 'Issue' diff --git a/app/models/project.rb b/app/models/project.rb index 411299eef63..96ab7fdc99d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -70,8 +70,7 @@ class Project < ActiveRecord::Base after_validation :check_pending_delete - ActsAsTaggableOn.strict_case_match = true - acts_as_taggable_on :tags + acts_as_taggable attr_accessor :new_default_branch attr_accessor :old_path_with_namespace -- cgit v1.2.1 From 5a2c68811712aecdece01ed203cda2ae2bb32ca9 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Thu, 9 Feb 2017 12:29:56 +0000 Subject: Fix MR changes tab size count This was wrong when there were over 100 files in the diff, because we did not use the same diff options as subclasses of `Gitlab::Diff::FileCollection::Base` when getting the raw diffs. (The reason we don't use those classes directly is because they may perform highlighting, which isn't needed for just counting the diffs.) --- app/models/merge_request.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 204d2b153ad..9076179b0b3 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -203,7 +203,11 @@ class MergeRequest < ActiveRecord::Base end def diff_size - opts = diff_options || {} + # The `#diffs` method ends up at an instance of a class inheriting from + # `Gitlab::Diff::FileCollection::Base`, so use those options as defaults + # here too, to get the same diff size without performing highlighting. + # + opts = Gitlab::Diff::FileCollection::Base.default_options.merge(diff_options || {}) raw_diffs(opts).size end -- cgit v1.2.1 From 3dadf306ddc81183e74b048bc4119796852ed7ea Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 17:29:35 -0600 Subject: Enable Style/DotPosition --- app/models/ci/build.rb | 18 +++++++++--------- app/models/ci/pipeline.rb | 34 +++++++++++++++++----------------- app/models/ci/runner.rb | 4 ++-- app/models/ci/stage.rb | 6 +++--- app/models/commit_status.rb | 10 +++++----- app/models/concerns/milestoneish.rb | 4 ++-- app/models/concerns/presentable.rb | 6 +++--- app/models/concerns/subscribable.rb | 8 ++++---- app/models/generic_commit_status.rb | 6 +++--- app/models/global_milestone.rb | 4 ++-- app/models/group.rb | 6 +++--- app/models/label.rb | 6 +++--- app/models/lfs_object.rb | 6 +++--- app/models/member.rb | 6 +++--- app/models/merge_request.rb | 6 +++--- app/models/merge_request_diff.rb | 4 ++-- app/models/namespace.rb | 6 +++--- app/models/network/commit.rb | 4 ++-- app/models/network/graph.rb | 12 ++++++------ 19 files changed, 78 insertions(+), 78 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index e018f8e7c4e..9a45ef06750 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -63,9 +63,9 @@ module Ci end def retry(build, current_user) - Ci::RetryBuildService - .new(build.project, current_user) - .execute(build) + Ci::RetryBuildService. + new(build.project, current_user). + execute(build) end end @@ -96,9 +96,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Build::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Build::Factory. + new(self, current_user). + fabricate! end def manual? @@ -220,9 +220,9 @@ module Ci end def merge_request - merge_requests = MergeRequest.includes(:merge_request_diff) - .where(source_branch: ref, source_project_id: pipeline.gl_project_id) - .reorder(iid: :asc) + merge_requests = MergeRequest.includes(:merge_request_diff). + where(source_branch: ref, source_project_id: pipeline.gl_project_id). + reorder(iid: :asc) merge_requests.find do |merge_request| merge_request.commits_sha.include?(pipeline.sha) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 6e89b18aee5..ae4759ed2a0 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -89,9 +89,9 @@ module Ci # ref can't be HEAD or SHA, can only be branch/tag name scope :latest, ->(ref = nil) do - max_id = unscope(:select) - .select("max(#{quoted_table_name}.id)") - .group(:ref, :sha) + max_id = unscope(:select). + select("max(#{quoted_table_name}.id)"). + group(:ref, :sha) if ref where(ref: ref, id: max_id.where(ref: ref)) @@ -133,16 +133,16 @@ module Ci def stages # TODO, this needs refactoring, see gitlab-ce#26481. - stages_query = statuses - .group('stage').select(:stage).order('max(stage_idx)') + stages_query = statuses. + group('stage').select(:stage).order('max(stage_idx)') status_sql = statuses.latest.where('stage=sg.stage').status_sql - warnings_sql = statuses.latest.select('COUNT(*) > 0') - .where('stage=sg.stage').failed_but_allowed.to_sql + warnings_sql = statuses.latest.select('COUNT(*) > 0'). + where('stage=sg.stage').failed_but_allowed.to_sql - stages_with_statuses = CommitStatus.from(stages_query, :sg) - .pluck('sg.stage', status_sql, "(#{warnings_sql})") + stages_with_statuses = CommitStatus.from(stages_query, :sg). + pluck('sg.stage', status_sql, "(#{warnings_sql})") stages_with_statuses.map do |stage| Ci::Stage.new(self, Hash[%i[name status warnings].zip(stage)]) @@ -222,8 +222,8 @@ module Ci end def retry_failed(current_user) - Ci::RetryPipelineService.new(project, current_user) - .execute(self) + Ci::RetryPipelineService.new(project, current_user). + execute(self) end def mark_as_processable_after_stage(stage_idx) @@ -355,15 +355,15 @@ module Ci # Merge requests for which the current pipeline is running against # the merge request's latest commit. def merge_requests - @merge_requests ||= project.merge_requests - .where(source_branch: self.ref) - .select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } + @merge_requests ||= project.merge_requests. + where(source_branch: self.ref). + select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } end def detailed_status(current_user) - Gitlab::Ci::Status::Pipeline::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Pipeline::Factory. + new(self, current_user). + fabricate! end private diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 07a086b0aca..9cda008a549 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -23,8 +23,8 @@ module Ci scope :ordered, ->() { order(id: :desc) } scope :owned_or_shared, ->(project_id) do - joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id') - .where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) + joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'). + where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) end scope :assignable_for, ->(project) do diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index ca74c91b062..0751ab1b7d8 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -28,9 +28,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Stage::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Stage::Factory. + new(self, current_user). + fabricate! end def statuses diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 99a6326309d..d31a6d81ebd 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -96,8 +96,8 @@ class CommitStatus < ActiveRecord::Base after_transition any => :failed do |commit_status| commit_status.run_after_commit do - MergeRequests::AddTodoWhenBuildFailsService - .new(pipeline.project, nil).execute(self) + MergeRequests::AddTodoWhenBuildFailsService. + new(pipeline.project, nil).execute(self) end end end @@ -133,9 +133,9 @@ class CommitStatus < ActiveRecord::Base end def detailed_status(current_user) - Gitlab::Ci::Status::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Factory. + new(self, current_user). + fabricate! end def sortable_name diff --git a/app/models/concerns/milestoneish.rb b/app/models/concerns/milestoneish.rb index f449229864d..870a6fbaa90 100644 --- a/app/models/concerns/milestoneish.rb +++ b/app/models/concerns/milestoneish.rb @@ -39,8 +39,8 @@ module Milestoneish def issues_visible_to_user(user) memoize_per_user(user, :issues_visible_to_user) do - IssuesFinder.new(user, issues_finder_params) - .execute.where(milestone_id: milestoneish_ids) + IssuesFinder.new(user, issues_finder_params). + execute.where(milestone_id: milestoneish_ids) end end diff --git a/app/models/concerns/presentable.rb b/app/models/concerns/presentable.rb index 7b33b837004..d0f84831d71 100644 --- a/app/models/concerns/presentable.rb +++ b/app/models/concerns/presentable.rb @@ -1,7 +1,7 @@ module Presentable def present(**attributes) - Gitlab::View::Presenter::Factory - .new(self, attributes) - .fabricate! + Gitlab::View::Presenter::Factory. + new(self, attributes). + fabricate! end end diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb index 83daa9b1a64..e4f5818d0e3 100644 --- a/app/models/concerns/subscribable.rb +++ b/app/models/concerns/subscribable.rb @@ -42,15 +42,15 @@ module Subscribable def subscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project) - .update(subscribed: true) + find_or_initialize_subscription(user, project). + update(subscribed: true) end def unsubscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project) - .update(subscribed: false) + find_or_initialize_subscription(user, project). + update(subscribed: false) end private diff --git a/app/models/generic_commit_status.rb b/app/models/generic_commit_status.rb index 8867ba0d2ff..36b8568871b 100644 --- a/app/models/generic_commit_status.rb +++ b/app/models/generic_commit_status.rb @@ -18,8 +18,8 @@ class GenericCommitStatus < CommitStatus end def detailed_status(current_user) - Gitlab::Ci::Status::External::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::External::Factory. + new(self, current_user). + fabricate! end end diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index b991d78e27f..84deb67ba9b 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -76,8 +76,8 @@ class GlobalMilestone end def labels - @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten) - .sort_by!(&:title) + @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten). + sort_by!(&:title) end def due_date diff --git a/app/models/group.rb b/app/models/group.rb index 240a17f1dc1..1835ce118a1 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -71,9 +71,9 @@ class Group < Namespace def select_for_project_authorization if current_scope.joins_values.include?(:shared_projects) - joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id') - .where('project_namespace.share_with_group_lock = ?', false) - .select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") + joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id'). + where('project_namespace.share_with_group_lock = ?', false). + select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") else super end diff --git a/app/models/label.rb b/app/models/label.rb index 5b6b9a7a736..8d76e422c67 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -34,9 +34,9 @@ class Label < ActiveRecord::Base scope :with_title, ->(title) { where(title: title) } def self.prioritized(project) - joins(:priorities) - .where(label_priorities: { project_id: project }) - .reorder('label_priorities.priority ASC, labels.title ASC') + joins(:priorities). + where(label_priorities: { project_id: project }). + reorder('label_priorities.priority ASC, labels.title ASC') end def self.unprioritized(project) diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb index 7712d5783e0..ee9ac282e39 100644 --- a/app/models/lfs_object.rb +++ b/app/models/lfs_object.rb @@ -19,8 +19,8 @@ class LfsObject < ActiveRecord::Base end def self.destroy_unreferenced - joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") - .where(lfs_objects_projects: { id: nil }) - .destroy_all + joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id"). + where(lfs_objects_projects: { id: nil }). + destroy_all end end diff --git a/app/models/member.rb b/app/models/member.rb index d07f270b757..0f6b75b0b93 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -39,9 +39,9 @@ class Member < ActiveRecord::Base is_external_invite = arel_table[:user_id].eq(nil).and(arel_table[:invite_token].not_eq(nil)) user_is_active = User.arel_table[:state].eq(:active) - includes(:user).references(:users) - .where(is_external_invite.or(user_is_active)) - .where(requested_at: nil) + includes(:user).references(:users). + where(is_external_invite.or(user_is_active)). + where(requested_at: nil) end scope :invite, -> { where.not(invite_token: nil) } diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 204d2b153ad..a0b8a63d6ab 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -813,9 +813,9 @@ class MergeRequest < ActiveRecord::Base def all_pipelines return Ci::Pipeline.none unless source_project - @all_pipelines ||= source_project.pipelines - .where(sha: all_commits_sha, ref: source_branch) - .order(id: :desc) + @all_pipelines ||= source_project.pipelines. + where(sha: all_commits_sha, ref: source_branch). + order(id: :desc) end # Note that this could also return SHA from now dangling commits diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 70bad2a4396..e1f172b24bf 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -169,8 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base # 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: straight) + CompareService.new(project, head_commit_sha). + execute(project, sha, straight: straight) end def commits_count diff --git a/app/models/namespace.rb b/app/models/namespace.rb index bd0336c984a..e207ac3db4e 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -48,9 +48,9 @@ class Namespace < ActiveRecord::Base scope :root, -> { where('type IS NULL') } scope :with_statistics, -> do - joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id') - .group('namespaces.id') - .select( + joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id'). + group('namespaces.id'). + select( 'namespaces.*', 'COALESCE(SUM(ps.storage_size), 0) AS storage_size', 'COALESCE(SUM(ps.repository_size), 0) AS repository_size', diff --git a/app/models/network/commit.rb b/app/models/network/commit.rb index 8417f200e36..a48e872ad84 100644 --- a/app/models/network/commit.rb +++ b/app/models/network/commit.rb @@ -28,8 +28,8 @@ module Network if map.include?(p.id) map[p.id] end - end - .compact + end. + compact end end end diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index b524ca50ee8..b16ecc424dd 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -23,12 +23,12 @@ module Network def collect_notes h = Hash.new(0) - @project - .notes - .where('noteable_type = ?', 'Commit') - .group('notes.commit_id') - .select('notes.commit_id, count(notes.id) as note_count') - .each do |item| + @project. + notes. + where('noteable_type = ?', 'Commit'). + group('notes.commit_id'). + select('notes.commit_id, count(notes.id) as note_count'). + each do |item| h[item.commit_id] = item.note_count.to_i end -- cgit v1.2.1 From b7d8df503cf35b3048b273dc0cadb5ec39aac5e1 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 17:32:18 -0600 Subject: Enable Style/MutableConstant --- app/models/application_setting.rb | 2 +- app/models/ci/runner.rb | 4 ++-- app/models/commit.rb | 2 +- app/models/concerns/cache_markdown_field.rb | 2 +- app/models/concerns/has_status.rb | 12 ++++++------ app/models/label.rb | 2 +- app/models/members/group_member.rb | 2 +- app/models/members/project_member.rb | 2 +- app/models/merge_request_diff.rb | 2 +- app/models/notification_setting.rb | 4 ++-- app/models/project.rb | 2 +- app/models/project_feature.rb | 2 +- app/models/project_services/buildkite_service.rb | 2 +- app/models/project_services/hipchat_service.rb | 2 +- app/models/project_services/pivotaltracker_service.rb | 2 +- app/models/project_statistics.rb | 2 +- app/models/project_wiki.rb | 2 +- app/models/repository.rb | 4 ++-- app/models/todo.rb | 2 +- 19 files changed, 27 insertions(+), 27 deletions(-) (limited to 'app/models') diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 74b358d8c40..4212f1247cc 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -5,7 +5,7 @@ class ApplicationSetting < ActiveRecord::Base add_authentication_token_field :runners_registration_token add_authentication_token_field :health_check_access_token - CACHE_KEY = 'application_setting.last' + CACHE_KEY = 'application_setting.last'.freeze DOMAIN_LIST_SEPARATOR = %r{\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace | # or \s # any whitespace character diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 9cda008a549..a120112e882 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -4,8 +4,8 @@ module Ci RUNNER_QUEUE_EXPIRY_TIME = 60.minutes LAST_CONTACT_TIME = 1.hour.ago - AVAILABLE_SCOPES = %w[specific shared active paused online] - FORM_EDITABLE = %i[description tag_list active run_untagged locked] + AVAILABLE_SCOPES = %w[specific shared active paused online].freeze + FORM_EDITABLE = %i[description tag_list active run_untagged locked].freeze has_many :builds has_many :runner_projects, dependent: :destroy diff --git a/app/models/commit.rb b/app/models/commit.rb index 46f06733da1..ec759762977 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -22,7 +22,7 @@ class Commit DIFF_HARD_LIMIT_LINES = 50000 # The SHA can be between 7 and 40 hex characters. - COMMIT_SHA_PATTERN = '\h{7,40}' + COMMIT_SHA_PATTERN = '\h{7,40}'.freeze class << self def decorate(commits, project) diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index a600f9c14c5..6dc8c88a14d 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -45,7 +45,7 @@ module CacheMarkdownField Project Release Snippet - ] + ].freeze def self.caching_classes CACHING_CLASSES.map(&:constantize) diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb index 431c0354969..aea359e70bb 100644 --- a/app/models/concerns/has_status.rb +++ b/app/models/concerns/has_status.rb @@ -1,12 +1,12 @@ module HasStatus extend ActiveSupport::Concern - DEFAULT_STATUS = 'created' - AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped] - STARTED_STATUSES = %w[running success failed skipped] - ACTIVE_STATUSES = %w[pending running] - COMPLETED_STATUSES = %w[success failed canceled skipped] - ORDERED_STATUSES = %w[failed pending running canceled success skipped] + DEFAULT_STATUS = 'created'.freeze + AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped].freeze + STARTED_STATUSES = %w[running success failed skipped].freeze + ACTIVE_STATUSES = %w[pending running].freeze + COMPLETED_STATUSES = %w[success failed canceled skipped].freeze + ORDERED_STATUSES = %w[failed pending running canceled success skipped].freeze class_methods do def status_sql diff --git a/app/models/label.rb b/app/models/label.rb index 8d76e422c67..27429e60e4a 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -11,7 +11,7 @@ class Label < ActiveRecord::Base cache_markdown_field :description, pipeline: :single_line - DEFAULT_COLOR = '#428BCA' + DEFAULT_COLOR = '#428BCA'.freeze default_value_for :color, DEFAULT_COLOR diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index 204f34f0269..4043fde5301 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -1,5 +1,5 @@ class GroupMember < Member - SOURCE_TYPE = 'Namespace' + SOURCE_TYPE = 'Namespace'.freeze belongs_to :group, foreign_key: 'source_id' diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 008fff0857c..06f8fd39c99 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -1,5 +1,5 @@ class ProjectMember < Member - SOURCE_TYPE = 'Project' + SOURCE_TYPE = 'Project'.freeze include Gitlab::ShellAdapter diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index e1f172b24bf..53d08488788 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -7,7 +7,7 @@ class MergeRequestDiff < ActiveRecord::Base COMMITS_SAFE_SIZE = 100 # Valid types of serialized diffs allowed by Gitlab::Git::Diff - VALID_CLASSES = [Hash, Rugged::Patch, Rugged::Diff::Delta] + VALID_CLASSES = [Hash, Rugged::Patch, Rugged::Diff::Delta].freeze belongs_to :merge_request diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index 58f6214bea7..52577bd52ea 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -35,11 +35,11 @@ class NotificationSetting < ActiveRecord::Base :merge_merge_request, :failed_pipeline, :success_pipeline - ] + ].freeze EXCLUDED_WATCHER_EVENTS = [ :success_pipeline - ] + ].freeze store :events, accessors: EMAIL_EVENTS, coder: JSON diff --git a/app/models/project.rb b/app/models/project.rb index 411299eef63..3a1a724b987 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -22,7 +22,7 @@ class Project < ActiveRecord::Base class BoardLimitExceeded < StandardError; end NUMBER_OF_PERMITTED_BOARDS = 1 - UNKNOWN_IMPORT_URL = 'http://unknown.git' + UNKNOWN_IMPORT_URL = 'http://unknown.git'.freeze cache_markdown_field :description, pipeline: :description diff --git a/app/models/project_feature.rb b/app/models/project_feature.rb index 03194fc2141..e3ef4919b28 100644 --- a/app/models/project_feature.rb +++ b/app/models/project_feature.rb @@ -18,7 +18,7 @@ class ProjectFeature < ActiveRecord::Base PRIVATE = 10 ENABLED = 20 - FEATURES = %i(issues merge_requests wiki snippets builds repository) + FEATURES = %i(issues merge_requests wiki snippets builds repository).freeze class << self def access_level_attribute(feature) diff --git a/app/models/project_services/buildkite_service.rb b/app/models/project_services/buildkite_service.rb index 0956c4a4ede..5fb95050b83 100644 --- a/app/models/project_services/buildkite_service.rb +++ b/app/models/project_services/buildkite_service.rb @@ -3,7 +3,7 @@ require "addressable/uri" class BuildkiteService < CiService include ReactiveService - ENDPOINT = "https://buildkite.com" + ENDPOINT = "https://buildkite.com".freeze prop_accessor :project_url, :token boolean_accessor :enable_ssl_verification diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index 72da219df28..3fdcee26bf3 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -6,7 +6,7 @@ class HipchatService < Service a b i strong em br img pre code table th tr td caption colgroup col thead tbody tfoot ul ol li dl dt dd - ] + ].freeze prop_accessor :token, :room, :server, :color, :api_version boolean_accessor :notify_only_broken_builds, :notify diff --git a/app/models/project_services/pivotaltracker_service.rb b/app/models/project_services/pivotaltracker_service.rb index 9cc642591f4..d86f4f6f448 100644 --- a/app/models/project_services/pivotaltracker_service.rb +++ b/app/models/project_services/pivotaltracker_service.rb @@ -1,7 +1,7 @@ class PivotaltrackerService < Service include HTTParty - API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits' + API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits'.freeze prop_accessor :token, :restrict_to_branch validates :token, presence: true, if: :activated? diff --git a/app/models/project_statistics.rb b/app/models/project_statistics.rb index 06abd406523..aeaf63abab9 100644 --- a/app/models/project_statistics.rb +++ b/app/models/project_statistics.rb @@ -4,7 +4,7 @@ class ProjectStatistics < ActiveRecord::Base before_save :update_storage_size - STORAGE_COLUMNS = [:repository_size, :lfs_objects_size, :build_artifacts_size] + STORAGE_COLUMNS = [:repository_size, :lfs_objects_size, :build_artifacts_size].freeze STATISTICS_COLUMNS = [:commit_count] + STORAGE_COLUMNS def total_repository_size diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index d0b991db112..de36fd3b252 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -5,7 +5,7 @@ class ProjectWiki 'Markdown' => :markdown, 'RDoc' => :rdoc, 'AsciiDoc' => :asciidoc - } unless defined?(MARKUPS) + }.freeze unless defined?(MARKUPS) class CouldNotCreateWikiError < StandardError; end diff --git a/app/models/repository.rb b/app/models/repository.rb index 56c582cd9be..e2a4f458c50 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -18,7 +18,7 @@ class Repository CACHED_METHODS = %i(size commit_count readme version contribution_guide changelog license_blob license_key gitignore koding_yml gitlab_ci_yml branch_names tag_names branch_count - tag_count avatar exists? empty? root_ref) + tag_count avatar exists? empty? root_ref).freeze # Certain method caches should be refreshed when certain types of files are # changed. This Hash maps file types (as returned by Gitlab::FileDetector) to @@ -33,7 +33,7 @@ class Repository koding: :koding_yml, gitlab_ci: :gitlab_ci_yml, avatar: :avatar - } + }.freeze # Wraps around the given method and caches its output in Redis and an instance # variable. diff --git a/app/models/todo.rb b/app/models/todo.rb index 3dda7948d0b..47789a21133 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -17,7 +17,7 @@ class Todo < ActiveRecord::Base APPROVAL_REQUIRED => :approval_required, UNMERGEABLE => :unmergeable, DIRECTLY_ADDRESSED => :directly_addressed - } + }.freeze belongs_to :author, class_name: "User" belongs_to :note -- cgit v1.2.1 From c10064aad5d0e4ca1981fd898a6688e42ea8c9d0 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 17:33:53 -0600 Subject: Enable Style/SpaceInsideBrackets --- app/models/concerns/issuable.rb | 2 +- app/models/concerns/reactive_service.rb | 2 +- app/models/project_services/kubernetes_service.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index c9c6bd24d75..e07ae9d1660 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -68,7 +68,7 @@ module Issuable scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) } scope :join_project, -> { joins(:project) } - scope :inc_notes_with_associations, -> { includes(notes: [ :project, :author, :award_emoji ]) } + scope :inc_notes_with_associations, -> { includes(notes: [:project, :author, :award_emoji]) } scope :references_project, -> { references(:project) } scope :non_archived, -> { join_project.where(projects: { archived: false }) } diff --git a/app/models/concerns/reactive_service.rb b/app/models/concerns/reactive_service.rb index e1f868a299b..713246039c1 100644 --- a/app/models/concerns/reactive_service.rb +++ b/app/models/concerns/reactive_service.rb @@ -5,6 +5,6 @@ module ReactiveService include ReactiveCaching # Default cache key: class name + project_id - self.reactive_cache_key = ->(service) { [ service.class.model_name.singular, service.project_id ] } + self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] } end end diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb index f2f019c43bb..eb5019c08b5 100644 --- a/app/models/project_services/kubernetes_service.rb +++ b/app/models/project_services/kubernetes_service.rb @@ -3,7 +3,7 @@ class KubernetesService < DeploymentService include Gitlab::Kubernetes include ReactiveCaching - self.reactive_cache_key = ->(service) { [ service.class.model_name.singular, service.project_id ] } + self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] } # Namespace defaults to the project path, but can be overridden in case that # is an invalid or inappropriate name @@ -167,7 +167,7 @@ class KubernetesService < DeploymentService url = URI.parse(api_url) prefix = url.path.sub(%r{/+\z}, '') - url.path = [ prefix, *parts ].join("/") + url.path = [prefix, *parts].join("/") url.to_s end -- cgit v1.2.1 From 030baf70d25a666b660b0024f000586631ee3daf Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 17:50:22 -0600 Subject: Enable Performance/RedundantMerge --- app/models/concerns/issuable.rb | 2 +- app/models/merge_request.rb | 2 +- app/models/project_services/pushover_service.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index e07ae9d1660..768baa80c01 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -235,7 +235,7 @@ module Issuable # DEPRECATED repository: project.hook_attrs.slice(:name, :url, :description, :homepage) } - hook_data.merge!(assignee: assignee.hook_attrs) if assignee + hook_data[:assignee] = assignee.hook_attrs if assignee hook_data end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index a0b8a63d6ab..ea784f77015 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -527,7 +527,7 @@ class MergeRequest < ActiveRecord::Base } if diff_head_commit - attrs.merge!(last_commit: diff_head_commit.hook_attrs) + attrs[:last_commit] = diff_head_commit.hook_attrs end attributes.merge!(attrs) diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index a963d27a376..f623bf9851b 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -97,7 +97,7 @@ class PushoverService < Service # Sound parameter MUST NOT be sent to API if not selected if sound - pushover_data.merge!(sound: sound) + pushover_data[:sound] = sound end PushoverService.post('/messages.json', body: pushover_data) -- cgit v1.2.1 From ccbebbdfeb9ce78c0a386ae08ae88aeb7dc5ad86 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 18:16:48 -0600 Subject: Enable Performance/RedundantMatch --- app/models/external_issue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/external_issue.rb b/app/models/external_issue.rb index 26712c19b5a..b973bbcd8da 100644 --- a/app/models/external_issue.rb +++ b/app/models/external_issue.rb @@ -43,7 +43,7 @@ class ExternalIssue end def reference_link_text(from_project = nil) - return "##{id}" if /^\d+$/.match(id) + return "##{id}" if id =~ /^\d+$/ id end -- cgit v1.2.1 From 5cd9c7c6ea1ba5c6ad40799b9476145803dccba5 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 18:40:04 -0600 Subject: Enable Rails/Validation --- app/models/ci/build.rb | 2 +- app/models/ci/pipeline.rb | 6 +++--- app/models/ci/runner_project.rb | 2 +- app/models/ci/trigger.rb | 4 ++-- app/models/commit_status.rb | 2 +- app/models/members/group_member.rb | 2 +- app/models/members/project_member.rb | 2 +- app/models/pages_domain.rb | 2 +- app/models/project.rb | 4 ++-- app/models/protected_branch.rb | 4 ++-- app/models/user.rb | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 9a45ef06750..f9592873ea0 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -23,7 +23,7 @@ module Ci serialize :yaml_variables, Gitlab::Serializer::Ci::Variables validates :coverage, numericality: true, allow_blank: true - validates_presence_of :ref + validates :ref, presence: true scope :unstarted, ->() { where(runner_id: nil) } scope :ignore_failures, ->() { where(allow_failure: false) } diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index ae4759ed2a0..673647f284a 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -14,9 +14,9 @@ module Ci has_many :builds, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id - validates_presence_of :sha, unless: :importing? - validates_presence_of :ref, unless: :importing? - validates_presence_of :status, unless: :importing? + validates :sha, presence: { unless: :importing? } + validates :ref, presence: { unless: :importing? } + validates :status, presence: { unless: :importing? } validate :valid_commit_sha, unless: :importing? after_create :keep_around_commits, unless: :importing? diff --git a/app/models/ci/runner_project.rb b/app/models/ci/runner_project.rb index 1f9baeca5b1..234376a7e4c 100644 --- a/app/models/ci/runner_project.rb +++ b/app/models/ci/runner_project.rb @@ -5,6 +5,6 @@ module Ci belongs_to :runner belongs_to :project, foreign_key: :gl_project_id - validates_uniqueness_of :runner_id, scope: :gl_project_id + validates :runner_id, uniqueness: { scope: :gl_project_id } end end diff --git a/app/models/ci/trigger.rb b/app/models/ci/trigger.rb index 62889fe80d8..39a1dd86241 100644 --- a/app/models/ci/trigger.rb +++ b/app/models/ci/trigger.rb @@ -7,8 +7,8 @@ module Ci belongs_to :project, foreign_key: :gl_project_id has_many :trigger_requests, dependent: :destroy - validates_presence_of :token - validates_uniqueness_of :token + validates :token, presence: true + validates :token, uniqueness: true before_validation :set_default_values diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index d31a6d81ebd..ef5e6202519 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -13,7 +13,7 @@ class CommitStatus < ActiveRecord::Base validates :pipeline, presence: true, unless: :importing? - validates_presence_of :name + validates :name, presence: true alias_attribute :author, :user diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index 4043fde5301..446f9f8f8a7 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -5,7 +5,7 @@ class GroupMember < Member # Make sure group member points only to group as it source default_value_for :source_type, SOURCE_TYPE - validates_format_of :source_type, with: /\ANamespace\z/ + validates :source_type, format: { with: /\ANamespace\z/ } default_scope { where(source_type: SOURCE_TYPE) } def self.access_level_roles diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 06f8fd39c99..912820b51ac 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -7,7 +7,7 @@ class ProjectMember < Member # Make sure project member points only to project as it source default_value_for :source_type, SOURCE_TYPE - validates_format_of :source_type, with: /\AProject\z/ + validates :source_type, format: { with: /\AProject\z/ } validates :access_level, inclusion: { in: Gitlab::Access.values } default_scope { where(source_type: SOURCE_TYPE) } diff --git a/app/models/pages_domain.rb b/app/models/pages_domain.rb index 0b9ebf1ffe2..f2f2fc1e32a 100644 --- a/app/models/pages_domain.rb +++ b/app/models/pages_domain.rb @@ -2,7 +2,7 @@ class PagesDomain < ActiveRecord::Base belongs_to :project validates :domain, hostname: true - validates_uniqueness_of :domain, case_sensitive: false + validates :domain, uniqueness: { case_sensitive: false } validates :certificate, certificate: true, allow_nil: true, allow_blank: true validates :key, certificate_key: true, allow_nil: true, allow_blank: true diff --git a/app/models/project.rb b/app/models/project.rb index 3a1a724b987..0da21be8351 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -191,8 +191,8 @@ class Project < ActiveRecord::Base format: { with: Gitlab::Regex.project_path_regex, message: Gitlab::Regex.project_path_regex_message } validates :namespace, presence: true - validates_uniqueness_of :name, scope: :namespace_id - validates_uniqueness_of :path, scope: :namespace_id + validates :name, uniqueness: { scope: :namespace_id } + validates :path, uniqueness: { scope: :namespace_id } validates :import_url, addressable_url: true, if: :external_import? validates :star_count, numericality: { greater_than_or_equal_to: 0 } validate :check_limit, on: :create diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index 6240912a6e1..39e979ef15b 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -8,8 +8,8 @@ class ProtectedBranch < ActiveRecord::Base has_many :merge_access_levels, dependent: :destroy has_many :push_access_levels, dependent: :destroy - validates_length_of :merge_access_levels, is: 1, message: "are restricted to a single instance per protected branch." - validates_length_of :push_access_levels, is: 1, message: "are restricted to a single instance per protected branch." + validates :merge_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." } + validates :push_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." } accepts_nested_attributes_for :push_access_levels accepts_nested_attributes_for :merge_access_levels diff --git a/app/models/user.rb b/app/models/user.rb index f614eb66e1f..f37735c5eba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -104,7 +104,7 @@ class User < ActiveRecord::Base # # Note: devise :validatable above adds validations for :email and :password validates :name, presence: true - validates_confirmation_of :email + validates :email, confirmation: true validates :notification_email, presence: true validates :notification_email, email: true, if: ->(user) { user.notification_email != user.email } validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true -- cgit v1.2.1 From baafd8de26507ebd76177b5c65b5da921445ddc9 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 18:47:39 -0600 Subject: Enable Style/BarePercentLiterals --- app/models/commit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index ec759762977..20be3c9cba7 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -255,7 +255,7 @@ class Commit end def revert_message(user) - %Q{Revert "#{title.strip}"\n\n#{revert_description(user)}} + %{Revert "#{title.strip}"\n\n#{revert_description(user)}} end def reverts_commit?(commit, user) -- cgit v1.2.1 From 7ea641b6d0882fc782a7eb493daf8b66d076924b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 18:51:36 -0600 Subject: Enable Style/ColonMethodCall --- app/models/commit.rb | 2 +- app/models/project_services/drone_ci_service.rb | 4 ++-- app/models/repository.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index 20be3c9cba7..7afc8f4add8 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -105,7 +105,7 @@ class Commit end def diff_line_count - @diff_line_count ||= Commit::diff_line_count(raw_diffs) + @diff_line_count ||= Commit.diff_line_count(raw_diffs) @diff_line_count end diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb index 1ad9efac196..cd55194e291 100644 --- a/app/models/project_services/drone_ci_service.rb +++ b/app/models/project_services/drone_ci_service.rb @@ -39,7 +39,7 @@ class DroneCiService < CiService def commit_status_path(sha, ref) url = [drone_url, "gitlab/#{project.full_path}/commits/#{sha}", - "?branch=#{URI::encode(ref.to_s)}&access_token=#{token}"] + "?branch=#{URI.encode(ref.to_s)}&access_token=#{token}"] URI.join(*url).to_s end @@ -74,7 +74,7 @@ class DroneCiService < CiService def build_page(sha, ref) url = [drone_url, "gitlab/#{project.full_path}/redirect/commits/#{sha}", - "?branch=#{URI::encode(ref.to_s)}"] + "?branch=#{URI.encode(ref.to_s)}"] URI.join(*url).to_s end diff --git a/app/models/repository.rb b/app/models/repository.rb index e2a4f458c50..32252957a84 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -892,7 +892,7 @@ class Repository def get_committer_and_author(user, email: nil, name: nil) committer = user_to_committer(user) - author = Gitlab::Git::committer_hash(email: email, name: name) || committer + author = Gitlab::Git.committer_hash(email: email, name: name) || committer { author: author, -- cgit v1.2.1 From 8a4d68c53e9c58ad7f8dce1494f7976292b2f929 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Feb 2017 19:02:23 -0600 Subject: Enable Style/ConditionalAssignment --- app/models/commit.rb | 6 +++--- app/models/concerns/case_sensitivity.rb | 6 +++--- app/models/concerns/sortable.rb | 6 +++--- app/models/network/graph.rb | 6 +++--- app/models/project.rb | 6 +++--- app/models/project_services/pushover_service.rb | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index 7afc8f4add8..feb35bb3e92 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -122,10 +122,10 @@ class Commit def full_title return @full_title if @full_title - if safe_message.blank? - @full_title = no_commit_message + @full_title = if safe_message.blank? + no_commit_message else - @full_title = safe_message.split("\n", 2).first + safe_message.split("\n", 2).first end end diff --git a/app/models/concerns/case_sensitivity.rb b/app/models/concerns/case_sensitivity.rb index fe0cea8465f..2cfb6127c96 100644 --- a/app/models/concerns/case_sensitivity.rb +++ b/app/models/concerns/case_sensitivity.rb @@ -13,10 +13,10 @@ module CaseSensitivity params.each do |key, value| column = ActiveRecord::Base.connection.quote_table_name(key) - if cast_lower - condition = "LOWER(#{column}) = LOWER(:value)" + condition = if cast_lower + "LOWER(#{column}) = LOWER(:value)" else - condition = "#{column} = :value" + "#{column} = :value" end criteria = criteria.where(condition, value: value) diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb index 7edb0acd56c..fdcb4f3ba64 100644 --- a/app/models/concerns/sortable.rb +++ b/app/models/concerns/sortable.rb @@ -46,10 +46,10 @@ module Sortable where("label_links.target_id = #{target_column}"). reorder(nil) - if target_type_column - query = query.where("label_links.target_type = #{target_type_column}") + query = if target_type_column + query.where("label_links.target_type = #{target_type_column}") else - query = query.where(label_links: { target_type: target_type }) + query.where(label_links: { target_type: target_type }) end query = query.where.not(title: excluded_labels) if excluded_labels.present? diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index b16ecc424dd..b859d40da24 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -188,10 +188,10 @@ module Network end # and mark it as reserved - if parent_time.nil? - min_time = leaves.first.time + min_time = if parent_time.nil? + leaves.first.time else - min_time = parent_time + 1 + parent_time + 1 end max_time = leaves.last.time diff --git a/app/models/project.rb b/app/models/project.rb index 0da21be8351..a0bc82af7d5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -453,12 +453,12 @@ class Project < ActiveRecord::Base end def add_import_job - if forked? - job_id = RepositoryForkWorker.perform_async(id, forked_from_project.repository_storage_path, + job_id = if forked? + RepositoryForkWorker.perform_async(id, forked_from_project.repository_storage_path, forked_from_project.path_with_namespace, self.namespace.full_path) else - job_id = RepositoryImportWorker.perform_async(self.id) + RepositoryImportWorker.perform_async(self.id) end if job_id diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index f623bf9851b..cd185f6e120 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -72,12 +72,12 @@ class PushoverService < Service before = data[:before] after = data[:after] - if Gitlab::Git.blank_ref?(before) - message = "#{data[:user_name]} pushed new branch \"#{ref}\"." + message = if Gitlab::Git.blank_ref?(before) + "#{data[:user_name]} pushed new branch \"#{ref}\"." elsif Gitlab::Git.blank_ref?(after) - message = "#{data[:user_name]} deleted branch \"#{ref}\"." + "#{data[:user_name]} deleted branch \"#{ref}\"." else - message = "#{data[:user_name]} push to branch \"#{ref}\"." + "#{data[:user_name]} push to branch \"#{ref}\"." end if data[:total_commits_count] > 0 -- cgit v1.2.1 From 5c7f9d69e3db27921acf6d8259245f2b4babcc2b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 09:10:32 -0600 Subject: Fix code for cops --- app/models/commit.rb | 11 ++++++----- app/models/concerns/case_sensitivity.rb | 11 ++++++----- app/models/concerns/sortable.rb | 11 ++++++----- app/models/network/graph.rb | 11 ++++++----- app/models/project.rb | 15 ++++++++------- app/models/project_services/pushover_service.rb | 15 ++++++++------- 6 files changed, 40 insertions(+), 34 deletions(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index feb35bb3e92..8f6179f183e 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -122,11 +122,12 @@ class Commit def full_title return @full_title if @full_title - @full_title = if safe_message.blank? - no_commit_message - else - safe_message.split("\n", 2).first - end + @full_title = + if safe_message.blank? + no_commit_message + else + safe_message.split("\n", 2).first + end end # Returns the commits description diff --git a/app/models/concerns/case_sensitivity.rb b/app/models/concerns/case_sensitivity.rb index 2cfb6127c96..034e9f40ff0 100644 --- a/app/models/concerns/case_sensitivity.rb +++ b/app/models/concerns/case_sensitivity.rb @@ -13,11 +13,12 @@ module CaseSensitivity params.each do |key, value| column = ActiveRecord::Base.connection.quote_table_name(key) - condition = if cast_lower - "LOWER(#{column}) = LOWER(:value)" - else - "#{column} = :value" - end + condition = + if cast_lower + "LOWER(#{column}) = LOWER(:value)" + else + "#{column} = :value" + end criteria = criteria.where(condition, value: value) end diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb index fdcb4f3ba64..b9a2d812edd 100644 --- a/app/models/concerns/sortable.rb +++ b/app/models/concerns/sortable.rb @@ -46,11 +46,12 @@ module Sortable where("label_links.target_id = #{target_column}"). reorder(nil) - query = if target_type_column - query.where("label_links.target_type = #{target_type_column}") - else - query.where(label_links: { target_type: target_type }) - end + query = + if target_type_column + query.where("label_links.target_type = #{target_type_column}") + else + query.where(label_links: { target_type: target_type }) + end query = query.where.not(title: excluded_labels) if excluded_labels.present? diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index b859d40da24..2a7fa7d0607 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -188,11 +188,12 @@ module Network end # and mark it as reserved - min_time = if parent_time.nil? - leaves.first.time - else - parent_time + 1 - end + min_time = + if parent_time.nil? + leaves.first.time + else + parent_time + 1 + end max_time = leaves.last.time leaves.last.parents(@map).each do |parent| diff --git a/app/models/project.rb b/app/models/project.rb index a0bc82af7d5..e75ba3abb98 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -453,13 +453,14 @@ class Project < ActiveRecord::Base end def add_import_job - job_id = if forked? - RepositoryForkWorker.perform_async(id, forked_from_project.repository_storage_path, - forked_from_project.path_with_namespace, - self.namespace.full_path) - else - RepositoryImportWorker.perform_async(self.id) - end + job_id = + if forked? + RepositoryForkWorker.perform_async(id, forked_from_project.repository_storage_path, + forked_from_project.path_with_namespace, + self.namespace.full_path) + else + RepositoryImportWorker.perform_async(self.id) + end if job_id Rails.logger.info "Import job started for #{path_with_namespace} with job ID #{job_id}" diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index cd185f6e120..f4106048345 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -72,13 +72,14 @@ class PushoverService < Service before = data[:before] after = data[:after] - message = if Gitlab::Git.blank_ref?(before) - "#{data[:user_name]} pushed new branch \"#{ref}\"." - elsif Gitlab::Git.blank_ref?(after) - "#{data[:user_name]} deleted branch \"#{ref}\"." - else - "#{data[:user_name]} push to branch \"#{ref}\"." - end + message = + if Gitlab::Git.blank_ref?(before) + "#{data[:user_name]} pushed new branch \"#{ref}\"." + elsif Gitlab::Git.blank_ref?(after) + "#{data[:user_name]} deleted branch \"#{ref}\"." + else + "#{data[:user_name]} push to branch \"#{ref}\"." + end if data[:total_commits_count] > 0 message << "\nTotal commits count: #{data[:total_commits_count]}" -- cgit v1.2.1 From 206953a430e442fbbd06984b1120890dbf8d3f79 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 10:55:08 -0600 Subject: Prefer leading style for Style/DotPosition --- app/models/award_emoji.rb | 6 +-- app/models/ci/build.rb | 22 ++++----- app/models/ci/pipeline.rb | 44 +++++++++--------- app/models/ci/runner.rb | 8 ++-- app/models/ci/stage.rb | 6 +-- app/models/commit_status.rb | 10 ++-- app/models/concerns/issuable.rb | 6 +-- app/models/concerns/mentionable.rb | 4 +- app/models/concerns/milestoneish.rb | 4 +- app/models/concerns/presentable.rb | 6 +-- app/models/concerns/routable.rb | 8 ++-- app/models/concerns/sortable.rb | 12 ++--- app/models/concerns/subscribable.rb | 26 +++++------ app/models/deployment.rb | 22 ++++----- app/models/environment.rb | 6 +-- app/models/event.rb | 6 +-- app/models/generic_commit_status.rb | 6 +-- app/models/global_milestone.rb | 4 +- app/models/group.rb | 10 ++-- app/models/issue_collection.rb | 6 +-- app/models/label.rb | 18 ++++---- app/models/lfs_object.rb | 6 +-- app/models/member.rb | 12 ++--- app/models/merge_request.rb | 18 ++++---- app/models/merge_request_diff.rb | 4 +- app/models/merge_requests_closing_issues.rb | 6 +-- app/models/milestone.rb | 14 +++--- app/models/namespace.rb | 14 +++--- app/models/network/commit.rb | 4 +- app/models/network/graph.rb | 12 ++--- app/models/note.rb | 10 ++-- app/models/project.rb | 22 ++++----- app/models/project_services/kubernetes_service.rb | 6 +-- .../mattermost_slash_commands_service.rb | 4 +- app/models/project_team.rb | 8 ++-- app/models/repository.rb | 12 ++--- app/models/todo.rb | 6 +-- app/models/user.rb | 54 +++++++++++----------- app/models/wiki_page.rb | 10 ++-- 39 files changed, 231 insertions(+), 231 deletions(-) (limited to 'app/models') diff --git a/app/models/award_emoji.rb b/app/models/award_emoji.rb index 6937ad3bdd9..2eedbf3ffde 100644 --- a/app/models/award_emoji.rb +++ b/app/models/award_emoji.rb @@ -18,9 +18,9 @@ class AwardEmoji < ActiveRecord::Base class << self def votes_for_collection(ids, type) - select('name', 'awardable_id', 'COUNT(*) as count'). - where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids). - group('name', 'awardable_id') + select('name', 'awardable_id', 'COUNT(*) as count') + .where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids) + .group('name', 'awardable_id') end end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index f9592873ea0..de9fe352059 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -63,9 +63,9 @@ module Ci end def retry(build, current_user) - Ci::RetryBuildService. - new(build.project, current_user). - execute(build) + Ci::RetryBuildService + .new(build.project, current_user) + .execute(build) end end @@ -96,9 +96,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Build::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Build::Factory + .new(self, current_user) + .fabricate! end def manual? @@ -220,9 +220,9 @@ module Ci end def merge_request - merge_requests = MergeRequest.includes(:merge_request_diff). - where(source_branch: ref, source_project_id: pipeline.gl_project_id). - reorder(iid: :asc) + merge_requests = MergeRequest.includes(:merge_request_diff) + .where(source_branch: ref, source_project_id: pipeline.gl_project_id) + .reorder(iid: :asc) merge_requests.find do |merge_request| merge_request.commits_sha.include?(pipeline.sha) @@ -278,8 +278,8 @@ module Ci def raw_trace(last_lines: nil) if File.exist?(trace_file_path) - Gitlab::Ci::TraceReader.new(trace_file_path). - read(last_lines: last_lines) + Gitlab::Ci::TraceReader.new(trace_file_path) + .read(last_lines: last_lines) else # backward compatibility read_attribute :trace diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 673647f284a..999720d2ea3 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -89,9 +89,9 @@ module Ci # ref can't be HEAD or SHA, can only be branch/tag name scope :latest, ->(ref = nil) do - max_id = unscope(:select). - select("max(#{quoted_table_name}.id)"). - group(:ref, :sha) + max_id = unscope(:select) + .select("max(#{quoted_table_name}.id)") + .group(:ref, :sha) if ref where(ref: ref, id: max_id.where(ref: ref)) @@ -126,23 +126,23 @@ module Ci end def stages_name - statuses.order(:stage_idx).distinct. - pluck(:stage, :stage_idx).map(&:first) + statuses.order(:stage_idx).distinct + .pluck(:stage, :stage_idx).map(&:first) end def stages # TODO, this needs refactoring, see gitlab-ce#26481. - stages_query = statuses. - group('stage').select(:stage).order('max(stage_idx)') + stages_query = statuses + .group('stage').select(:stage).order('max(stage_idx)') status_sql = statuses.latest.where('stage=sg.stage').status_sql - warnings_sql = statuses.latest.select('COUNT(*) > 0'). - where('stage=sg.stage').failed_but_allowed.to_sql + warnings_sql = statuses.latest.select('COUNT(*) > 0') + .where('stage=sg.stage').failed_but_allowed.to_sql - stages_with_statuses = CommitStatus.from(stages_query, :sg). - pluck('sg.stage', status_sql, "(#{warnings_sql})") + stages_with_statuses = CommitStatus.from(stages_query, :sg) + .pluck('sg.stage', status_sql, "(#{warnings_sql})") stages_with_statuses.map do |stage| Ci::Stage.new(self, Hash[%i[name status warnings].zip(stage)]) @@ -222,8 +222,8 @@ module Ci end def retry_failed(current_user) - Ci::RetryPipelineService.new(project, current_user). - execute(self) + Ci::RetryPipelineService.new(project, current_user) + .execute(self) end def mark_as_processable_after_stage(stage_idx) @@ -255,9 +255,9 @@ module Ci def config_builds_attributes return [] unless config_processor - config_processor. - builds_for_ref(ref, tag?, trigger_requests.first). - sort_by { |build| build[:stage_idx] } + config_processor + .builds_for_ref(ref, tag?, trigger_requests.first) + .sort_by { |build| build[:stage_idx] } end def has_warnings? @@ -355,15 +355,15 @@ module Ci # Merge requests for which the current pipeline is running against # the merge request's latest commit. def merge_requests - @merge_requests ||= project.merge_requests. - where(source_branch: self.ref). - select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } + @merge_requests ||= project.merge_requests + .where(source_branch: self.ref) + .select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } end def detailed_status(current_user) - Gitlab::Ci::Status::Pipeline::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Pipeline::Factory + .new(self, current_user) + .fabricate! end private diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index a120112e882..9cf6164e8dd 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -23,15 +23,15 @@ module Ci scope :ordered, ->() { order(id: :desc) } scope :owned_or_shared, ->(project_id) do - joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'). - where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) + joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id') + .where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) end scope :assignable_for, ->(project) do # FIXME: That `to_sql` is needed to workaround a weird Rails bug. # Without that, placeholders would miss one and couldn't match. - where(locked: false). - where.not("id IN (#{project.runners.select(:id).to_sql})").specific + where(locked: false) + .where.not("id IN (#{project.runners.select(:id).to_sql})").specific end validate :tag_constraints diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index 0751ab1b7d8..ca74c91b062 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -28,9 +28,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Stage::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Stage::Factory + .new(self, current_user) + .fabricate! end def statuses diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index ef5e6202519..df835b99189 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -96,8 +96,8 @@ class CommitStatus < ActiveRecord::Base after_transition any => :failed do |commit_status| commit_status.run_after_commit do - MergeRequests::AddTodoWhenBuildFailsService. - new(pipeline.project, nil).execute(self) + MergeRequests::AddTodoWhenBuildFailsService + .new(pipeline.project, nil).execute(self) end end end @@ -133,9 +133,9 @@ class CommitStatus < ActiveRecord::Base end def detailed_status(current_user) - Gitlab::Ci::Status::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Factory + .new(self, current_user) + .fabricate! end def sortable_name diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 768baa80c01..303d4910ee1 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -162,9 +162,9 @@ module Issuable highest_priority = highest_label_priority(params).to_sql - select("#{table_name}.*, (#{highest_priority}) AS highest_priority"). - group(arel_table[:id]). - reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) + select("#{table_name}.*, (#{highest_priority}) AS highest_priority") + .group(arel_table[:id]) + .reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) end def with_label(title, sort = nil) diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index 7e56e371b27..a8ce36e51fc 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -48,8 +48,8 @@ module Mentionable if extractor @extractor = extractor else - @extractor ||= Gitlab::ReferenceExtractor. - new(project, current_user) + @extractor ||= Gitlab::ReferenceExtractor + .new(project, current_user) @extractor.reset_memoized_values end diff --git a/app/models/concerns/milestoneish.rb b/app/models/concerns/milestoneish.rb index 870a6fbaa90..f449229864d 100644 --- a/app/models/concerns/milestoneish.rb +++ b/app/models/concerns/milestoneish.rb @@ -39,8 +39,8 @@ module Milestoneish def issues_visible_to_user(user) memoize_per_user(user, :issues_visible_to_user) do - IssuesFinder.new(user, issues_finder_params). - execute.where(milestone_id: milestoneish_ids) + IssuesFinder.new(user, issues_finder_params) + .execute.where(milestone_id: milestoneish_ids) end end diff --git a/app/models/concerns/presentable.rb b/app/models/concerns/presentable.rb index d0f84831d71..7b33b837004 100644 --- a/app/models/concerns/presentable.rb +++ b/app/models/concerns/presentable.rb @@ -1,7 +1,7 @@ module Presentable def present(**attributes) - Gitlab::View::Presenter::Factory. - new(self, attributes). - fabricate! + Gitlab::View::Presenter::Factory + .new(self, attributes) + .fabricate! end end diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 9f6d215ceb3..c2373de32c5 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -75,11 +75,11 @@ module Routable # # Returns an ActiveRecord::Relation. def member_descendants(user_id) - joins(:route). - joins("INNER JOIN routes r2 ON routes.path LIKE CONCAT(r2.path, '/%') + joins(:route) + .joins("INNER JOIN routes r2 ON routes.path LIKE CONCAT(r2.path, '/%') INNER JOIN members ON members.source_id = r2.source_id - AND members.source_type = r2.source_type"). - where('members.user_id = ?', user_id) + AND members.source_type = r2.source_type") + .where('members.user_id = ?', user_id) end end diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb index b9a2d812edd..a155a064032 100644 --- a/app/models/concerns/sortable.rb +++ b/app/models/concerns/sortable.rb @@ -39,12 +39,12 @@ module Sortable private def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: []) - query = Label.select(LabelPriority.arel_table[:priority].minimum). - left_join_priorities. - joins(:label_links). - where("label_priorities.project_id = #{project_column}"). - where("label_links.target_id = #{target_column}"). - reorder(nil) + query = Label.select(LabelPriority.arel_table[:priority].minimum) + .left_join_priorities + .joins(:label_links) + .where("label_priorities.project_id = #{project_column}") + .where("label_links.target_id = #{target_column}") + .reorder(nil) query = if target_type_column diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb index e4f5818d0e3..f60a0f8f438 100644 --- a/app/models/concerns/subscribable.rb +++ b/app/models/concerns/subscribable.rb @@ -27,30 +27,30 @@ module Subscribable end def subscribers(project) - subscriptions_available(project). - where(subscribed: true). - map(&:user) + subscriptions_available(project) + .where(subscribed: true) + .map(&:user) end def toggle_subscription(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project). - update(subscribed: !subscribed?(user, project)) + find_or_initialize_subscription(user, project) + .update(subscribed: !subscribed?(user, project)) end def subscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project). - update(subscribed: true) + find_or_initialize_subscription(user, project) + .update(subscribed: true) end def unsubscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project). - update(subscribed: false) + find_or_initialize_subscription(user, project) + .update(subscribed: false) end private @@ -69,14 +69,14 @@ module Subscribable end def find_or_initialize_subscription(user, project) - subscriptions. - find_or_initialize_by(user_id: user.id, project_id: project.try(:id)) + subscriptions + .find_or_initialize_by(user_id: user.id, project_id: project.try(:id)) end def subscriptions_available(project) t = Subscription.arel_table - subscriptions. - where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id)))) + subscriptions + .where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id)))) end end diff --git a/app/models/deployment.rb b/app/models/deployment.rb index afad001d50f..43f7460bd5d 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -53,10 +53,10 @@ class Deployment < ActiveRecord::Base def update_merge_request_metrics! return unless environment.update_merge_request_metrics? - merge_requests = project.merge_requests. - joins(:metrics). - where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }). - where("merge_request_metrics.merged_at <= ?", self.created_at) + merge_requests = project.merge_requests + .joins(:metrics) + .where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }) + .where("merge_request_metrics.merged_at <= ?", self.created_at) if previous_deployment merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at) @@ -71,17 +71,17 @@ class Deployment < ActiveRecord::Base merge_requests.map(&:id) end - MergeRequest::Metrics. - where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil). - update_all(first_deployed_to_production_at: self.created_at) + MergeRequest::Metrics + .where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil) + .update_all(first_deployed_to_production_at: self.created_at) end def previous_deployment @previous_deployment ||= - project.deployments.joins(:environment). - where(environments: { name: self.environment.name }, ref: self.ref). - where.not(id: self.id). - take + project.deployments.joins(:environment) + .where(environments: { name: self.environment.name }, ref: self.ref) + .where.not(id: self.id) + .take end def stop_action diff --git a/app/models/environment.rb b/app/models/environment.rb index 1a21b5e52b5..f917f52f832 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -40,9 +40,9 @@ class Environment < ActiveRecord::Base scope :stopped, -> { with_state(:stopped) } scope :order_by_last_deployed_at, -> do max_deployment_id_sql = - Deployment.select(Deployment.arel_table[:id].maximum). - where(Deployment.arel_table[:environment_id].eq(arel_table[:id])). - to_sql + Deployment.select(Deployment.arel_table[:id].maximum) + .where(Deployment.arel_table[:environment_id].eq(arel_table[:id])) + .to_sql order(Gitlab::Database.nulls_first_order("(#{max_deployment_id_sql})", 'ASC')) end diff --git a/app/models/event.rb b/app/models/event.rb index e5027df3f8a..42c4a233ce3 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -343,9 +343,9 @@ class Event < ActiveRecord::Base # At this point it's possible for multiple threads/processes to try to # update the project. Only one query should actually perform the update, # hence we add the extra WHERE clause for last_activity_at. - Project.unscoped.where(id: project_id). - where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago). - update_all(last_activity_at: created_at) + Project.unscoped.where(id: project_id) + .where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago) + .update_all(last_activity_at: created_at) end def authored_by?(user) diff --git a/app/models/generic_commit_status.rb b/app/models/generic_commit_status.rb index 36b8568871b..8867ba0d2ff 100644 --- a/app/models/generic_commit_status.rb +++ b/app/models/generic_commit_status.rb @@ -18,8 +18,8 @@ class GenericCommitStatus < CommitStatus end def detailed_status(current_user) - Gitlab::Ci::Status::External::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::External::Factory + .new(self, current_user) + .fabricate! end end diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index 84deb67ba9b..b991d78e27f 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -76,8 +76,8 @@ class GlobalMilestone end def labels - @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten). - sort_by!(&:title) + @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten) + .sort_by!(&:title) end def due_date diff --git a/app/models/group.rb b/app/models/group.rb index 1835ce118a1..5ef3f9513fc 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -71,9 +71,9 @@ class Group < Namespace def select_for_project_authorization if current_scope.joins_values.include?(:shared_projects) - joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id'). - where('project_namespace.share_with_group_lock = ?', false). - select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") + joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id') + .where('project_namespace.share_with_group_lock = ?', false) + .select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") else super end @@ -197,8 +197,8 @@ class Group < Namespace end def refresh_members_authorized_projects - UserProjectAccessChangedService.new(user_ids_for_project_authorizations). - execute + UserProjectAccessChangedService.new(user_ids_for_project_authorizations) + .execute end def user_ids_for_project_authorizations diff --git a/app/models/issue_collection.rb b/app/models/issue_collection.rb index f0b7d9914c8..49f011c113f 100644 --- a/app/models/issue_collection.rb +++ b/app/models/issue_collection.rb @@ -17,9 +17,9 @@ class IssueCollection # Given all the issue projects we get a list of projects that the current # user has at least reporter access to. - projects_with_reporter_access = user. - projects_with_reporter_access_limited_to(project_ids). - pluck(:id) + projects_with_reporter_access = user + .projects_with_reporter_access_limited_to(project_ids) + .pluck(:id) collection.select do |issue| if projects_with_reporter_access.include?(issue.project_id) diff --git a/app/models/label.rb b/app/models/label.rb index 27429e60e4a..e97e53301cc 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -34,18 +34,18 @@ class Label < ActiveRecord::Base scope :with_title, ->(title) { where(title: title) } def self.prioritized(project) - joins(:priorities). - where(label_priorities: { project_id: project }). - reorder('label_priorities.priority ASC, labels.title ASC') + joins(:priorities) + .where(label_priorities: { project_id: project }) + .reorder('label_priorities.priority ASC, labels.title ASC') end def self.unprioritized(project) labels = Label.arel_table priorities = LabelPriority.arel_table - label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin). - on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))). - join_sources + label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin) + .on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))) + .join_sources joins(label_priorities).where(priorities[:priority].eq(nil)) end @@ -54,9 +54,9 @@ class Label < ActiveRecord::Base labels = Label.arel_table priorities = LabelPriority.arel_table - label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin). - on(labels[:id].eq(priorities[:label_id])). - join_sources + label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin) + .on(labels[:id].eq(priorities[:label_id])) + .join_sources joins(label_priorities) end diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb index ee9ac282e39..7712d5783e0 100644 --- a/app/models/lfs_object.rb +++ b/app/models/lfs_object.rb @@ -19,8 +19,8 @@ class LfsObject < ActiveRecord::Base end def self.destroy_unreferenced - joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id"). - where(lfs_objects_projects: { id: nil }). - destroy_all + joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") + .where(lfs_objects_projects: { id: nil }) + .destroy_all end end diff --git a/app/models/member.rb b/app/models/member.rb index 0f6b75b0b93..2ea4abacea4 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -39,9 +39,9 @@ class Member < ActiveRecord::Base is_external_invite = arel_table[:user_id].eq(nil).and(arel_table[:invite_token].not_eq(nil)) user_is_active = User.arel_table[:state].eq(:active) - includes(:user).references(:users). - where(is_external_invite.or(user_is_active)). - where(requested_at: nil) + includes(:user).references(:users) + .where(is_external_invite.or(user_is_active)) + .where(requested_at: nil) end scope :invite, -> { where.not(invite_token: nil) } @@ -99,9 +99,9 @@ class Member < ActiveRecord::Base users = User.arel_table members = Member.arel_table - member_users = members.join(users, Arel::Nodes::OuterJoin). - on(members[:user_id].eq(users[:id])). - join_sources + member_users = members.join(users, Arel::Nodes::OuterJoin) + .on(members[:user_id].eq(users[:id])) + .join_sources joins(member_users) end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ea784f77015..c4520c16a43 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -475,10 +475,10 @@ class MergeRequest < ActiveRecord::Base end def discussions - @discussions ||= self.related_notes. - inc_relations_for_view. - fresh. - discussions + @discussions ||= self.related_notes + .inc_relations_for_view + .fresh + .discussions end def diff_discussions @@ -564,8 +564,8 @@ class MergeRequest < ActiveRecord::Base messages = [title, description] messages.concat(commits.map(&:safe_message)) if merge_request_diff - Gitlab::ClosingIssueExtractor.new(project, current_user). - closed_by_message(messages.join("\n")) + Gitlab::ClosingIssueExtractor.new(project, current_user) + .closed_by_message(messages.join("\n")) else [] end @@ -813,9 +813,9 @@ class MergeRequest < ActiveRecord::Base def all_pipelines return Ci::Pipeline.none unless source_project - @all_pipelines ||= source_project.pipelines. - where(sha: all_commits_sha, ref: source_branch). - order(id: :desc) + @all_pipelines ||= source_project.pipelines + .where(sha: all_commits_sha, ref: source_branch) + .order(id: :desc) end # Note that this could also return SHA from now dangling commits diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 53d08488788..baee00b8fcd 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -169,8 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base # 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: straight) + CompareService.new(project, head_commit_sha) + .execute(project, sha, straight: straight) end def commits_count diff --git a/app/models/merge_requests_closing_issues.rb b/app/models/merge_requests_closing_issues.rb index daafb137be4..7f7c114803d 100644 --- a/app/models/merge_requests_closing_issues.rb +++ b/app/models/merge_requests_closing_issues.rb @@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base class << self def count_for_collection(ids) - group(:issue_id). - where(issue_id: ids). - pluck('issue_id', 'COUNT(*) as count') + group(:issue_id) + .where(issue_id: ids) + .pluck('issue_id', 'COUNT(*) as count') end end end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 7331000a9f2..30e5dfd096e 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -98,11 +98,11 @@ class Milestone < ActiveRecord::Base if Gitlab::Database.postgresql? rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id') else - rel. - group(:project_id). - having('due_date = MIN(due_date)'). - pluck(:id, :project_id, :due_date). - map(&:first) + rel + .group(:project_id) + .having('due_date = MIN(due_date)') + .pluck(:id, :project_id, :due_date) + .map(&:first) end end @@ -177,8 +177,8 @@ class Milestone < ActiveRecord::Base conditions = 'WHEN id = ? THEN ? ' * ids.length - issues.where(id: ids). - update_all(["position = CASE #{conditions} ELSE position END", *pairs]) + issues.where(id: ids) + .update_all(["position = CASE #{conditions} ELSE position END", *pairs]) end private diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e207ac3db4e..9334b7d9e61 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -48,9 +48,9 @@ class Namespace < ActiveRecord::Base scope :root, -> { where('type IS NULL') } scope :with_statistics, -> do - joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id'). - group('namespaces.id'). - select( + joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id') + .group('namespaces.id') + .select( 'namespaces.*', 'COALESCE(SUM(ps.storage_size), 0) AS storage_size', 'COALESCE(SUM(ps.repository_size), 0) AS repository_size', @@ -251,10 +251,10 @@ class Namespace < ActiveRecord::Base end def refresh_access_of_projects_invited_groups - Group. - joins(project_group_links: :project). - where(projects: { namespace_id: id }). - find_each(&:refresh_members_authorized_projects) + Group + .joins(project_group_links: :project) + .where(projects: { namespace_id: id }) + .find_each(&:refresh_members_authorized_projects) end def remove_exports! diff --git a/app/models/network/commit.rb b/app/models/network/commit.rb index a48e872ad84..8417f200e36 100644 --- a/app/models/network/commit.rb +++ b/app/models/network/commit.rb @@ -28,8 +28,8 @@ module Network if map.include?(p.id) map[p.id] end - end. - compact + end + .compact end end end diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index 2a7fa7d0607..0bbc9451ffd 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -23,12 +23,12 @@ module Network def collect_notes h = Hash.new(0) - @project. - notes. - where('noteable_type = ?', 'Commit'). - group('notes.commit_id'). - select('notes.commit_id, count(notes.id) as note_count'). - each do |item| + @project + .notes + .where('noteable_type = ?', 'Commit') + .group('notes.commit_id') + .select('notes.commit_id, count(notes.id) as note_count') + .each do |item| h[item.commit_id] = item.note_count.to_i end diff --git a/app/models/note.rb b/app/models/note.rb index 029fe667a45..4f87b9a4dc2 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -105,14 +105,14 @@ class Note < ActiveRecord::Base def grouped_diff_discussions active_notes = diff_notes.fresh.select(&:active?) - Discussion.for_diff_notes(active_notes). - map { |d| [d.line_code, d] }.to_h + Discussion.for_diff_notes(active_notes) + .map { |d| [d.line_code, d] }.to_h end def count_for_collection(ids, type) - user.select('noteable_id', 'COUNT(*) as count'). - group(:noteable_id). - where(noteable_type: type, noteable_id: ids) + user.select('noteable_id', 'COUNT(*) as count') + .group(:noteable_id) + .where(noteable_type: type, noteable_id: ids) end end diff --git a/app/models/project.rb b/app/models/project.rb index e75ba3abb98..f2be9e6a80c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -233,8 +233,8 @@ class Project < ActiveRecord::Base scope :inside_path, ->(path) do # We need routes alias rs for JOIN so it does not conflict with # includes(:route) which we use in ProjectsFinder. - joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'"). - where('rs.path LIKE ?', "#{path}/%") + joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'") + .where('rs.path LIKE ?', "#{path}/%") end # "enabled" here means "not disabled". It includes private features! @@ -311,9 +311,9 @@ class Project < ActiveRecord::Base pattern = "%#{query}%" projects = select(:id).where( - ptable[:path].matches(pattern). - or(ptable[:name].matches(pattern)). - or(ptable[:description].matches(pattern)) + ptable[:path].matches(pattern) + .or(ptable[:name].matches(pattern)) + .or(ptable[:description].matches(pattern)) ) # We explicitly remove any eager loading clauses as they're: @@ -322,10 +322,10 @@ class Project < ActiveRecord::Base # 2. Combined with .joins(:namespace) lead to all columns from the # projects & namespaces tables being selected, leading to a SQL error # due to the columns of all UNION'd queries no longer being the same. - namespaces = select(:id). - except(:includes). - joins(:namespace). - where(ntable[:name].matches(pattern)) + namespaces = select(:id) + .except(:includes) + .joins(:namespace) + .where(ntable[:name].matches(pattern)) union = Gitlab::SQL::Union.new([projects, namespaces]) @@ -367,8 +367,8 @@ class Project < ActiveRecord::Base end def trending - joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id'). - reorder('trending_projects.id ASC') + joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id') + .reorder('trending_projects.id ASC') end def cached_count diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb index eb5019c08b5..caf71676837 100644 --- a/app/models/project_services/kubernetes_service.rb +++ b/app/models/project_services/kubernetes_service.rb @@ -109,9 +109,9 @@ class KubernetesService < DeploymentService def terminals(environment) with_reactive_cache do |data| pods = data.fetch(:pods, nil) - filter_pods(pods, app: environment.slug). - flat_map { |pod| terminals_for_pod(api_url, namespace, pod) }. - each { |terminal| add_terminal_auth(terminal, terminal_auth) } + filter_pods(pods, app: environment.slug) + .flat_map { |pod| terminals_for_pod(api_url, namespace, pod) } + .each { |terminal| add_terminal_auth(terminal, terminal_auth) } end end diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb index 56f42d63b2d..26376fd87ff 100644 --- a/app/models/project_services/mattermost_slash_commands_service.rb +++ b/app/models/project_services/mattermost_slash_commands_service.rb @@ -20,8 +20,8 @@ class MattermostSlashCommandsService < ChatSlashCommandsService end def configure(user, params) - token = Mattermost::Command.new(user). - create(command(params)) + token = Mattermost::Command.new(user) + .create(command(params)) update(active: true, token: token) if token rescue Mattermost::Error => e diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 8a53e974b6f..67cc06642f1 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -169,10 +169,10 @@ class ProjectTeam # Lookup only the IDs we need user_ids = user_ids - access.keys - users_access = project.project_authorizations. - where(user: user_ids). - group(:user_id). - maximum(:access_level) + users_access = project.project_authorizations + .where(user: user_ids) + .group(:user_id) + .maximum(:access_level) access.merge!(users_access) access diff --git a/app/models/repository.rb b/app/models/repository.rb index 32252957a84..7113879417e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -249,11 +249,11 @@ class Repository cache.fetch(:"diverging_commit_counts_#{branch.name}") do # Rugged seems to throw a `ReferenceError` when given branch_names rather # than SHA-1 hashes - number_commits_behind = raw_repository. - count_commits_between(branch.dereferenced_target.sha, root_ref_hash) + number_commits_behind = raw_repository + .count_commits_between(branch.dereferenced_target.sha, root_ref_hash) - number_commits_ahead = raw_repository. - count_commits_between(root_ref_hash, branch.dereferenced_target.sha) + number_commits_ahead = raw_repository + .count_commits_between(root_ref_hash, branch.dereferenced_target.sha) { behind: number_commits_behind, ahead: number_commits_ahead } end @@ -759,8 +759,8 @@ class Repository check_tree_entry_for_dir(branch_name, path) if start_branch_name - start_project.repository. - check_tree_entry_for_dir(start_branch_name, path) + start_project.repository + .check_tree_entry_for_dir(start_branch_name, path) end commit_file( diff --git a/app/models/todo.rb b/app/models/todo.rb index 47789a21133..32bb9bf2045 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -64,9 +64,9 @@ class Todo < ActiveRecord::Base highest_priority = highest_label_priority(params).to_sql - select("#{table_name}.*, (#{highest_priority}) AS highest_priority"). - order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')). - order('todos.created_at') + select("#{table_name}.*, (#{highest_priority}) AS highest_priority") + .order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) + .order('todos.created_at') end end diff --git a/app/models/user.rb b/app/models/user.rb index f37735c5eba..296bcc699a9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -197,13 +197,13 @@ class User < ActiveRecord::Base scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) } def self.with_two_factor - joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). - where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id]) + joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id") + .where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id]) end def self.without_two_factor - joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). - where("u2f.id IS NULL AND otp_required_for_login = ?", false) + joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id") + .where("u2f.id IS NULL AND otp_required_for_login = ?", false) end # @@ -274,9 +274,9 @@ class User < ActiveRecord::Base pattern = "%#{query}%" where( - table[:name].matches(pattern). - or(table[:email].matches(pattern)). - or(table[:username].matches(pattern)) + table[:name].matches(pattern) + .or(table[:email].matches(pattern)) + .or(table[:username].matches(pattern)) ) end @@ -291,10 +291,10 @@ class User < ActiveRecord::Base matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern)) where( - table[:name].matches(pattern). - or(table[:email].matches(pattern)). - or(table[:username].matches(pattern)). - or(table[:id].in(matched_by_emails_user_ids)) + table[:name].matches(pattern) + .or(table[:email].matches(pattern)) + .or(table[:username].matches(pattern)) + .or(table[:id].in(matched_by_emails_user_ids)) ) end @@ -447,8 +447,8 @@ class User < ActiveRecord::Base # Returns the groups a user has access to def authorized_groups - union = Gitlab::SQL::Union. - new([groups.select(:id), authorized_projects.select(:namespace_id)]) + union = Gitlab::SQL::Union + .new([groups.select(:id), authorized_projects.select(:namespace_id)]) Group.where("namespaces.id IN (#{union.to_sql})") end @@ -458,8 +458,8 @@ class User < ActiveRecord::Base end def nested_projects - Project.joins(:namespace).where('namespaces.parent_id IS NOT NULL'). - member_descendants(id) + Project.joins(:namespace).where('namespaces.parent_id IS NOT NULL') + .member_descendants(id) end def refresh_authorized_projects @@ -579,8 +579,8 @@ class User < ActiveRecord::Base next unless project if project.repository.branch_exists?(event.branch_name) - merge_requests = MergeRequest.where("created_at >= ?", event.created_at). - where(source_project_id: project.id, + merge_requests = MergeRequest.where("created_at >= ?", event.created_at) + .where(source_project_id: project.id, source_branch: event.branch_name) merge_requests.empty? end @@ -793,8 +793,8 @@ class User < ActiveRecord::Base def toggle_star(project) UsersStarProject.transaction do - user_star_project = users_star_projects. - where(project: project, user: self).lock(true).first + user_star_project = users_star_projects + .where(project: project, user: self).lock(true).first if user_star_project user_star_project.destroy @@ -830,11 +830,11 @@ class User < ActiveRecord::Base # ms on a database with a similar size to GitLab.com's database. On the other # hand, using a subquery means we can get the exact same data in about 40 ms. def contributed_projects - events = Event.select(:project_id). - contributions.where(author_id: self). - where("created_at > ?", Time.now - 1.year). - uniq. - reorder(nil) + events = Event.select(:project_id) + .contributions.where(author_id: self) + .where("created_at > ?", Time.now - 1.year) + .uniq + .reorder(nil) Project.where(id: events) end @@ -845,9 +845,9 @@ class User < ActiveRecord::Base def ci_authorized_runners @ci_authorized_runners ||= begin - runner_ids = Ci::RunnerProject. - where("ci_runner_projects.gl_project_id IN (#{ci_projects_union.to_sql})"). - select(:runner_id) + runner_ids = Ci::RunnerProject + .where("ci_runner_projects.gl_project_id IN (#{ci_projects_union.to_sql})") + .select(:runner_id) Ci::Runner.specific.where(id: runner_ids) end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 2caebb496db..0fa9d77a771 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -22,16 +22,16 @@ class WikiPage def self.group_by_directory(pages) return [] if pages.blank? - pages.sort_by { |page| [page.directory, page.slug] }. - group_by(&:directory). - map do |dir, pages| + pages.sort_by { |page| [page.directory, page.slug] } + .group_by(&:directory) + .map do |dir, pages| if dir.present? WikiDirectory.new(dir, pages) else pages end - end. - flatten + end + .flatten end def self.unhyphenize(name) -- cgit v1.2.1 From f74ca33a32fbf810b377cf480e996fb383d8f400 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 11:25:50 -0600 Subject: Enable Style/ClassCheck --- app/models/ci/build.rb | 2 +- app/models/commit.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index de9fe352059..7e21eb22e27 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -257,7 +257,7 @@ module Ci return unless regex matches = text.scan(Regexp.new(regex)).last - matches = matches.last if matches.kind_of?(Array) + matches = matches.last if matches.is_a?(Array) coverage = matches.gsub(/\d+(\.\d+)?/).first if coverage.present? diff --git a/app/models/commit.rb b/app/models/commit.rb index 8f6179f183e..dc971e710ff 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -27,7 +27,7 @@ class Commit class << self def decorate(commits, project) commits.map do |commit| - if commit.kind_of?(Commit) + if commit.is_a?(Commit) commit else self.new(commit, project) -- cgit v1.2.1 From eacae00516ffe534f197eeca20655cbc0fdf5694 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 11:44:44 -0600 Subject: Enable Style/MultilineHashBraceLayout --- app/models/project_services/chat_message/issue_message.rb | 3 ++- app/models/project_services/irker_service.rb | 3 ++- app/models/project_services/kubernetes_service.rb | 12 ++++-------- app/models/project_services/pushover_service.rb | 6 ++---- 4 files changed, 10 insertions(+), 14 deletions(-) (limited to 'app/models') diff --git a/app/models/project_services/chat_message/issue_message.rb b/app/models/project_services/chat_message/issue_message.rb index b96aca47e65..791e5b0cec7 100644 --- a/app/models/project_services/chat_message/issue_message.rb +++ b/app/models/project_services/chat_message/issue_message.rb @@ -51,7 +51,8 @@ module ChatMessage title: issue_title, title_link: issue_url, text: format(description), - color: "#C95823" }] + color: "#C95823" + }] end def project_link diff --git a/app/models/project_services/irker_service.rb b/app/models/project_services/irker_service.rb index 5d6862d9faa..c62bb4fa120 100644 --- a/app/models/project_services/irker_service.rb +++ b/app/models/project_services/irker_service.rb @@ -33,7 +33,8 @@ class IrkerService < Service end def settings - { server_host: server_host.present? ? server_host : 'localhost', + { + server_host: server_host.present? ? server_host : 'localhost', server_port: server_port.present? ? server_port : 6659 } end diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb index caf71676837..02e802bad6d 100644 --- a/app/models/project_services/kubernetes_service.rb +++ b/app/models/project_services/kubernetes_service.rb @@ -62,23 +62,19 @@ class KubernetesService < DeploymentService { type: 'text', name: 'namespace', title: 'Kubernetes namespace', - placeholder: 'Kubernetes namespace', - }, + placeholder: 'Kubernetes namespace' }, { type: 'text', name: 'api_url', title: 'API URL', - placeholder: 'Kubernetes API URL, like https://kube.example.com/', - }, + placeholder: 'Kubernetes API URL, like https://kube.example.com/' }, { type: 'text', name: 'token', title: 'Service token', - placeholder: 'Service token', - }, + placeholder: 'Service token' }, { type: 'textarea', name: 'ca_pem', title: 'Custom CA bundle', - placeholder: 'Certificate Authority bundle (PEM format)', - }, + placeholder: 'Certificate Authority bundle (PEM format)' }, ] end diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index f4106048345..508d3a5f2fa 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -29,8 +29,7 @@ class PushoverService < Service ['Normal Priority', 0], ['High Priority', 1] ], - default_choice: 0 - }, + default_choice: 0 }, { type: 'select', name: 'sound', choices: [ ['Device default sound', nil], @@ -56,8 +55,7 @@ class PushoverService < Service ['Pushover Echo (long)', 'echo'], ['Up Down (long)', 'updown'], ['None (silent)', 'none'] - ] - }, + ]}, ] end -- cgit v1.2.1 From 7d4b52b27dcbe30d85d4fad27e983cee51cf6677 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 11:46:57 -0600 Subject: Enable Style/WordArray --- app/models/concerns/issuable.rb | 2 +- app/models/diff_note.rb | 2 +- app/models/event.rb | 2 +- app/models/note.rb | 2 +- app/models/project_services/drone_ci_service.rb | 2 +- app/models/project_services/hipchat_service.rb | 2 +- app/models/project_services/pushover_service.rb | 22 +++++++++++----------- 7 files changed, 17 insertions(+), 17 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 303d4910ee1..8b33e776e87 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -182,7 +182,7 @@ module Issuable def grouping_columns(sort) grouping_columns = [arel_table[:id]] - if ["milestone_due_desc", "milestone_due_asc"].include?(sort) + if %w(milestone_due_desc milestone_due_asc).include?(sort) milestone_table = Milestone.arel_table grouping_columns << milestone_table[:id] grouping_columns << milestone_table[:due_date] diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index 559b3075905..895a91139c9 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -8,7 +8,7 @@ class DiffNote < Note validates :position, presence: true validates :diff_line, presence: true validates :line_code, presence: true, line_code: true - validates :noteable_type, inclusion: { in: ['Commit', 'MergeRequest'] } + validates :noteable_type, inclusion: { in: %w(Commit MergeRequest) } validates :resolved_by, presence: true, if: :resolved? validate :positions_complete validate :verify_supported diff --git a/app/models/event.rb b/app/models/event.rb index 42c4a233ce3..b8918fcda21 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -47,7 +47,7 @@ class Event < ActiveRecord::Base def contributions where("action = ? OR (target_type IN (?) AND action IN (?)) OR (target_type = ? AND action = ?)", Event::PUSHED, - ["MergeRequest", "Issue"], [Event::CREATED, Event::CLOSED, Event::MERGED], + %w(MergeRequest Issue), [Event::CREATED, Event::CLOSED, Event::MERGED], "Note", Event::COMMENTED) end diff --git a/app/models/note.rb b/app/models/note.rb index 4f87b9a4dc2..c6406f644e0 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -72,7 +72,7 @@ class Note < ActiveRecord::Base scope :inc_author, ->{ includes(:author) } scope :inc_relations_for_view, ->{ includes(:project, :author, :updated_by, :resolved_by, :award_emoji) } - scope :diff_notes, ->{ where(type: ['LegacyDiffNote', 'DiffNote']) } + scope :diff_notes, ->{ where(type: %w(LegacyDiffNote DiffNote)) } scope :non_diff_notes, ->{ where(type: ['Note', nil]) } scope :with_associations, -> do diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb index cd55194e291..2717c240f05 100644 --- a/app/models/project_services/drone_ci_service.rb +++ b/app/models/project_services/drone_ci_service.rb @@ -114,7 +114,7 @@ class DroneCiService < CiService end def merge_request_valid?(data) - ['opened', 'reopened'].include?(data[:object_attributes][:state]) && + %w(opened reopened).include?(data[:object_attributes][:state]) && data[:object_attributes][:merge_status] == 'unchecked' end end diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index 3fdcee26bf3..c4142c38b2f 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -36,7 +36,7 @@ class HipchatService < Service { type: 'text', name: 'token', placeholder: 'Room token' }, { type: 'text', name: 'room', placeholder: 'Room name or ID' }, { type: 'checkbox', name: 'notify' }, - { type: 'select', name: 'color', choices: ['yellow', 'red', 'green', 'purple', 'gray', 'random'] }, + { type: 'select', name: 'color', choices: %w(yellow red green purple gray random) }, { type: 'text', name: 'api_version', placeholder: 'Leave blank for default (v2)' }, { type: 'text', name: 'server', diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index 508d3a5f2fa..689bf03f469 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -34,19 +34,19 @@ class PushoverService < Service [ ['Device default sound', nil], ['Pushover (default)', 'pushover'], - ['Bike', 'bike'], - ['Bugle', 'bugle'], + %w(Bike bike), + %w(Bugle bugle), ['Cash Register', 'cashregister'], - ['Classical', 'classical'], - ['Cosmic', 'cosmic'], - ['Falling', 'falling'], - ['Gamelan', 'gamelan'], - ['Incoming', 'incoming'], - ['Intermission', 'intermission'], - ['Magic', 'magic'], - ['Mechanical', 'mechanical'], + %w(Classical classical), + %w(Cosmic cosmic), + %w(Falling falling), + %w(Gamelan gamelan), + %w(Incoming incoming), + %w(Intermission intermission), + %w(Magic magic), + %w(Mechanical mechanical), ['Piano Bar', 'pianobar'], - ['Siren', 'siren'], + %w(Siren siren), ['Space Alarm', 'spacealarm'], ['Tug Boat', 'tugboat'], ['Alien Alarm (long)', 'alien'], -- cgit v1.2.1 From 75f5fa997de148c9bc0e5bd6e6f6050526a0b164 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 11:51:46 -0600 Subject: Enable Rails/Delegate --- app/models/ci/build.rb | 4 +--- app/models/ci/pipeline.rb | 4 +--- app/models/project.rb | 8 ++------ app/models/project_wiki.rb | 8 ++------ app/models/repository.rb | 8 ++------ 5 files changed, 8 insertions(+), 24 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 7e21eb22e27..d2a53315f1d 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -233,9 +233,7 @@ module Ci gl_project_id end - def project_name - project.name - end + delegate :name, to: :project, prefix: true def repo_url auth = "gitlab-ci-token:#{ensure_token!}@" diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 999720d2ea3..d2312215f85 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -153,9 +153,7 @@ module Ci builds.latest.with_artifacts_not_expired.includes(project: [:namespace]) end - def project_id - project.id - end + delegate :id, to: :project, prefix: true # For now the only user who participates is the user who triggered def participants(_current_user = nil) diff --git a/app/models/project.rb b/app/models/project.rb index f2be9e6a80c..a1b29d335b3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -838,9 +838,7 @@ class Project < ActiveRecord::Base false end - def empty_repo? - repository.empty_repo? - end + delegate :empty_repo?, to: :repository def repo repository.raw @@ -1029,9 +1027,7 @@ class Project < ActiveRecord::Base forked? && project == forked_from_project end - def forks_count - forks.count - end + delegate :count, to: :forks, prefix: true def origin_merge_requests merge_requests.where(source_project_id: self.id) diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index de36fd3b252..2f55b853232 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -60,9 +60,7 @@ class ProjectWiki !!repository.exists? end - def empty? - pages.empty? - end + delegate :empty?, to: :pages # Returns an Array of Gitlab WikiPage instances or an # empty Array if this Wiki has no pages. @@ -160,9 +158,7 @@ class ProjectWiki } end - def repository_storage_path - project.repository_storage_path - end + delegate :repository_storage_path, to: :project private diff --git a/app/models/repository.rb b/app/models/repository.rb index 7113879417e..d1dd900d597 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -487,9 +487,7 @@ class Repository end cache_method :exists? - def empty? - raw_repository.empty? - end + delegate :empty?, to: :raw_repository cache_method :empty? # The size of this repository in megabytes. @@ -508,9 +506,7 @@ class Repository end cache_method :branch_names, fallback: [] - def tag_names - raw_repository.tag_names - end + delegate :tag_names, to: :raw_repository cache_method :tag_names, fallback: [] def branch_count -- cgit v1.2.1 From e2bbbb1a9aea72e4313cdc257460eb416fe8dc0b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 12:03:32 -0600 Subject: Fix new offenses --- app/models/project_services/pushover_service.rb | 2 +- app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/project_services/pushover_service.rb b/app/models/project_services/pushover_service.rb index 689bf03f469..3e618a8dbf1 100644 --- a/app/models/project_services/pushover_service.rb +++ b/app/models/project_services/pushover_service.rb @@ -55,7 +55,7 @@ class PushoverService < Service ['Pushover Echo (long)', 'echo'], ['Up Down (long)', 'updown'], ['None (silent)', 'none'] - ]}, + ] }, ] end diff --git a/app/models/user.rb b/app/models/user.rb index 296bcc699a9..801c84dc011 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -581,7 +581,7 @@ class User < ActiveRecord::Base if project.repository.branch_exists?(event.branch_name) merge_requests = MergeRequest.where("created_at >= ?", event.created_at) .where(source_project_id: project.id, - source_branch: event.branch_name) + source_branch: event.branch_name) merge_requests.empty? end end -- cgit v1.2.1 From 32a7041030dcb95d9476b3cbcc5d3c036aae81f3 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 15:36:16 -0600 Subject: ActiveSupport delegation is preferred over Forwardable --- app/models/concerns/cache_markdown_field.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index 6dc8c88a14d..8ea95beed79 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -11,14 +11,15 @@ module CacheMarkdownField # Knows about the relationship between markdown and html field names, and # stores the rendering contexts for the latter class FieldData - extend Forwardable - def initialize @data = {} end - def_delegators :@data, :[], :[]= - def_delegator :@data, :keys, :markdown_fields + delegate :[], :[]=, to: :@data + + def markdown_fields + @data.keys + end def html_field(markdown_field) "#{markdown_field}_html" -- cgit v1.2.1 From b3ff48c9a1d61b22ab4040ebcdc64eeeb797ad44 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 16:35:08 -0600 Subject: Move up delegate calls --- app/models/ci/build.rb | 4 ++-- app/models/ci/pipeline.rb | 4 ++-- app/models/commit_status.rb | 3 +-- app/models/concerns/issuable.rb | 22 +++++++++++----------- app/models/member.rb | 4 ++-- app/models/project.rb | 6 ++---- app/models/project_wiki.rb | 7 +++---- 7 files changed, 23 insertions(+), 27 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index d2a53315f1d..3a17d5c8dbe 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -22,6 +22,8 @@ module Ci serialize :options serialize :yaml_variables, Gitlab::Serializer::Ci::Variables + delegate :name, to: :project, prefix: true + validates :coverage, numericality: true, allow_blank: true validates :ref, presence: true @@ -233,8 +235,6 @@ module Ci gl_project_id end - delegate :name, to: :project, prefix: true - def repo_url auth = "gitlab-ci-token:#{ensure_token!}@" project.http_url_to_repo.sub(/^https?:\/\//) do |prefix| diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index d2312215f85..632178de887 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -14,6 +14,8 @@ module Ci has_many :builds, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id + delegate :id, to: :project, prefix: true + validates :sha, presence: { unless: :importing? } validates :ref, presence: { unless: :importing? } validates :status, presence: { unless: :importing? } @@ -153,8 +155,6 @@ module Ci builds.latest.with_artifacts_not_expired.includes(project: [:namespace]) end - delegate :id, to: :project, prefix: true - # For now the only user who participates is the user who triggered def participants(_current_user = nil) Array(user) diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index df835b99189..fc750a3e5e9 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -10,6 +10,7 @@ class CommitStatus < ActiveRecord::Base belongs_to :user delegate :commit, to: :pipeline + delegate :sha, :short_sha, to: :pipeline validates :pipeline, presence: true, unless: :importing? @@ -102,8 +103,6 @@ class CommitStatus < ActiveRecord::Base end end - delegate :sha, :short_sha, to: :pipeline - def before_sha pipeline.before_sha || Gitlab::Git::BLANK_SHA end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 8b33e776e87..fcb335e48d1 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -46,6 +46,17 @@ module Issuable has_one :metrics + delegate :name, + :email, + to: :author, + prefix: true + + delegate :name, + :email, + to: :assignee, + allow_nil: true, + prefix: true + validates :author, presence: true validates :title, presence: true, length: { maximum: 255 } @@ -72,17 +83,6 @@ module Issuable scope :references_project, -> { references(:project) } scope :non_archived, -> { join_project.where(projects: { archived: false }) } - delegate :name, - :email, - to: :author, - prefix: true - - delegate :name, - :email, - to: :assignee, - allow_nil: true, - prefix: true - attr_mentionable :title, pipeline: :single_line attr_mentionable :description diff --git a/app/models/member.rb b/app/models/member.rb index 2ea4abacea4..f198fbe9056 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -10,6 +10,8 @@ class Member < ActiveRecord::Base belongs_to :user belongs_to :source, polymorphic: true + delegate :name, :username, :email, to: :user, prefix: true + validates :user, presence: true, unless: :invite? validates :source, presence: true validates :user_id, uniqueness: { scope: [:source_type, :source_id], @@ -73,8 +75,6 @@ class Member < ActiveRecord::Base after_destroy :post_destroy_hook, unless: :pending? after_commit :refresh_member_authorized_projects - delegate :name, :username, :email, to: :user, prefix: true - default_value_for :notification_level, NotificationSetting.levels[:global] class << self diff --git a/app/models/project.rb b/app/models/project.rb index a1b29d335b3..698e742de48 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -172,9 +172,11 @@ class Project < ActiveRecord::Base accepts_nested_attributes_for :project_feature delegate :name, to: :owner, allow_nil: true, prefix: true + delegate :count, to: :forks, prefix: true delegate :members, to: :team, prefix: true delegate :add_user, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_master, to: :team + delegate :empty_repo?, to: :repository # Validations validates :creator, presence: true, on: :create @@ -838,8 +840,6 @@ class Project < ActiveRecord::Base false end - delegate :empty_repo?, to: :repository - def repo repository.raw end @@ -1027,8 +1027,6 @@ class Project < ActiveRecord::Base forked? && project == forked_from_project end - delegate :count, to: :forks, prefix: true - def origin_merge_requests merge_requests.where(source_project_id: self.id) end diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index 2f55b853232..9891f5edf41 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -19,6 +19,9 @@ class ProjectWiki @user = user end + delegate :empty?, to: :pages + delegate :repository_storage_path, to: :project + def path @project.path + '.wiki' end @@ -60,8 +63,6 @@ class ProjectWiki !!repository.exists? end - delegate :empty?, to: :pages - # Returns an Array of Gitlab WikiPage instances or an # empty Array if this Wiki has no pages. def pages @@ -158,8 +159,6 @@ class ProjectWiki } end - delegate :repository_storage_path, to: :project - private def init_repo(path_with_namespace) -- cgit v1.2.1 From bdbc7d967a0c3d95d5e4ea19a2a5be41268d3540 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 16:39:43 -0600 Subject: Revert "Enable Style/BarePercentLiterals" This reverts commit 96bef54154e669f9a3e92c3a4bc76c0be3a52e48. --- app/models/commit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index dc971e710ff..0a18986ef26 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -256,7 +256,7 @@ class Commit end def revert_message(user) - %{Revert "#{title.strip}"\n\n#{revert_description(user)}} + %Q{Revert "#{title.strip}"\n\n#{revert_description(user)}} end def reverts_commit?(commit, user) -- cgit v1.2.1 From 1fe7501b49f896b74102c4b970310aa9ae34da85 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 16:50:15 -0600 Subject: Revert "Prefer leading style for Style/DotPosition" This reverts commit cb10b725c8929b8b4460f89c9d96c773af39ba6b. --- app/models/award_emoji.rb | 6 +-- app/models/ci/build.rb | 22 ++++----- app/models/ci/pipeline.rb | 44 ++++++++--------- app/models/ci/runner.rb | 8 ++-- app/models/ci/stage.rb | 6 +-- app/models/commit_status.rb | 10 ++-- app/models/concerns/issuable.rb | 6 +-- app/models/concerns/mentionable.rb | 4 +- app/models/concerns/milestoneish.rb | 4 +- app/models/concerns/presentable.rb | 6 +-- app/models/concerns/routable.rb | 8 ++-- app/models/concerns/sortable.rb | 12 ++--- app/models/concerns/subscribable.rb | 26 +++++----- app/models/deployment.rb | 22 ++++----- app/models/environment.rb | 6 +-- app/models/event.rb | 6 +-- app/models/generic_commit_status.rb | 6 +-- app/models/global_milestone.rb | 4 +- app/models/group.rb | 10 ++-- app/models/issue_collection.rb | 6 +-- app/models/label.rb | 18 +++---- app/models/lfs_object.rb | 6 +-- app/models/member.rb | 12 ++--- app/models/merge_request.rb | 18 +++---- app/models/merge_request_diff.rb | 4 +- app/models/merge_requests_closing_issues.rb | 6 +-- app/models/milestone.rb | 14 +++--- app/models/namespace.rb | 14 +++--- app/models/network/commit.rb | 4 +- app/models/network/graph.rb | 12 ++--- app/models/note.rb | 10 ++-- app/models/project.rb | 22 ++++----- app/models/project_services/kubernetes_service.rb | 6 +-- .../mattermost_slash_commands_service.rb | 4 +- app/models/project_team.rb | 8 ++-- app/models/repository.rb | 12 ++--- app/models/todo.rb | 6 +-- app/models/user.rb | 56 +++++++++++----------- app/models/wiki_page.rb | 10 ++-- 39 files changed, 232 insertions(+), 232 deletions(-) (limited to 'app/models') diff --git a/app/models/award_emoji.rb b/app/models/award_emoji.rb index 2eedbf3ffde..6937ad3bdd9 100644 --- a/app/models/award_emoji.rb +++ b/app/models/award_emoji.rb @@ -18,9 +18,9 @@ class AwardEmoji < ActiveRecord::Base class << self def votes_for_collection(ids, type) - select('name', 'awardable_id', 'COUNT(*) as count') - .where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids) - .group('name', 'awardable_id') + select('name', 'awardable_id', 'COUNT(*) as count'). + where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids). + group('name', 'awardable_id') end end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 3a17d5c8dbe..2689078c771 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -65,9 +65,9 @@ module Ci end def retry(build, current_user) - Ci::RetryBuildService - .new(build.project, current_user) - .execute(build) + Ci::RetryBuildService. + new(build.project, current_user). + execute(build) end end @@ -98,9 +98,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Build::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Build::Factory. + new(self, current_user). + fabricate! end def manual? @@ -222,9 +222,9 @@ module Ci end def merge_request - merge_requests = MergeRequest.includes(:merge_request_diff) - .where(source_branch: ref, source_project_id: pipeline.gl_project_id) - .reorder(iid: :asc) + merge_requests = MergeRequest.includes(:merge_request_diff). + where(source_branch: ref, source_project_id: pipeline.gl_project_id). + reorder(iid: :asc) merge_requests.find do |merge_request| merge_request.commits_sha.include?(pipeline.sha) @@ -276,8 +276,8 @@ module Ci def raw_trace(last_lines: nil) if File.exist?(trace_file_path) - Gitlab::Ci::TraceReader.new(trace_file_path) - .read(last_lines: last_lines) + Gitlab::Ci::TraceReader.new(trace_file_path). + read(last_lines: last_lines) else # backward compatibility read_attribute :trace diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 632178de887..04d43ca3c5c 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -91,9 +91,9 @@ module Ci # ref can't be HEAD or SHA, can only be branch/tag name scope :latest, ->(ref = nil) do - max_id = unscope(:select) - .select("max(#{quoted_table_name}.id)") - .group(:ref, :sha) + max_id = unscope(:select). + select("max(#{quoted_table_name}.id)"). + group(:ref, :sha) if ref where(ref: ref, id: max_id.where(ref: ref)) @@ -128,23 +128,23 @@ module Ci end def stages_name - statuses.order(:stage_idx).distinct - .pluck(:stage, :stage_idx).map(&:first) + statuses.order(:stage_idx).distinct. + pluck(:stage, :stage_idx).map(&:first) end def stages # TODO, this needs refactoring, see gitlab-ce#26481. - stages_query = statuses - .group('stage').select(:stage).order('max(stage_idx)') + stages_query = statuses. + group('stage').select(:stage).order('max(stage_idx)') status_sql = statuses.latest.where('stage=sg.stage').status_sql - warnings_sql = statuses.latest.select('COUNT(*) > 0') - .where('stage=sg.stage').failed_but_allowed.to_sql + warnings_sql = statuses.latest.select('COUNT(*) > 0'). + where('stage=sg.stage').failed_but_allowed.to_sql - stages_with_statuses = CommitStatus.from(stages_query, :sg) - .pluck('sg.stage', status_sql, "(#{warnings_sql})") + stages_with_statuses = CommitStatus.from(stages_query, :sg). + pluck('sg.stage', status_sql, "(#{warnings_sql})") stages_with_statuses.map do |stage| Ci::Stage.new(self, Hash[%i[name status warnings].zip(stage)]) @@ -220,8 +220,8 @@ module Ci end def retry_failed(current_user) - Ci::RetryPipelineService.new(project, current_user) - .execute(self) + Ci::RetryPipelineService.new(project, current_user). + execute(self) end def mark_as_processable_after_stage(stage_idx) @@ -253,9 +253,9 @@ module Ci def config_builds_attributes return [] unless config_processor - config_processor - .builds_for_ref(ref, tag?, trigger_requests.first) - .sort_by { |build| build[:stage_idx] } + config_processor. + builds_for_ref(ref, tag?, trigger_requests.first). + sort_by { |build| build[:stage_idx] } end def has_warnings? @@ -353,15 +353,15 @@ module Ci # Merge requests for which the current pipeline is running against # the merge request's latest commit. def merge_requests - @merge_requests ||= project.merge_requests - .where(source_branch: self.ref) - .select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } + @merge_requests ||= project.merge_requests. + where(source_branch: self.ref). + select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } end def detailed_status(current_user) - Gitlab::Ci::Status::Pipeline::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Pipeline::Factory. + new(self, current_user). + fabricate! end private diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 9cf6164e8dd..a120112e882 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -23,15 +23,15 @@ module Ci scope :ordered, ->() { order(id: :desc) } scope :owned_or_shared, ->(project_id) do - joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id') - .where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) + joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'). + where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) end scope :assignable_for, ->(project) do # FIXME: That `to_sql` is needed to workaround a weird Rails bug. # Without that, placeholders would miss one and couldn't match. - where(locked: false) - .where.not("id IN (#{project.runners.select(:id).to_sql})").specific + where(locked: false). + where.not("id IN (#{project.runners.select(:id).to_sql})").specific end validate :tag_constraints diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index ca74c91b062..0751ab1b7d8 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -28,9 +28,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Stage::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Stage::Factory. + new(self, current_user). + fabricate! end def statuses diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index fc750a3e5e9..1349beafb76 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -97,8 +97,8 @@ class CommitStatus < ActiveRecord::Base after_transition any => :failed do |commit_status| commit_status.run_after_commit do - MergeRequests::AddTodoWhenBuildFailsService - .new(pipeline.project, nil).execute(self) + MergeRequests::AddTodoWhenBuildFailsService. + new(pipeline.project, nil).execute(self) end end end @@ -132,9 +132,9 @@ class CommitStatus < ActiveRecord::Base end def detailed_status(current_user) - Gitlab::Ci::Status::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::Factory. + new(self, current_user). + fabricate! end def sortable_name diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index fcb335e48d1..37c727b5d9f 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -162,9 +162,9 @@ module Issuable highest_priority = highest_label_priority(params).to_sql - select("#{table_name}.*, (#{highest_priority}) AS highest_priority") - .group(arel_table[:id]) - .reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) + select("#{table_name}.*, (#{highest_priority}) AS highest_priority"). + group(arel_table[:id]). + reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) end def with_label(title, sort = nil) diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index a8ce36e51fc..7e56e371b27 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -48,8 +48,8 @@ module Mentionable if extractor @extractor = extractor else - @extractor ||= Gitlab::ReferenceExtractor - .new(project, current_user) + @extractor ||= Gitlab::ReferenceExtractor. + new(project, current_user) @extractor.reset_memoized_values end diff --git a/app/models/concerns/milestoneish.rb b/app/models/concerns/milestoneish.rb index f449229864d..870a6fbaa90 100644 --- a/app/models/concerns/milestoneish.rb +++ b/app/models/concerns/milestoneish.rb @@ -39,8 +39,8 @@ module Milestoneish def issues_visible_to_user(user) memoize_per_user(user, :issues_visible_to_user) do - IssuesFinder.new(user, issues_finder_params) - .execute.where(milestone_id: milestoneish_ids) + IssuesFinder.new(user, issues_finder_params). + execute.where(milestone_id: milestoneish_ids) end end diff --git a/app/models/concerns/presentable.rb b/app/models/concerns/presentable.rb index 7b33b837004..d0f84831d71 100644 --- a/app/models/concerns/presentable.rb +++ b/app/models/concerns/presentable.rb @@ -1,7 +1,7 @@ module Presentable def present(**attributes) - Gitlab::View::Presenter::Factory - .new(self, attributes) - .fabricate! + Gitlab::View::Presenter::Factory. + new(self, attributes). + fabricate! end end diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index c2373de32c5..9f6d215ceb3 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -75,11 +75,11 @@ module Routable # # Returns an ActiveRecord::Relation. def member_descendants(user_id) - joins(:route) - .joins("INNER JOIN routes r2 ON routes.path LIKE CONCAT(r2.path, '/%') + joins(:route). + joins("INNER JOIN routes r2 ON routes.path LIKE CONCAT(r2.path, '/%') INNER JOIN members ON members.source_id = r2.source_id - AND members.source_type = r2.source_type") - .where('members.user_id = ?', user_id) + AND members.source_type = r2.source_type"). + where('members.user_id = ?', user_id) end end diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb index a155a064032..b9a2d812edd 100644 --- a/app/models/concerns/sortable.rb +++ b/app/models/concerns/sortable.rb @@ -39,12 +39,12 @@ module Sortable private def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: []) - query = Label.select(LabelPriority.arel_table[:priority].minimum) - .left_join_priorities - .joins(:label_links) - .where("label_priorities.project_id = #{project_column}") - .where("label_links.target_id = #{target_column}") - .reorder(nil) + query = Label.select(LabelPriority.arel_table[:priority].minimum). + left_join_priorities. + joins(:label_links). + where("label_priorities.project_id = #{project_column}"). + where("label_links.target_id = #{target_column}"). + reorder(nil) query = if target_type_column diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb index f60a0f8f438..e4f5818d0e3 100644 --- a/app/models/concerns/subscribable.rb +++ b/app/models/concerns/subscribable.rb @@ -27,30 +27,30 @@ module Subscribable end def subscribers(project) - subscriptions_available(project) - .where(subscribed: true) - .map(&:user) + subscriptions_available(project). + where(subscribed: true). + map(&:user) end def toggle_subscription(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project) - .update(subscribed: !subscribed?(user, project)) + find_or_initialize_subscription(user, project). + update(subscribed: !subscribed?(user, project)) end def subscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project) - .update(subscribed: true) + find_or_initialize_subscription(user, project). + update(subscribed: true) end def unsubscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project) - .update(subscribed: false) + find_or_initialize_subscription(user, project). + update(subscribed: false) end private @@ -69,14 +69,14 @@ module Subscribable end def find_or_initialize_subscription(user, project) - subscriptions - .find_or_initialize_by(user_id: user.id, project_id: project.try(:id)) + subscriptions. + find_or_initialize_by(user_id: user.id, project_id: project.try(:id)) end def subscriptions_available(project) t = Subscription.arel_table - subscriptions - .where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id)))) + subscriptions. + where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id)))) end end diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 43f7460bd5d..afad001d50f 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -53,10 +53,10 @@ class Deployment < ActiveRecord::Base def update_merge_request_metrics! return unless environment.update_merge_request_metrics? - merge_requests = project.merge_requests - .joins(:metrics) - .where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }) - .where("merge_request_metrics.merged_at <= ?", self.created_at) + merge_requests = project.merge_requests. + joins(:metrics). + where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }). + where("merge_request_metrics.merged_at <= ?", self.created_at) if previous_deployment merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at) @@ -71,17 +71,17 @@ class Deployment < ActiveRecord::Base merge_requests.map(&:id) end - MergeRequest::Metrics - .where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil) - .update_all(first_deployed_to_production_at: self.created_at) + MergeRequest::Metrics. + where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil). + update_all(first_deployed_to_production_at: self.created_at) end def previous_deployment @previous_deployment ||= - project.deployments.joins(:environment) - .where(environments: { name: self.environment.name }, ref: self.ref) - .where.not(id: self.id) - .take + project.deployments.joins(:environment). + where(environments: { name: self.environment.name }, ref: self.ref). + where.not(id: self.id). + take end def stop_action diff --git a/app/models/environment.rb b/app/models/environment.rb index f917f52f832..1a21b5e52b5 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -40,9 +40,9 @@ class Environment < ActiveRecord::Base scope :stopped, -> { with_state(:stopped) } scope :order_by_last_deployed_at, -> do max_deployment_id_sql = - Deployment.select(Deployment.arel_table[:id].maximum) - .where(Deployment.arel_table[:environment_id].eq(arel_table[:id])) - .to_sql + Deployment.select(Deployment.arel_table[:id].maximum). + where(Deployment.arel_table[:environment_id].eq(arel_table[:id])). + to_sql order(Gitlab::Database.nulls_first_order("(#{max_deployment_id_sql})", 'ASC')) end diff --git a/app/models/event.rb b/app/models/event.rb index b8918fcda21..4b8eac9accf 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -343,9 +343,9 @@ class Event < ActiveRecord::Base # At this point it's possible for multiple threads/processes to try to # update the project. Only one query should actually perform the update, # hence we add the extra WHERE clause for last_activity_at. - Project.unscoped.where(id: project_id) - .where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago) - .update_all(last_activity_at: created_at) + Project.unscoped.where(id: project_id). + where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago). + update_all(last_activity_at: created_at) end def authored_by?(user) diff --git a/app/models/generic_commit_status.rb b/app/models/generic_commit_status.rb index 8867ba0d2ff..36b8568871b 100644 --- a/app/models/generic_commit_status.rb +++ b/app/models/generic_commit_status.rb @@ -18,8 +18,8 @@ class GenericCommitStatus < CommitStatus end def detailed_status(current_user) - Gitlab::Ci::Status::External::Factory - .new(self, current_user) - .fabricate! + Gitlab::Ci::Status::External::Factory. + new(self, current_user). + fabricate! end end diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index b991d78e27f..84deb67ba9b 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -76,8 +76,8 @@ class GlobalMilestone end def labels - @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten) - .sort_by!(&:title) + @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten). + sort_by!(&:title) end def due_date diff --git a/app/models/group.rb b/app/models/group.rb index 5ef3f9513fc..1835ce118a1 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -71,9 +71,9 @@ class Group < Namespace def select_for_project_authorization if current_scope.joins_values.include?(:shared_projects) - joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id') - .where('project_namespace.share_with_group_lock = ?', false) - .select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") + joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id'). + where('project_namespace.share_with_group_lock = ?', false). + select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") else super end @@ -197,8 +197,8 @@ class Group < Namespace end def refresh_members_authorized_projects - UserProjectAccessChangedService.new(user_ids_for_project_authorizations) - .execute + UserProjectAccessChangedService.new(user_ids_for_project_authorizations). + execute end def user_ids_for_project_authorizations diff --git a/app/models/issue_collection.rb b/app/models/issue_collection.rb index 49f011c113f..f0b7d9914c8 100644 --- a/app/models/issue_collection.rb +++ b/app/models/issue_collection.rb @@ -17,9 +17,9 @@ class IssueCollection # Given all the issue projects we get a list of projects that the current # user has at least reporter access to. - projects_with_reporter_access = user - .projects_with_reporter_access_limited_to(project_ids) - .pluck(:id) + projects_with_reporter_access = user. + projects_with_reporter_access_limited_to(project_ids). + pluck(:id) collection.select do |issue| if projects_with_reporter_access.include?(issue.project_id) diff --git a/app/models/label.rb b/app/models/label.rb index e97e53301cc..27429e60e4a 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -34,18 +34,18 @@ class Label < ActiveRecord::Base scope :with_title, ->(title) { where(title: title) } def self.prioritized(project) - joins(:priorities) - .where(label_priorities: { project_id: project }) - .reorder('label_priorities.priority ASC, labels.title ASC') + joins(:priorities). + where(label_priorities: { project_id: project }). + reorder('label_priorities.priority ASC, labels.title ASC') end def self.unprioritized(project) labels = Label.arel_table priorities = LabelPriority.arel_table - label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin) - .on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))) - .join_sources + label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin). + on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))). + join_sources joins(label_priorities).where(priorities[:priority].eq(nil)) end @@ -54,9 +54,9 @@ class Label < ActiveRecord::Base labels = Label.arel_table priorities = LabelPriority.arel_table - label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin) - .on(labels[:id].eq(priorities[:label_id])) - .join_sources + label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin). + on(labels[:id].eq(priorities[:label_id])). + join_sources joins(label_priorities) end diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb index 7712d5783e0..ee9ac282e39 100644 --- a/app/models/lfs_object.rb +++ b/app/models/lfs_object.rb @@ -19,8 +19,8 @@ class LfsObject < ActiveRecord::Base end def self.destroy_unreferenced - joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") - .where(lfs_objects_projects: { id: nil }) - .destroy_all + joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id"). + where(lfs_objects_projects: { id: nil }). + destroy_all end end diff --git a/app/models/member.rb b/app/models/member.rb index f198fbe9056..abe9aee3edf 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -41,9 +41,9 @@ class Member < ActiveRecord::Base is_external_invite = arel_table[:user_id].eq(nil).and(arel_table[:invite_token].not_eq(nil)) user_is_active = User.arel_table[:state].eq(:active) - includes(:user).references(:users) - .where(is_external_invite.or(user_is_active)) - .where(requested_at: nil) + includes(:user).references(:users). + where(is_external_invite.or(user_is_active)). + where(requested_at: nil) end scope :invite, -> { where.not(invite_token: nil) } @@ -99,9 +99,9 @@ class Member < ActiveRecord::Base users = User.arel_table members = Member.arel_table - member_users = members.join(users, Arel::Nodes::OuterJoin) - .on(members[:user_id].eq(users[:id])) - .join_sources + member_users = members.join(users, Arel::Nodes::OuterJoin). + on(members[:user_id].eq(users[:id])). + join_sources joins(member_users) end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index c4520c16a43..ea784f77015 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -475,10 +475,10 @@ class MergeRequest < ActiveRecord::Base end def discussions - @discussions ||= self.related_notes - .inc_relations_for_view - .fresh - .discussions + @discussions ||= self.related_notes. + inc_relations_for_view. + fresh. + discussions end def diff_discussions @@ -564,8 +564,8 @@ class MergeRequest < ActiveRecord::Base messages = [title, description] messages.concat(commits.map(&:safe_message)) if merge_request_diff - Gitlab::ClosingIssueExtractor.new(project, current_user) - .closed_by_message(messages.join("\n")) + Gitlab::ClosingIssueExtractor.new(project, current_user). + closed_by_message(messages.join("\n")) else [] end @@ -813,9 +813,9 @@ class MergeRequest < ActiveRecord::Base def all_pipelines return Ci::Pipeline.none unless source_project - @all_pipelines ||= source_project.pipelines - .where(sha: all_commits_sha, ref: source_branch) - .order(id: :desc) + @all_pipelines ||= source_project.pipelines. + where(sha: all_commits_sha, ref: source_branch). + order(id: :desc) end # Note that this could also return SHA from now dangling commits diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index baee00b8fcd..53d08488788 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -169,8 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base # 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: straight) + CompareService.new(project, head_commit_sha). + execute(project, sha, straight: straight) end def commits_count diff --git a/app/models/merge_requests_closing_issues.rb b/app/models/merge_requests_closing_issues.rb index 7f7c114803d..daafb137be4 100644 --- a/app/models/merge_requests_closing_issues.rb +++ b/app/models/merge_requests_closing_issues.rb @@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base class << self def count_for_collection(ids) - group(:issue_id) - .where(issue_id: ids) - .pluck('issue_id', 'COUNT(*) as count') + group(:issue_id). + where(issue_id: ids). + pluck('issue_id', 'COUNT(*) as count') end end end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 30e5dfd096e..7331000a9f2 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -98,11 +98,11 @@ class Milestone < ActiveRecord::Base if Gitlab::Database.postgresql? rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id') else - rel - .group(:project_id) - .having('due_date = MIN(due_date)') - .pluck(:id, :project_id, :due_date) - .map(&:first) + rel. + group(:project_id). + having('due_date = MIN(due_date)'). + pluck(:id, :project_id, :due_date). + map(&:first) end end @@ -177,8 +177,8 @@ class Milestone < ActiveRecord::Base conditions = 'WHEN id = ? THEN ? ' * ids.length - issues.where(id: ids) - .update_all(["position = CASE #{conditions} ELSE position END", *pairs]) + issues.where(id: ids). + update_all(["position = CASE #{conditions} ELSE position END", *pairs]) end private diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 9334b7d9e61..e207ac3db4e 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -48,9 +48,9 @@ class Namespace < ActiveRecord::Base scope :root, -> { where('type IS NULL') } scope :with_statistics, -> do - joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id') - .group('namespaces.id') - .select( + joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id'). + group('namespaces.id'). + select( 'namespaces.*', 'COALESCE(SUM(ps.storage_size), 0) AS storage_size', 'COALESCE(SUM(ps.repository_size), 0) AS repository_size', @@ -251,10 +251,10 @@ class Namespace < ActiveRecord::Base end def refresh_access_of_projects_invited_groups - Group - .joins(project_group_links: :project) - .where(projects: { namespace_id: id }) - .find_each(&:refresh_members_authorized_projects) + Group. + joins(project_group_links: :project). + where(projects: { namespace_id: id }). + find_each(&:refresh_members_authorized_projects) end def remove_exports! diff --git a/app/models/network/commit.rb b/app/models/network/commit.rb index 8417f200e36..a48e872ad84 100644 --- a/app/models/network/commit.rb +++ b/app/models/network/commit.rb @@ -28,8 +28,8 @@ module Network if map.include?(p.id) map[p.id] end - end - .compact + end. + compact end end end diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index 0bbc9451ffd..2a7fa7d0607 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -23,12 +23,12 @@ module Network def collect_notes h = Hash.new(0) - @project - .notes - .where('noteable_type = ?', 'Commit') - .group('notes.commit_id') - .select('notes.commit_id, count(notes.id) as note_count') - .each do |item| + @project. + notes. + where('noteable_type = ?', 'Commit'). + group('notes.commit_id'). + select('notes.commit_id, count(notes.id) as note_count'). + each do |item| h[item.commit_id] = item.note_count.to_i end diff --git a/app/models/note.rb b/app/models/note.rb index c6406f644e0..d6d5396afa5 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -105,14 +105,14 @@ class Note < ActiveRecord::Base def grouped_diff_discussions active_notes = diff_notes.fresh.select(&:active?) - Discussion.for_diff_notes(active_notes) - .map { |d| [d.line_code, d] }.to_h + Discussion.for_diff_notes(active_notes). + map { |d| [d.line_code, d] }.to_h end def count_for_collection(ids, type) - user.select('noteable_id', 'COUNT(*) as count') - .group(:noteable_id) - .where(noteable_type: type, noteable_id: ids) + user.select('noteable_id', 'COUNT(*) as count'). + group(:noteable_id). + where(noteable_type: type, noteable_id: ids) end end diff --git a/app/models/project.rb b/app/models/project.rb index 698e742de48..301ff71cc01 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -235,8 +235,8 @@ class Project < ActiveRecord::Base scope :inside_path, ->(path) do # We need routes alias rs for JOIN so it does not conflict with # includes(:route) which we use in ProjectsFinder. - joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'") - .where('rs.path LIKE ?', "#{path}/%") + joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'"). + where('rs.path LIKE ?', "#{path}/%") end # "enabled" here means "not disabled". It includes private features! @@ -313,9 +313,9 @@ class Project < ActiveRecord::Base pattern = "%#{query}%" projects = select(:id).where( - ptable[:path].matches(pattern) - .or(ptable[:name].matches(pattern)) - .or(ptable[:description].matches(pattern)) + ptable[:path].matches(pattern). + or(ptable[:name].matches(pattern)). + or(ptable[:description].matches(pattern)) ) # We explicitly remove any eager loading clauses as they're: @@ -324,10 +324,10 @@ class Project < ActiveRecord::Base # 2. Combined with .joins(:namespace) lead to all columns from the # projects & namespaces tables being selected, leading to a SQL error # due to the columns of all UNION'd queries no longer being the same. - namespaces = select(:id) - .except(:includes) - .joins(:namespace) - .where(ntable[:name].matches(pattern)) + namespaces = select(:id). + except(:includes). + joins(:namespace). + where(ntable[:name].matches(pattern)) union = Gitlab::SQL::Union.new([projects, namespaces]) @@ -369,8 +369,8 @@ class Project < ActiveRecord::Base end def trending - joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id') - .reorder('trending_projects.id ASC') + joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id'). + reorder('trending_projects.id ASC') end def cached_count diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb index 02e802bad6d..9819e723fe8 100644 --- a/app/models/project_services/kubernetes_service.rb +++ b/app/models/project_services/kubernetes_service.rb @@ -105,9 +105,9 @@ class KubernetesService < DeploymentService def terminals(environment) with_reactive_cache do |data| pods = data.fetch(:pods, nil) - filter_pods(pods, app: environment.slug) - .flat_map { |pod| terminals_for_pod(api_url, namespace, pod) } - .each { |terminal| add_terminal_auth(terminal, terminal_auth) } + filter_pods(pods, app: environment.slug). + flat_map { |pod| terminals_for_pod(api_url, namespace, pod) }. + each { |terminal| add_terminal_auth(terminal, terminal_auth) } end end diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb index 26376fd87ff..56f42d63b2d 100644 --- a/app/models/project_services/mattermost_slash_commands_service.rb +++ b/app/models/project_services/mattermost_slash_commands_service.rb @@ -20,8 +20,8 @@ class MattermostSlashCommandsService < ChatSlashCommandsService end def configure(user, params) - token = Mattermost::Command.new(user) - .create(command(params)) + token = Mattermost::Command.new(user). + create(command(params)) update(active: true, token: token) if token rescue Mattermost::Error => e diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 67cc06642f1..8a53e974b6f 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -169,10 +169,10 @@ class ProjectTeam # Lookup only the IDs we need user_ids = user_ids - access.keys - users_access = project.project_authorizations - .where(user: user_ids) - .group(:user_id) - .maximum(:access_level) + users_access = project.project_authorizations. + where(user: user_ids). + group(:user_id). + maximum(:access_level) access.merge!(users_access) access diff --git a/app/models/repository.rb b/app/models/repository.rb index d1dd900d597..cd2568ad445 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -249,11 +249,11 @@ class Repository cache.fetch(:"diverging_commit_counts_#{branch.name}") do # Rugged seems to throw a `ReferenceError` when given branch_names rather # than SHA-1 hashes - number_commits_behind = raw_repository - .count_commits_between(branch.dereferenced_target.sha, root_ref_hash) + number_commits_behind = raw_repository. + count_commits_between(branch.dereferenced_target.sha, root_ref_hash) - number_commits_ahead = raw_repository - .count_commits_between(root_ref_hash, branch.dereferenced_target.sha) + number_commits_ahead = raw_repository. + count_commits_between(root_ref_hash, branch.dereferenced_target.sha) { behind: number_commits_behind, ahead: number_commits_ahead } end @@ -755,8 +755,8 @@ class Repository check_tree_entry_for_dir(branch_name, path) if start_branch_name - start_project.repository - .check_tree_entry_for_dir(start_branch_name, path) + start_project.repository. + check_tree_entry_for_dir(start_branch_name, path) end commit_file( diff --git a/app/models/todo.rb b/app/models/todo.rb index 32bb9bf2045..47789a21133 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -64,9 +64,9 @@ class Todo < ActiveRecord::Base highest_priority = highest_label_priority(params).to_sql - select("#{table_name}.*, (#{highest_priority}) AS highest_priority") - .order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) - .order('todos.created_at') + select("#{table_name}.*, (#{highest_priority}) AS highest_priority"). + order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')). + order('todos.created_at') end end diff --git a/app/models/user.rb b/app/models/user.rb index 801c84dc011..fada0e567f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -197,13 +197,13 @@ class User < ActiveRecord::Base scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) } def self.with_two_factor - joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id") - .where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id]) + joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). + where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id]) end def self.without_two_factor - joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id") - .where("u2f.id IS NULL AND otp_required_for_login = ?", false) + joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). + where("u2f.id IS NULL AND otp_required_for_login = ?", false) end # @@ -274,9 +274,9 @@ class User < ActiveRecord::Base pattern = "%#{query}%" where( - table[:name].matches(pattern) - .or(table[:email].matches(pattern)) - .or(table[:username].matches(pattern)) + table[:name].matches(pattern). + or(table[:email].matches(pattern)). + or(table[:username].matches(pattern)) ) end @@ -291,10 +291,10 @@ class User < ActiveRecord::Base matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern)) where( - table[:name].matches(pattern) - .or(table[:email].matches(pattern)) - .or(table[:username].matches(pattern)) - .or(table[:id].in(matched_by_emails_user_ids)) + table[:name].matches(pattern). + or(table[:email].matches(pattern)). + or(table[:username].matches(pattern)). + or(table[:id].in(matched_by_emails_user_ids)) ) end @@ -447,8 +447,8 @@ class User < ActiveRecord::Base # Returns the groups a user has access to def authorized_groups - union = Gitlab::SQL::Union - .new([groups.select(:id), authorized_projects.select(:namespace_id)]) + union = Gitlab::SQL::Union. + new([groups.select(:id), authorized_projects.select(:namespace_id)]) Group.where("namespaces.id IN (#{union.to_sql})") end @@ -458,8 +458,8 @@ class User < ActiveRecord::Base end def nested_projects - Project.joins(:namespace).where('namespaces.parent_id IS NOT NULL') - .member_descendants(id) + Project.joins(:namespace).where('namespaces.parent_id IS NOT NULL'). + member_descendants(id) end def refresh_authorized_projects @@ -579,9 +579,9 @@ class User < ActiveRecord::Base next unless project if project.repository.branch_exists?(event.branch_name) - merge_requests = MergeRequest.where("created_at >= ?", event.created_at) - .where(source_project_id: project.id, - source_branch: event.branch_name) + merge_requests = MergeRequest.where("created_at >= ?", event.created_at). + where(source_project_id: project.id, + source_branch: event.branch_name) merge_requests.empty? end end @@ -793,8 +793,8 @@ class User < ActiveRecord::Base def toggle_star(project) UsersStarProject.transaction do - user_star_project = users_star_projects - .where(project: project, user: self).lock(true).first + user_star_project = users_star_projects. + where(project: project, user: self).lock(true).first if user_star_project user_star_project.destroy @@ -830,11 +830,11 @@ class User < ActiveRecord::Base # ms on a database with a similar size to GitLab.com's database. On the other # hand, using a subquery means we can get the exact same data in about 40 ms. def contributed_projects - events = Event.select(:project_id) - .contributions.where(author_id: self) - .where("created_at > ?", Time.now - 1.year) - .uniq - .reorder(nil) + events = Event.select(:project_id). + contributions.where(author_id: self). + where("created_at > ?", Time.now - 1.year). + uniq. + reorder(nil) Project.where(id: events) end @@ -845,9 +845,9 @@ class User < ActiveRecord::Base def ci_authorized_runners @ci_authorized_runners ||= begin - runner_ids = Ci::RunnerProject - .where("ci_runner_projects.gl_project_id IN (#{ci_projects_union.to_sql})") - .select(:runner_id) + runner_ids = Ci::RunnerProject. + where("ci_runner_projects.gl_project_id IN (#{ci_projects_union.to_sql})"). + select(:runner_id) Ci::Runner.specific.where(id: runner_ids) end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 0fa9d77a771..2caebb496db 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -22,16 +22,16 @@ class WikiPage def self.group_by_directory(pages) return [] if pages.blank? - pages.sort_by { |page| [page.directory, page.slug] } - .group_by(&:directory) - .map do |dir, pages| + pages.sort_by { |page| [page.directory, page.slug] }. + group_by(&:directory). + map do |dir, pages| if dir.present? WikiDirectory.new(dir, pages) else pages end - end - .flatten + end. + flatten end def self.unhyphenize(name) -- cgit v1.2.1 From 56de781a2cef437b6e1af748dc0c231af74e044d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 22 Feb 2017 16:54:59 -0600 Subject: Revert "Enable Style/DotPosition" This reverts commit e00fb2bdc2090e9cabeb1eb35a2672a882cc96e9. # Conflicts: # .rubocop.yml # .rubocop_todo.yml # lib/gitlab/ci/config/entry/global.rb # lib/gitlab/ci/config/entry/jobs.rb # spec/lib/gitlab/ci/config/entry/factory_spec.rb # spec/lib/gitlab/ci/config/entry/global_spec.rb # spec/lib/gitlab/ci/config/entry/job_spec.rb # spec/lib/gitlab/ci/status/build/factory_spec.rb # spec/lib/gitlab/incoming_email_spec.rb --- app/models/ci/build.rb | 18 +++++++++--------- app/models/ci/pipeline.rb | 34 +++++++++++++++++----------------- app/models/ci/runner.rb | 4 ++-- app/models/ci/stage.rb | 6 +++--- app/models/commit_status.rb | 10 +++++----- app/models/concerns/milestoneish.rb | 4 ++-- app/models/concerns/presentable.rb | 6 +++--- app/models/concerns/subscribable.rb | 8 ++++---- app/models/generic_commit_status.rb | 6 +++--- app/models/global_milestone.rb | 4 ++-- app/models/group.rb | 6 +++--- app/models/label.rb | 6 +++--- app/models/lfs_object.rb | 6 +++--- app/models/member.rb | 6 +++--- app/models/merge_request.rb | 6 +++--- app/models/merge_request_diff.rb | 4 ++-- app/models/namespace.rb | 6 +++--- app/models/network/commit.rb | 4 ++-- app/models/network/graph.rb | 12 ++++++------ 19 files changed, 78 insertions(+), 78 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 2689078c771..16d4f3b4f1b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -65,9 +65,9 @@ module Ci end def retry(build, current_user) - Ci::RetryBuildService. - new(build.project, current_user). - execute(build) + Ci::RetryBuildService + .new(build.project, current_user) + .execute(build) end end @@ -98,9 +98,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Build::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Build::Factory + .new(self, current_user) + .fabricate! end def manual? @@ -222,9 +222,9 @@ module Ci end def merge_request - merge_requests = MergeRequest.includes(:merge_request_diff). - where(source_branch: ref, source_project_id: pipeline.gl_project_id). - reorder(iid: :asc) + merge_requests = MergeRequest.includes(:merge_request_diff) + .where(source_branch: ref, source_project_id: pipeline.gl_project_id) + .reorder(iid: :asc) merge_requests.find do |merge_request| merge_request.commits_sha.include?(pipeline.sha) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 04d43ca3c5c..80e11a5b58f 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -91,9 +91,9 @@ module Ci # ref can't be HEAD or SHA, can only be branch/tag name scope :latest, ->(ref = nil) do - max_id = unscope(:select). - select("max(#{quoted_table_name}.id)"). - group(:ref, :sha) + max_id = unscope(:select) + .select("max(#{quoted_table_name}.id)") + .group(:ref, :sha) if ref where(ref: ref, id: max_id.where(ref: ref)) @@ -135,16 +135,16 @@ module Ci def stages # TODO, this needs refactoring, see gitlab-ce#26481. - stages_query = statuses. - group('stage').select(:stage).order('max(stage_idx)') + stages_query = statuses + .group('stage').select(:stage).order('max(stage_idx)') status_sql = statuses.latest.where('stage=sg.stage').status_sql - warnings_sql = statuses.latest.select('COUNT(*) > 0'). - where('stage=sg.stage').failed_but_allowed.to_sql + warnings_sql = statuses.latest.select('COUNT(*) > 0') + .where('stage=sg.stage').failed_but_allowed.to_sql - stages_with_statuses = CommitStatus.from(stages_query, :sg). - pluck('sg.stage', status_sql, "(#{warnings_sql})") + stages_with_statuses = CommitStatus.from(stages_query, :sg) + .pluck('sg.stage', status_sql, "(#{warnings_sql})") stages_with_statuses.map do |stage| Ci::Stage.new(self, Hash[%i[name status warnings].zip(stage)]) @@ -220,8 +220,8 @@ module Ci end def retry_failed(current_user) - Ci::RetryPipelineService.new(project, current_user). - execute(self) + Ci::RetryPipelineService.new(project, current_user) + .execute(self) end def mark_as_processable_after_stage(stage_idx) @@ -353,15 +353,15 @@ module Ci # Merge requests for which the current pipeline is running against # the merge request's latest commit. def merge_requests - @merge_requests ||= project.merge_requests. - where(source_branch: self.ref). - select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } + @merge_requests ||= project.merge_requests + .where(source_branch: self.ref) + .select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } end def detailed_status(current_user) - Gitlab::Ci::Status::Pipeline::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Pipeline::Factory + .new(self, current_user) + .fabricate! end private diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index a120112e882..4863c34a6a6 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -23,8 +23,8 @@ module Ci scope :ordered, ->() { order(id: :desc) } scope :owned_or_shared, ->(project_id) do - joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'). - where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) + joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id') + .where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id) end scope :assignable_for, ->(project) do diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index 0751ab1b7d8..ca74c91b062 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -28,9 +28,9 @@ module Ci end def detailed_status(current_user) - Gitlab::Ci::Status::Stage::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Stage::Factory + .new(self, current_user) + .fabricate! end def statuses diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 1349beafb76..fc750a3e5e9 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -97,8 +97,8 @@ class CommitStatus < ActiveRecord::Base after_transition any => :failed do |commit_status| commit_status.run_after_commit do - MergeRequests::AddTodoWhenBuildFailsService. - new(pipeline.project, nil).execute(self) + MergeRequests::AddTodoWhenBuildFailsService + .new(pipeline.project, nil).execute(self) end end end @@ -132,9 +132,9 @@ class CommitStatus < ActiveRecord::Base end def detailed_status(current_user) - Gitlab::Ci::Status::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::Factory + .new(self, current_user) + .fabricate! end def sortable_name diff --git a/app/models/concerns/milestoneish.rb b/app/models/concerns/milestoneish.rb index 870a6fbaa90..f449229864d 100644 --- a/app/models/concerns/milestoneish.rb +++ b/app/models/concerns/milestoneish.rb @@ -39,8 +39,8 @@ module Milestoneish def issues_visible_to_user(user) memoize_per_user(user, :issues_visible_to_user) do - IssuesFinder.new(user, issues_finder_params). - execute.where(milestone_id: milestoneish_ids) + IssuesFinder.new(user, issues_finder_params) + .execute.where(milestone_id: milestoneish_ids) end end diff --git a/app/models/concerns/presentable.rb b/app/models/concerns/presentable.rb index d0f84831d71..7b33b837004 100644 --- a/app/models/concerns/presentable.rb +++ b/app/models/concerns/presentable.rb @@ -1,7 +1,7 @@ module Presentable def present(**attributes) - Gitlab::View::Presenter::Factory. - new(self, attributes). - fabricate! + Gitlab::View::Presenter::Factory + .new(self, attributes) + .fabricate! end end diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb index e4f5818d0e3..83daa9b1a64 100644 --- a/app/models/concerns/subscribable.rb +++ b/app/models/concerns/subscribable.rb @@ -42,15 +42,15 @@ module Subscribable def subscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project). - update(subscribed: true) + find_or_initialize_subscription(user, project) + .update(subscribed: true) end def unsubscribe(user, project = nil) unsubscribe_from_other_levels(user, project) - find_or_initialize_subscription(user, project). - update(subscribed: false) + find_or_initialize_subscription(user, project) + .update(subscribed: false) end private diff --git a/app/models/generic_commit_status.rb b/app/models/generic_commit_status.rb index 36b8568871b..8867ba0d2ff 100644 --- a/app/models/generic_commit_status.rb +++ b/app/models/generic_commit_status.rb @@ -18,8 +18,8 @@ class GenericCommitStatus < CommitStatus end def detailed_status(current_user) - Gitlab::Ci::Status::External::Factory. - new(self, current_user). - fabricate! + Gitlab::Ci::Status::External::Factory + .new(self, current_user) + .fabricate! end end diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index 84deb67ba9b..b991d78e27f 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -76,8 +76,8 @@ class GlobalMilestone end def labels - @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten). - sort_by!(&:title) + @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten) + .sort_by!(&:title) end def due_date diff --git a/app/models/group.rb b/app/models/group.rb index 1835ce118a1..240a17f1dc1 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -71,9 +71,9 @@ class Group < Namespace def select_for_project_authorization if current_scope.joins_values.include?(:shared_projects) - joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id'). - where('project_namespace.share_with_group_lock = ?', false). - select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") + joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id') + .where('project_namespace.share_with_group_lock = ?', false) + .select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") else super end diff --git a/app/models/label.rb b/app/models/label.rb index 27429e60e4a..f68a8c9cff2 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -34,9 +34,9 @@ class Label < ActiveRecord::Base scope :with_title, ->(title) { where(title: title) } def self.prioritized(project) - joins(:priorities). - where(label_priorities: { project_id: project }). - reorder('label_priorities.priority ASC, labels.title ASC') + joins(:priorities) + .where(label_priorities: { project_id: project }) + .reorder('label_priorities.priority ASC, labels.title ASC') end def self.unprioritized(project) diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb index ee9ac282e39..7712d5783e0 100644 --- a/app/models/lfs_object.rb +++ b/app/models/lfs_object.rb @@ -19,8 +19,8 @@ class LfsObject < ActiveRecord::Base end def self.destroy_unreferenced - joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id"). - where(lfs_objects_projects: { id: nil }). - destroy_all + joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") + .where(lfs_objects_projects: { id: nil }) + .destroy_all end end diff --git a/app/models/member.rb b/app/models/member.rb index abe9aee3edf..0545bd4eedf 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -41,9 +41,9 @@ class Member < ActiveRecord::Base is_external_invite = arel_table[:user_id].eq(nil).and(arel_table[:invite_token].not_eq(nil)) user_is_active = User.arel_table[:state].eq(:active) - includes(:user).references(:users). - where(is_external_invite.or(user_is_active)). - where(requested_at: nil) + includes(:user).references(:users) + .where(is_external_invite.or(user_is_active)) + .where(requested_at: nil) end scope :invite, -> { where.not(invite_token: nil) } diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ea784f77015..d5eb44aeeb8 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -813,9 +813,9 @@ class MergeRequest < ActiveRecord::Base def all_pipelines return Ci::Pipeline.none unless source_project - @all_pipelines ||= source_project.pipelines. - where(sha: all_commits_sha, ref: source_branch). - order(id: :desc) + @all_pipelines ||= source_project.pipelines + .where(sha: all_commits_sha, ref: source_branch) + .order(id: :desc) end # Note that this could also return SHA from now dangling commits diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 53d08488788..baee00b8fcd 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -169,8 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base # 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: straight) + CompareService.new(project, head_commit_sha) + .execute(project, sha, straight: straight) end def commits_count diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e207ac3db4e..bd0336c984a 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -48,9 +48,9 @@ class Namespace < ActiveRecord::Base scope :root, -> { where('type IS NULL') } scope :with_statistics, -> do - joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id'). - group('namespaces.id'). - select( + joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id') + .group('namespaces.id') + .select( 'namespaces.*', 'COALESCE(SUM(ps.storage_size), 0) AS storage_size', 'COALESCE(SUM(ps.repository_size), 0) AS repository_size', diff --git a/app/models/network/commit.rb b/app/models/network/commit.rb index a48e872ad84..8417f200e36 100644 --- a/app/models/network/commit.rb +++ b/app/models/network/commit.rb @@ -28,8 +28,8 @@ module Network if map.include?(p.id) map[p.id] end - end. - compact + end + .compact end end end diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index 2a7fa7d0607..0bbc9451ffd 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -23,12 +23,12 @@ module Network def collect_notes h = Hash.new(0) - @project. - notes. - where('noteable_type = ?', 'Commit'). - group('notes.commit_id'). - select('notes.commit_id, count(notes.id) as note_count'). - each do |item| + @project + .notes + .where('noteable_type = ?', 'Commit') + .group('notes.commit_id') + .select('notes.commit_id, count(notes.id) as note_count') + .each do |item| h[item.commit_id] = item.note_count.to_i end -- cgit v1.2.1