Commit b9da26c8 authored by Sean McGivern's avatar Sean McGivern

Merge branch '228858-resolve-numericpredicate-lib' into 'master'

[RUN AS-IF-FOSS] Resolve Style/NumericPredicate Cop exceptions in lib

See merge request gitlab-org/gitlab!38333
parents 6799856c 2be85d6b
...@@ -980,59 +980,7 @@ Style/NumericPredicate: ...@@ -980,59 +980,7 @@ Style/NumericPredicate:
- 'ee/app/workers/geo/registry_sync_worker.rb' - 'ee/app/workers/geo/registry_sync_worker.rb'
- 'ee/app/workers/geo/repository_shard_sync_worker.rb' - 'ee/app/workers/geo/repository_shard_sync_worker.rb'
- 'ee/app/workers/geo/repository_verification/primary/shard_worker.rb' - 'ee/app/workers/geo/repository_verification/primary/shard_worker.rb'
- 'ee/lib/api/helpers/packages/conan/api_helpers.rb'
- 'ee/lib/ee/gitlab/auth/ldap/person.rb'
- 'ee/lib/ee/gitlab/background_migration/prune_orphaned_geo_events.rb'
- 'ee/lib/ee/gitlab/checks/push_rules/file_size_check.rb'
- 'ee/lib/ee/gitlab/geo_git_access.rb'
- 'ee/lib/gitlab/geo/fdw.rb'
- 'ee/lib/gitlab/geo/log_cursor/lease.rb'
- 'ee/lib/tasks/gitlab/elastic.rake'
- 'lib/api/entities/feature.rb'
- 'lib/api/helpers/pagination_strategies.rb'
- 'lib/backup/files.rb'
- 'lib/banzai/filter/gollum_tags_filter.rb'
- 'lib/bitbucket_server/paginator.rb'
- 'lib/declarative_policy/runner.rb'
- 'lib/gitlab/auth/ldap/adapter.rb'
- 'lib/gitlab/bare_repository_import/importer.rb'
- 'lib/gitlab/ci/config/external/context.rb'
- 'lib/gitlab/ci/reports/accessibility_reports_comparer.rb'
- 'lib/gitlab/cycle_analytics/summary/value.rb'
- 'lib/gitlab/cycle_analytics/summary_helper.rb'
- 'lib/gitlab/danger/teammate.rb'
- 'lib/gitlab/database.rb'
- 'lib/gitlab/database/connection_timer.rb'
- 'lib/gitlab/database/migration_helpers.rb'
- 'lib/gitlab/exclusive_lease.rb'
- 'lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb'
- 'lib/gitlab/experimentation.rb'
- 'lib/gitlab/file_hook.rb'
- 'lib/gitlab/git/commit.rb'
- 'lib/gitlab/git/repository.rb'
- 'lib/gitlab/git/rugged_impl/blob.rb'
- 'lib/gitlab/gitaly_client.rb'
- 'lib/gitlab/github_import/user_finder.rb'
- 'lib/gitlab/hashed_storage/migrator.rb'
- 'lib/gitlab/import_export/command_line_util.rb'
- 'lib/gitlab/multi_collection_paginator.rb'
- 'lib/gitlab/polling_interval.rb'
- 'lib/gitlab/project_search_results.rb'
- 'lib/gitlab/seeder.rb'
- 'lib/gitlab/sidekiq_cluster.rb'
- 'lib/gitlab/sidekiq_daemon/memory_killer.rb'
- 'lib/gitlab/sidekiq_middleware/memory_killer.rb'
- 'lib/gitlab/sidekiq_status.rb'
- 'lib/gitlab/slash_commands/presenters/issue_show.rb'
- 'lib/gitlab/task_helpers.rb'
- 'lib/gitlab/untrusted_regexp.rb'
- 'lib/gitlab/utils.rb'
- 'lib/system_check/sidekiq_check.rb'
- 'lib/tasks/gitlab/gitaly.rake'
- 'lib/tasks/gitlab/snippets.rake'
- 'lib/tasks/gitlab/workhorse.rake'
- 'ee/app/models/ee/project.rb' - 'ee/app/models/ee/project.rb'
- 'lib/gitlab/usage_data/topology.rb'
# Offense count: 117 # Offense count: 117
# Cop supports --auto-correct. # Cop supports --auto-correct.
......
...@@ -46,7 +46,7 @@ module EE ...@@ -46,7 +46,7 @@ module EE
::Gitlab::Auth::Ldap::DN.new(dn).each_pair { |name, value| dn_components << { name: name, value: value } } ::Gitlab::Auth::Ldap::DN.new(dn).each_pair { |name, value| dn_components << { name: name, value: value } }
dn_components dn_components
.reverse .reverse
.take_while { |rdn| rdn[:name].casecmp('DC').zero? } # Domain Component .take_while { |rdn| rdn[:name].casecmp('DC') == 0 } # Domain Component
.map { |rdn| rdn[:value] } .map { |rdn| rdn[:value] }
.reverse .reverse
.join('.') .join('.')
......
...@@ -45,7 +45,7 @@ module EE ...@@ -45,7 +45,7 @@ module EE
def delete_batch_of_orphans! def delete_batch_of_orphans!
deleted = where(id: orphans.limit(BATCH_SIZE)).delete_all deleted = where(id: orphans.limit(BATCH_SIZE)).delete_all
vacuum! if deleted.positive? vacuum! if deleted > 0
deleted deleted
end end
...@@ -64,7 +64,7 @@ module EE ...@@ -64,7 +64,7 @@ module EE
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.read_only?
deleted_rows = prune_orphaned_rows(table_name) deleted_rows = prune_orphaned_rows(table_name)
table_name = next_table(table_name) if deleted_rows.zero? table_name = next_table(table_name) if deleted_rows == 0
::BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, self.class.name.demodulize, table_name) if table_name ::BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, self.class.name.demodulize, table_name) if table_name
end end
......
...@@ -8,7 +8,7 @@ module EE ...@@ -8,7 +8,7 @@ module EE
LOG_MESSAGE = "Checking if any files are larger than the allowed size...".freeze LOG_MESSAGE = "Checking if any files are larger than the allowed size...".freeze
def validate! def validate!
return if push_rule.nil? || push_rule.max_file_size.zero? return if push_rule.nil? || push_rule.max_file_size == 0
logger.log_timed(LOG_MESSAGE) do logger.log_timed(LOG_MESSAGE) do
max_file_size = push_rule.max_file_size max_file_size = push_rule.max_file_size
......
...@@ -82,7 +82,7 @@ module EE ...@@ -82,7 +82,7 @@ module EE
end end
def current_replication_lag_message def current_replication_lag_message
return if ::Gitlab::Database.read_write? || current_replication_lag.zero? return if ::Gitlab::Database.read_write? || current_replication_lag == 0
"Current replication lag: #{current_replication_lag} seconds" "Current replication lag: #{current_replication_lag} seconds"
end end
......
...@@ -63,7 +63,7 @@ module Gitlab ...@@ -63,7 +63,7 @@ module Gitlab
private private
def fdw_capable? def fdw_capable?
has_foreign_server? && has_foreign_schema? && foreign_schema_tables_count.positive? has_foreign_server? && has_foreign_schema? && foreign_schema_tables_count > 0
rescue ::Geo::TrackingBase::SecondaryNotConfigured rescue ::Geo::TrackingBase::SecondaryNotConfigured
false false
end end
...@@ -74,7 +74,7 @@ module Gitlab ...@@ -74,7 +74,7 @@ module Gitlab
def has_foreign_server? def has_foreign_server?
::Geo::TrackingBase.connection.execute( ::Geo::TrackingBase.connection.execute(
"SELECT 1 FROM pg_foreign_server" "SELECT 1 FROM pg_foreign_server"
).count.positive? ).count > 0
end end
def has_foreign_schema? def has_foreign_schema?
...@@ -85,7 +85,7 @@ module Gitlab ...@@ -85,7 +85,7 @@ module Gitlab
WHERE schema_name='#{FOREIGN_SCHEMA}' WHERE schema_name='#{FOREIGN_SCHEMA}'
SQL SQL
::Geo::TrackingBase.connection.execute(sql).count.positive? ::Geo::TrackingBase.connection.execute(sql).count > 0
end end
end end
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
def self.try_obtain_with_ttl def self.try_obtain_with_ttl
lease = exclusive_lease.try_obtain_with_ttl lease = exclusive_lease.try_obtain_with_ttl
unless lease[:ttl].zero? || exclusive_lease.same_uuid? unless lease[:ttl] == 0 || exclusive_lease.same_uuid?
$stdout.puts lease_taken_message $stdout.puts lease_taken_message
logger.debug(lease_taken_message) logger.debug(lease_taken_message)
......
...@@ -108,7 +108,7 @@ namespace :gitlab do ...@@ -108,7 +108,7 @@ namespace :gitlab do
task projects_not_indexed: :environment do task projects_not_indexed: :environment do
not_indexed = Project.where.not(id: IndexStatus.select(:project_id).distinct) not_indexed = Project.where.not(id: IndexStatus.select(:project_id).distinct)
if not_indexed.count.zero? if not_indexed.count == 0
puts 'All projects are currently indexed'.color(:green) puts 'All projects are currently indexed'.color(:green)
else else
display_unindexed(not_indexed) display_unindexed(not_indexed)
......
...@@ -10,7 +10,7 @@ module API ...@@ -10,7 +10,7 @@ module API
value = model.gate_values[gate.key] value = model.gate_values[gate.key]
# By default all gate values are populated. Only show relevant ones. # By default all gate values are populated. Only show relevant ones.
if (value.is_a?(Integer) && value.zero?) || (value.is_a?(Set) && value.empty?) if (value.is_a?(Integer) && value == 0) || (value.is_a?(Set) && value.empty?)
next next
end end
......
...@@ -48,7 +48,7 @@ module API ...@@ -48,7 +48,7 @@ module API
end end
def offset_limit_exceeded?(offset_limit) def offset_limit_exceeded?(offset_limit)
offset_limit.positive? && params[:page] * params[:per_page] > offset_limit offset_limit > 0 && params[:page] * params[:per_page] > offset_limit
end end
end end
end end
......
...@@ -26,7 +26,7 @@ module Backup ...@@ -26,7 +26,7 @@ module Backup
cmd = %W(rsync -a --exclude=lost+found #{app_files_dir} #{Gitlab.config.backup.path}) cmd = %W(rsync -a --exclude=lost+found #{app_files_dir} #{Gitlab.config.backup.path})
output, status = Gitlab::Popen.popen(cmd) output, status = Gitlab::Popen.popen(cmd)
unless status.zero? unless status == 0
puts output puts output
raise Backup::Error, 'Backup failed' raise Backup::Error, 'Backup failed'
end end
......
...@@ -82,7 +82,7 @@ module Banzai ...@@ -82,7 +82,7 @@ module Banzai
def process_tag(tag) def process_tag(tag)
parts = tag.split('|') parts = tag.split('|')
return if parts.size.zero? return if parts.empty?
process_image_tag(parts) || process_page_link_tag(parts) process_image_tag(parts) || process_page_link_tag(parts)
end end
......
...@@ -36,7 +36,7 @@ module BitbucketServer ...@@ -36,7 +36,7 @@ module BitbucketServer
def over_limit? def over_limit?
return false unless @limit return false unless @limit
@limit.positive? && @total >= @limit @limit > 0 && @total >= @limit
end end
def next_offset def next_offset
......
...@@ -170,7 +170,7 @@ module DeclarativePolicy ...@@ -170,7 +170,7 @@ module DeclarativePolicy
lowest_score = score lowest_score = score
end end
break if lowest_score.zero? break if lowest_score == 0
end end
[remaining_steps, remaining_enablers, remaining_preventers].each do |set| [remaining_steps, remaining_enablers, remaining_preventers].each do |set|
......
...@@ -54,7 +54,7 @@ module Gitlab ...@@ -54,7 +54,7 @@ module Gitlab
if results.nil? if results.nil?
response = ldap.get_operation_result response = ldap.get_operation_result
unless response.code.zero? unless response.code == 0
Rails.logger.warn("LDAP search error: #{response.message}") # rubocop:disable Gitlab/RailsLogger Rails.logger.warn("LDAP search error: #{response.message}") # rubocop:disable Gitlab/RailsLogger
end end
......
...@@ -123,7 +123,7 @@ module Gitlab ...@@ -123,7 +123,7 @@ module Gitlab
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all) cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all)
output, status = Gitlab::Popen.popen(cmd) output, status = Gitlab::Popen.popen(cmd)
raise output unless status.zero? raise output unless status == 0
bundle_path bundle_path
end end
......
...@@ -54,7 +54,7 @@ module Gitlab ...@@ -54,7 +54,7 @@ module Gitlab
end end
def execution_expired? def execution_expired?
return false if execution_deadline.zero? return false if execution_deadline == 0
current_monotonic_time > execution_deadline current_monotonic_time > execution_deadline
end end
......
...@@ -17,7 +17,7 @@ module Gitlab ...@@ -17,7 +17,7 @@ module Gitlab
end end
def status def status
head_reports.errors_count.positive? ? STATUS_FAILED : STATUS_SUCCESS head_reports.errors_count > 0 ? STATUS_FAILED : STATUS_SUCCESS
end end
def existing_errors def existing_errors
......
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
end end
def to_s def to_s
value.zero? ? '0' : value.to_s value == 0 ? '0' : value.to_s
end end
def to_i def to_i
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
module CycleAnalytics module CycleAnalytics
module SummaryHelper module SummaryHelper
def frequency(count, from, to) def frequency(count, from, to)
return Summary::Value::None.new if count.zero? return Summary::Value::None.new if count == 0
freq = (count / days(from, to)).round(1) freq = (count / days(from, to)).round(1)
......
...@@ -80,7 +80,7 @@ module Gitlab ...@@ -80,7 +80,7 @@ module Gitlab
def offset_diff_compared_to_author(author) def offset_diff_compared_to_author(author)
diff = floored_offset_hours - author.floored_offset_hours diff = floored_offset_hours - author.floored_offset_hours
return "same timezone as `@#{author.username}`" if diff.zero? return "same timezone as `@#{author.username}`" if diff == 0
ahead_or_behind = diff < 0 ? 'behind' : 'ahead of' ahead_or_behind = diff < 0 ? 'behind' : 'ahead of'
pluralized_hours = pluralize(diff.abs, 'hour', 'hours') pluralized_hours = pluralize(diff.abs, 'hour', 'hours')
......
...@@ -74,7 +74,7 @@ module Gitlab ...@@ -74,7 +74,7 @@ module Gitlab
# @deprecated # @deprecated
def self.postgresql? def self.postgresql?
adapter_name.casecmp('postgresql').zero? adapter_name.casecmp('postgresql') == 0
end end
def self.read_only? def self.read_only?
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
end end
def interval_with_randomization def interval_with_randomization
interval + rand(RANDOMIZATION_INTERVAL) if interval.positive? interval + rand(RANDOMIZATION_INTERVAL) if interval > 0
end end
def current_clock_value def current_clock_value
......
...@@ -1062,7 +1062,7 @@ into similar problems in the future (e.g. when new tables are created). ...@@ -1062,7 +1062,7 @@ into similar problems in the future (e.g. when new tables are created).
AND pg_class.relname = '#{table}' AND pg_class.relname = '#{table}'
SQL SQL
connection.select_value(check_sql).positive? connection.select_value(check_sql) > 0
end end
# Adds a check constraint to a table # Adds a check constraint to a table
......
...@@ -102,7 +102,7 @@ module Gitlab ...@@ -102,7 +102,7 @@ module Gitlab
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::SharedState.with do |redis|
ttl = redis.ttl(@redis_shared_state_key) ttl = redis.ttl(@redis_shared_state_key)
ttl if ttl.positive? ttl if ttl > 0
end end
end end
......
...@@ -39,7 +39,7 @@ module Gitlab ...@@ -39,7 +39,7 @@ module Gitlab
end end
def first_attempt? def first_attempt?
attempts.zero? attempts == 0
end end
def sleep_sec def sleep_sec
......
...@@ -170,7 +170,7 @@ module Gitlab ...@@ -170,7 +170,7 @@ module Gitlab
Experiment = Struct.new(:key, :environment, :tracking_category, keyword_init: true) do Experiment = Struct.new(:key, :environment, :tracking_category, keyword_init: true) do
def enabled? def enabled?
experiment_percentage.positive? experiment_percentage > 0
end end
def enabled_for_environment? def enabled_for_environment?
......
...@@ -27,7 +27,7 @@ module Gitlab ...@@ -27,7 +27,7 @@ module Gitlab
end end
exit_status = result.status&.exitstatus exit_status = result.status&.exitstatus
[exit_status.zero?, result.stderr] [exit_status == 0, result.stderr]
rescue => e rescue => e
[false, e.message] [false, e.message]
end end
......
...@@ -261,7 +261,7 @@ module Gitlab ...@@ -261,7 +261,7 @@ module Gitlab
end end
def has_zero_stats? def has_zero_stats?
stats.total.zero? stats.total == 0
rescue rescue
true true
end end
...@@ -423,7 +423,7 @@ module Gitlab ...@@ -423,7 +423,7 @@ module Gitlab
end end
def message_from_gitaly_body def message_from_gitaly_body
return @raw_commit.subject.dup if @raw_commit.body_size.zero? return @raw_commit.subject.dup if @raw_commit.body_size == 0
return @raw_commit.body.dup if full_body_fetched_from_gitaly? return @raw_commit.body.dup if full_body_fetched_from_gitaly?
if @raw_commit.body_size > MAX_COMMIT_MESSAGE_DISPLAY_SIZE if @raw_commit.body_size > MAX_COMMIT_MESSAGE_DISPLAY_SIZE
......
...@@ -815,7 +815,7 @@ module Gitlab ...@@ -815,7 +815,7 @@ module Gitlab
def fsck def fsck
msg, status = gitaly_repository_client.fsck msg, status = gitaly_repository_client.fsck
raise GitError.new("Could not fsck repository: #{msg}") unless status.zero? raise GitError.new("Could not fsck repository: #{msg}") unless status == 0
end end
def create_from_bundle(bundle_path) def create_from_bundle(bundle_path)
......
...@@ -48,7 +48,7 @@ module Gitlab ...@@ -48,7 +48,7 @@ module Gitlab
name: blob_entry[:name], name: blob_entry[:name],
size: blob.size, size: blob.size,
# Rugged::Blob#content is expensive; don't call it if we don't have to. # Rugged::Blob#content is expensive; don't call it if we don't have to.
data: limit.zero? ? '' : blob.content(limit), data: limit == 0 ? '' : blob.content(limit),
mode: blob_entry[:filemode].to_s(8), mode: blob_entry[:filemode].to_s(8),
path: path, path: path,
commit_id: sha, commit_id: sha,
......
...@@ -476,7 +476,7 @@ module Gitlab ...@@ -476,7 +476,7 @@ module Gitlab
return unless stack_counter return unless stack_counter
max = max_call_count max = max_call_count
return if max.zero? return if max == 0
stack_counter.select { |_, v| v == max }.keys stack_counter.select { |_, v| v == max }.keys
end end
......
...@@ -161,7 +161,7 @@ module Gitlab ...@@ -161,7 +161,7 @@ module Gitlab
# The cache key may be empty to indicate a previously looked up user for # The cache key may be empty to indicate a previously looked up user for
# which we couldn't find an ID. # which we couldn't find an ID.
[exists, number.positive? ? number : nil] [exists, number > 0 ? number : nil]
end end
end end
end end
......
...@@ -101,7 +101,7 @@ module Gitlab ...@@ -101,7 +101,7 @@ module Gitlab
def any_non_empty_queue?(*workers) def any_non_empty_queue?(*workers)
workers.any? do |worker| workers.any? do |worker|
!Sidekiq::Queue.new(worker.queue).size.zero? Sidekiq::Queue.new(worker.queue).size != 0 # rubocop:disable Style/ZeroLengthPredicate
end end
end end
......
...@@ -47,8 +47,8 @@ module Gitlab ...@@ -47,8 +47,8 @@ module Gitlab
def execute(cmd) def execute(cmd)
output, status = Gitlab::Popen.popen(cmd) output, status = Gitlab::Popen.popen(cmd)
@shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status.zero? # rubocop:disable Gitlab/ModuleWithInstanceVariables @shared.error(Gitlab::ImportExport::Error.new(output.to_s)) unless status == 0 # rubocop:disable Gitlab/ModuleWithInstanceVariables
status.zero? status == 0
end end
def git_bin_path def git_bin_path
......
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
@second_collection_pages ||= Hash.new do |hash, page| @second_collection_pages ||= Hash.new do |hash, page|
second_collection_page = page - first_collection_page_count second_collection_page = page - first_collection_page_count
offset = if second_collection_page < 1 || first_collection_page_count.zero? offset = if second_collection_page < 1 || first_collection_page_count == 0
0 0
else else
per_page - first_collection_last_page_size per_page - first_collection_last_page_size
......
...@@ -20,7 +20,7 @@ module Gitlab ...@@ -20,7 +20,7 @@ module Gitlab
end end
def self.polling_enabled? def self.polling_enabled?
!Gitlab::CurrentSettings.polling_interval_multiplier.zero? Gitlab::CurrentSettings.polling_interval_multiplier != 0
end end
end end
end end
...@@ -81,7 +81,7 @@ module Gitlab ...@@ -81,7 +81,7 @@ module Gitlab
counts = %i(limited_milestones_count limited_notes_count counts = %i(limited_milestones_count limited_notes_count
limited_merge_requests_count limited_issues_count limited_merge_requests_count limited_issues_count
limited_blobs_count wiki_blobs_count) limited_blobs_count wiki_blobs_count)
counts.all? { |count_method| public_send(count_method).zero? } # rubocop:disable GitlabSecurity/PublicSend counts.all? { |count_method| public_send(count_method) == 0 } # rubocop:disable GitlabSecurity/PublicSend
end end
private private
......
...@@ -66,7 +66,7 @@ module Gitlab ...@@ -66,7 +66,7 @@ module Gitlab
estimated_minutes = (size.to_f / ESTIMATED_INSERT_PER_MINUTE).round estimated_minutes = (size.to_f / ESTIMATED_INSERT_PER_MINUTE).round
humanized_minutes = 'minute'.pluralize(estimated_minutes) humanized_minutes = 'minute'.pluralize(estimated_minutes)
if estimated_minutes.zero? if estimated_minutes == 0
"Rough estimated time: less than a minute ⏰" "Rough estimated time: less than a minute ⏰"
else else
"Rough estimated time: #{estimated_minutes} #{humanized_minutes} ⏰" "Rough estimated time: #{estimated_minutes} #{humanized_minutes} ⏰"
......
...@@ -126,7 +126,7 @@ module Gitlab ...@@ -126,7 +126,7 @@ module Gitlab
def self.concurrency(queues, min_concurrency, max_concurrency) def self.concurrency(queues, min_concurrency, max_concurrency)
concurrency_from_queues = queues.length + 1 concurrency_from_queues = queues.length + 1
max = max_concurrency.positive? ? max_concurrency : concurrency_from_queues max = max_concurrency > 0 ? max_concurrency : concurrency_from_queues
min = [min_concurrency, max].min min = [min_concurrency, max].min
concurrency_from_queues.clamp(min, max) concurrency_from_queues.clamp(min, max)
......
...@@ -239,7 +239,7 @@ module Gitlab ...@@ -239,7 +239,7 @@ module Gitlab
memory_growth_kb = get_job_options(job, 'memory_killer_memory_growth_kb', 0).to_i memory_growth_kb = get_job_options(job, 'memory_killer_memory_growth_kb', 0).to_i
max_memory_growth_kb = get_job_options(job, 'memory_killer_max_memory_growth_kb', DEFAULT_MAX_MEMORY_GROWTH_KB).to_i max_memory_growth_kb = get_job_options(job, 'memory_killer_max_memory_growth_kb', DEFAULT_MAX_MEMORY_GROWTH_KB).to_i
return 0 if memory_growth_kb.zero? return 0 if memory_growth_kb == 0
time_elapsed = [Gitlab::Metrics::System.monotonic_time - job[:started_at], 0].max time_elapsed = [Gitlab::Metrics::System.monotonic_time - job[:started_at], 0].max
[memory_growth_kb * time_elapsed, max_memory_growth_kb].min [memory_growth_kb * time_elapsed, max_memory_growth_kb].min
......
...@@ -55,7 +55,7 @@ module Gitlab ...@@ -55,7 +55,7 @@ module Gitlab
def get_rss def get_rss
output, status = Gitlab::Popen.popen(%W(ps -o rss= -p #{pid}), Rails.root.to_s) output, status = Gitlab::Popen.popen(%W(ps -o rss= -p #{pid}), Rails.root.to_s)
return 0 unless status.zero? return 0 unless status == 0
output.to_i output.to_i
end end
......
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
# #
# Returns true or false. # Returns true or false.
def self.all_completed?(job_ids) def self.all_completed?(job_ids)
self.num_running(job_ids).zero? self.num_running(job_ids) == 0
end end
# Returns true if the given job is running or enqueued. # Returns true if the given job is running or enqueued.
......
...@@ -23,14 +23,14 @@ module Gitlab ...@@ -23,14 +23,14 @@ module Gitlab
def text def text
message = ["**#{status_text(resource)}**"] message = ["**#{status_text(resource)}**"]
if resource.upvotes.zero? && resource.downvotes.zero? && resource.user_notes_count.zero? if resource.upvotes == 0 && resource.downvotes == 0 && resource.user_notes_count == 0
return message.join return message.join
end end
message << " · " message << " · "
message << ":+1: #{resource.upvotes} " unless resource.upvotes.zero? message << ":+1: #{resource.upvotes} " unless resource.upvotes == 0
message << ":-1: #{resource.downvotes} " unless resource.downvotes.zero? message << ":-1: #{resource.downvotes} " unless resource.downvotes == 0
message << ":speech_balloon: #{resource.user_notes_count}" unless resource.user_notes_count.zero? message << ":speech_balloon: #{resource.user_notes_count}" unless resource.user_notes_count == 0
message.join message.join
end end
......
...@@ -95,7 +95,7 @@ module Gitlab ...@@ -95,7 +95,7 @@ module Gitlab
def run_command!(command) def run_command!(command)
output, status = Gitlab::Popen.popen(command) output, status = Gitlab::Popen.popen(command)
raise Gitlab::TaskFailedError.new(output) unless status.zero? raise Gitlab::TaskFailedError.new(output) unless status == 0
output output
end end
......
...@@ -31,7 +31,7 @@ module Gitlab ...@@ -31,7 +31,7 @@ module Gitlab
def scan(text) def scan(text)
matches = scan_regexp.scan(text).to_a matches = scan_regexp.scan(text).to_a
matches.map!(&:first) if regexp.number_of_capturing_groups.zero? matches.map!(&:first) if regexp.number_of_capturing_groups == 0
matches matches
end end
...@@ -68,7 +68,7 @@ module Gitlab ...@@ -68,7 +68,7 @@ module Gitlab
# groups, so work around it # groups, so work around it
def scan_regexp def scan_regexp
@scan_regexp ||= @scan_regexp ||=
if regexp.number_of_capturing_groups.zero? if regexp.number_of_capturing_groups == 0
RE2::Regexp.new('(' + regexp.source + ')') RE2::Regexp.new('(' + regexp.source + ')')
else else
regexp regexp
......
...@@ -213,7 +213,7 @@ module Gitlab ...@@ -213,7 +213,7 @@ module Gitlab
def normalize_localhost_address(instance) def normalize_localhost_address(instance)
ip_addr = IPAddr.new(instance) ip_addr = IPAddr.new(instance)
is_local_ip = ip_addr.loopback? || ip_addr.to_i.zero? is_local_ip = ip_addr.loopback? || ip_addr.to_i == 0
is_local_ip ? 'localhost' : instance is_local_ip ? 'localhost' : instance
rescue IPAddr::InvalidAddressError rescue IPAddr::InvalidAddressError
......
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
def ensure_utf8_size(str, bytes:) def ensure_utf8_size(str, bytes:)
raise ArgumentError, 'Empty string provided!' if str.empty? raise ArgumentError, 'Empty string provided!' if str.empty?
raise ArgumentError, 'Negative string size provided!' if bytes.negative? raise ArgumentError, 'Negative string size provided!' if bytes < 0
truncated = str.each_char.each_with_object(+'') do |char, object| truncated = str.each_char.each_with_object(+'') do |char, object|
if object.bytesize + char.bytesize > bytes if object.bytesize + char.bytesize > bytes
......
...@@ -32,7 +32,7 @@ module SystemCheck ...@@ -32,7 +32,7 @@ module SystemCheck
def only_one_sidekiq_running def only_one_sidekiq_running
process_count = sidekiq_process_count process_count = sidekiq_process_count
return if process_count.zero? return if process_count == 0
$stdout.print 'Number of Sidekiq processes ... ' $stdout.print 'Number of Sidekiq processes ... '
......
...@@ -17,7 +17,7 @@ Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]") ...@@ -17,7 +17,7 @@ Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
command = [] command = []
_, status = Gitlab::Popen.popen(%w[which gmake]) _, status = Gitlab::Popen.popen(%w[which gmake])
command << (status.zero? ? 'gmake' : 'make') command << (status == 0 ? 'gmake' : 'make')
if Rails.env.test? if Rails.env.test?
command.push( command.push(
......
...@@ -13,7 +13,7 @@ namespace :gitlab do ...@@ -13,7 +13,7 @@ namespace :gitlab do
raise "Please supply the list of ids through the SNIPPET_IDS env var" raise "Please supply the list of ids through the SNIPPET_IDS env var"
end end
raise "Invalid limit value" if limit.zero? raise "Invalid limit value" if limit == 0
if migration_running? if migration_running?
raise "There are already snippet migrations running. Please wait until they are finished." raise "There are already snippet migrations running. Please wait until they are finished."
...@@ -37,7 +37,7 @@ namespace :gitlab do ...@@ -37,7 +37,7 @@ namespace :gitlab do
def parse_snippet_ids! def parse_snippet_ids!
ids = ENV['SNIPPET_IDS'].delete(' ').split(',').map do |id| ids = ENV['SNIPPET_IDS'].delete(' ').split(',').map do |id|
id.to_i.tap do |value| id.to_i.tap do |value|
raise "Invalid id provided" if value.zero? raise "Invalid id provided" if value == 0
end end
end end
...@@ -68,10 +68,10 @@ namespace :gitlab do ...@@ -68,10 +68,10 @@ namespace :gitlab do
# bundle exec rake gitlab:snippets:list_non_migrated LIMIT=50 # bundle exec rake gitlab:snippets:list_non_migrated LIMIT=50
desc 'GitLab | Show non migrated snippets' desc 'GitLab | Show non migrated snippets'
task list_non_migrated: :environment do task list_non_migrated: :environment do
raise "Invalid limit value" if limit.zero? raise "Invalid limit value" if limit == 0
non_migrated_count = non_migrated_snippets.count non_migrated_count = non_migrated_snippets.count
if non_migrated_count.zero? if non_migrated_count == 0
puts "All snippets have been successfully migrated" puts "All snippets have been successfully migrated"
else else
puts "There are #{non_migrated_count} snippets that haven't been migrated. Showing a batch of ids of those snippets:\n" puts "There are #{non_migrated_count} snippets that haven't been migrated. Showing a batch of ids of those snippets:\n"
......
...@@ -15,7 +15,7 @@ namespace :gitlab do ...@@ -15,7 +15,7 @@ namespace :gitlab do
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1]) checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
_, status = Gitlab::Popen.popen(%w[which gmake]) _, status = Gitlab::Popen.popen(%w[which gmake])
command = status.zero? ? 'gmake' : 'make' command = status == 0 ? 'gmake' : 'make'
Dir.chdir(args.dir) do Dir.chdir(args.dir) do
run_command!([command]) run_command!([command])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment