Skip to content

Commit

Permalink
Correct Style/FetchEnvVar rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
krauselukas committed Apr 22, 2022
1 parent d0b3063 commit e084c32
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dist/openQA_mail_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def send_notification(from, to, subject, message)
body message
end
settings = { address: SMTP_SERVER, port: 25, enable_starttls_auto: false }
settings[:domain] = ENV['HOSTNAME'] if ENV['HOSTNAME'].present?
settings[:domain] = ENV.fetch('HOSTNAME') if ENV.fetch('HOSTNAME', nil).present?
mail.delivery_method :smtp, settings
mail.deliver
rescue Exception => e
Expand Down
6 changes: 3 additions & 3 deletions src/api/config/initializers/airbrake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
# Configuration details:
# https://github.com/airbrake/airbrake-ruby#configuration
Airbrake.configure do |c|
c.host = CONFIG['errbit_host'] || ENV['ERRBIT_HOST']
c.host = CONFIG['errbit_host'] || ENV.fetch('ERRBIT_HOST', nil)
# You must set both project_id & project_key. To find your project_id and
# project_key navigate to your project's General Settings and copy the values
# from the right sidebar.
# https://github.com/airbrake/airbrake-ruby#project_id--project_key
c.project_id = CONFIG['errbit_project_id'] || ENV['ERRBIT_PROJECT_ID']
c.project_key = CONFIG['errbit_api_key'] || ENV['ERRBIT_API_KEY']
c.project_id = CONFIG['errbit_project_id'] || ENV.fetch('ERRBIT_PROJECT_ID', nil)
c.project_key = CONFIG['errbit_api_key'] || ENV.fetch('ERRBIT_API_KEY', nil)
c.app_version = CONFIG['version']

# Configures the root directory of your project. Expects a String or a
Expand Down
4 changes: 2 additions & 2 deletions src/api/lib/tasks/delayed_job.rake
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ namespace :consistency do

desc('Check project for consistency now, specify project with: project=MyProject')
task(check: [:environment, :project_environment]) do
puts ConsistencyCheckJob.new.check_project(ENV['project'])
puts ConsistencyCheckJob.new.check_project(ENV.fetch('project', nil))
end

desc('Fix inconsitent projects now, specify project with: project=MyProject')
task(fix: [:environment, :project_environment]) do
ConsistencyCheckJob.new.fix_project(ENV['project'])
ConsistencyCheckJob.new.fix_project(ENV.fetch('project', nil))
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/tasks/extract.rake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace :db do
desc 'Create YAML test fixtures from data in test database.'

task extract_fixtures: :environment do
raise 'You only want to run this in test environment' unless ENV['RAILS_ENV'] == 'test'
raise 'You only want to run this in test environment' unless ENV.fetch('RAILS_ENV', nil) == 'test'

sql = 'SELECT * FROM %s'
skip_tables = ['schema_info', 'sessions', 'schema_migrations']
Expand Down
4 changes: 2 additions & 2 deletions src/api/script/start_test_backend
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ port_src_server = 3200
port_rep_server = 3201
port_service_server = 3202
backend_dir_suffix = ''
if ENV['origin_RAILS_ENV'] == 'development'
if ENV.fetch('origin_RAILS_ENV', nil) == 'development'
port_src_server = 6200
port_rep_server = 6201
port_service_server = 6202
backend_dir_suffix = '_development'
end

backendtempdir = ENV['OBS_BACKEND_TEMP'] || "#{Rails.root}/tmp"
backendtempdir = ENV.fetch('OBS_BACKEND_TEMP', nil) || "#{Rails.root}/tmp"
backend_config = "#{backendtempdir}/config#{backend_dir_suffix}"
backend_data = "#{backendtempdir}/data#{backend_dir_suffix}"
require __dir__ + '/../test/test_helper'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/support/coverage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# for tracking test coverage
if ENV['CIRCLE_ARTIFACTS']
dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')
dir = File.join(ENV.fetch('CIRCLE_ARTIFACTS', nil), 'coverage')
SimpleCov.coverage_dir(dir)
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/backend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_validate_bsxml
end

# rubocop:disable Layout/LineLength
r = system("cd #{ENV['OBS_BACKEND_TEMP']}/config; exec perl #{perlopts} -mXML::Structured -mBSXML -mBSUtil -e \"use XML::Structured ':bytes'; BSUtil::readxml('#{dir}#{f}', \\\$BSXML::#{schema}, 0);\" 2>&1")
r = system("cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/config; exec perl #{perlopts} -mXML::Structured -mBSXML -mBSUtil -e \"use XML::Structured ':bytes'; BSUtil::readxml('#{dir}#{f}', \\\$BSXML::#{schema}, 0);\" 2>&1")
# rubocop:enable Layout/LineLength
assert_equal true, r
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/channel_maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def test_large_channel_test
assert_xml_tag tag: 'entry', attributes: { name: 'primary.xml.gz' }
assert_xml_tag tag: 'entry', attributes: { name: 'repomd.xml' }
assert_xml_tag tag: 'entry', attributes: { name: 'updateinfo.xml.gz' } # by modifyrepo
IO.popen("gunzip -cd #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro3Channel/channel_repo/repodata/updateinfo.xml.gz") do |io|
IO.popen("gunzip -cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro3Channel/channel_repo/repodata/updateinfo.xml.gz") do |io|
node = Xmlhash.parse(io.read)
end
assert_equal "UpdateInfoTagNew-patch_name-#{Time.now.year}-1", node['update']['id']
Expand Down
16 changes: 8 additions & 8 deletions src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1592,12 +1592,12 @@ def test_create_maintenance_project_and_release_packages
assert_xml_tag tag: 'description'
assert_xml_tag tag: 'mtime'
hashed = node = nil
IO.popen("gunzip -cd #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/*-updateinfo.xml.gz") do |io|
IO.popen("gunzip -cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/*-updateinfo.xml.gz") do |io|
node = REXML::Document.new(io.read)
end
assert_equal "My-oldname-#{Time.now.year}-1", node.elements['/updates/update/id'].first.to_s
# verify meta data created by createrepo
IO.popen("gunzip -cd #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/*-primary.xml.gz") do |io|
IO.popen("gunzip -cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/*-primary.xml.gz") do |io|
hashed = Xmlhash.parse(io.read)
end
pac = nil
Expand Down Expand Up @@ -1630,13 +1630,13 @@ def test_create_maintenance_project_and_release_packages
puts 'WARNING: some tests are skipped on non-SUSE systems. rpmmd meta data may not be complete.'
end
# file lists
IO.popen("gunzip -cd #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/*-filelists.xml.gz") do |io|
IO.popen("gunzip -cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/*-filelists.xml.gz") do |io|
hashed = Xmlhash.parse(io.read)
end
# STDERR.puts JSON.pretty_generate(hashed)
assert hashed['package'].map { |f| f['file'] }.include?('/my_packaged_file')
# master tags
IO.popen("cat #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/repomd.xml") do |io|
IO.popen("cat #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro2.0:/LinkedUpdateProject/BaseDistro2LinkedUpdateProject_repo/repodata/repomd.xml") do |io|
hashed = Xmlhash.parse(io.read)
end
# check repository markers
Expand Down Expand Up @@ -2460,7 +2460,7 @@ def test_copy_project_with_history_and_binaries

def test_copy_project_for_release_with_history
# Backup
system("for i in #{ENV['OBS_BACKEND_TEMP']}/data/projects/BaseDistro.pkg/*.rev; do cp $i $i.backup; done")
system("for i in #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/projects/BaseDistro.pkg/*.rev; do cp $i $i.backup; done")

# store revisions before copy
login_king
Expand Down Expand Up @@ -2520,7 +2520,7 @@ def test_copy_project_for_release_with_history
assert_equal 'king', last_revision(copyhistory).value('user')

# cleanup
system("for i in #{ENV['OBS_BACKEND_TEMP']}/data/projects/BaseDistro.pkg/*.rev; do mv $i.backup $i; done")
system("for i in #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/projects/BaseDistro.pkg/*.rev; do mv $i.backup $i; done")
delete '/source/CopyOfBaseDistro'
assert_response :success
end
Expand All @@ -2542,7 +2542,7 @@ def test_copy_from_origin_with_modification_has_write_permission_check

def test_copy_project_for_release_using_makeoriginolder
# Backup
system("for i in #{ENV['OBS_BACKEND_TEMP']}/data/projects/BaseDistro.pkg/*.rev; do cp $i $i.backup; done")
system("for i in #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/projects/BaseDistro.pkg/*.rev; do cp $i $i.backup; done")

# store revisions before copy
login_tom
Expand Down Expand Up @@ -2604,7 +2604,7 @@ def test_copy_project_for_release_using_makeoriginolder
assert_equal 'king', last_revision(copyhistory).value('user')

# cleanup
system("for i in #{ENV['OBS_BACKEND_TEMP']}/data/projects/BaseDistro.pkg/*.rev; do mv $i.backup $i; done")
system("for i in #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/projects/BaseDistro.pkg/*.rev; do mv $i.backup $i; done")
delete '/source/CopyOfBaseDistro'
assert_response :success
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/functional/published_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_rpm_md_formats

# verify meta data created by create_package_descr
package_seen = {}
IO.popen("gunzip -cd #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro3/BaseDistro3_repo/repodata/*-primary.xml.gz") do |io|
IO.popen("gunzip -cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro3/BaseDistro3_repo/repodata/*-primary.xml.gz") do |io|
hashed = Xmlhash.parse(io.read)
hashed.elements('package').each do |p|
next unless (p['name'] == 'package' && p['arch'] == 'i586') || (p['name'] == 'package_newweaktags' && p['arch'] == 'x86_64')
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_rpm_md_formats

# master tags
hashed = nil
IO.popen("cat #{ENV['OBS_BACKEND_TEMP']}/data/repos/BaseDistro3/BaseDistro3_repo/repodata/repomd.xml") do |io|
IO.popen("cat #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/repos/BaseDistro3/BaseDistro3_repo/repodata/repomd.xml") do |io|
hashed = Xmlhash.parse(io.read)
end
if File.exist?('/var/adm/fillup-templates') || File.exist?('/usr/share/fillup-templates/')
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/functional/source_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4150,7 +4150,7 @@ def test_obscpio_deltastore
assert_response :success
before_deltastore = @response.body

deltastore = "#{ENV['OBS_BACKEND_TEMP']}/data/sources/deltapack/deltastore"
deltastore = "#{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/sources/deltapack/deltastore"

assert_not File.exist?(deltastore)
run_deltastore
Expand All @@ -4160,7 +4160,7 @@ def test_obscpio_deltastore
assert_response :success
assert_equal before_deltastore, @response.body

assert 0, run_admin("--show-delta-file #{ENV['OBS_BACKEND_TEMP']}/data/sources/deltapack/c1b8dd35488695c3c248f0acd447b4d5-archive.obscpio")
assert 0, run_admin("--show-delta-file #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data/sources/deltapack/c1b8dd35488695c3c248f0acd447b4d5-archive.obscpio")

delete '/source/home:tom:deltastore'
assert_response :success
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/zzz_post_consistency_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_fsck_backend

progress = nil
failed = nil
IO.popen("cd #{ENV['OBS_BACKEND_TEMP']}/config; exec perl #{perlopts} ./bs_check_consistency --check-all --do-check-meta --do-check-signatures 2>&1") do |io|
IO.popen("cd #{ENV.fetch('OBS_BACKEND_TEMP', nil)}/config; exec perl #{perlopts} ./bs_check_consistency --check-all --do-check-meta --do-check-signatures 2>&1") do |io|
io.each do |line|
# puts ">#{line}<"
next if line.blank?
Expand Down
12 changes: 6 additions & 6 deletions src/api/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENV['origin_RAILS_ENV'] = ENV['RAILS_ENV']
ENV['origin_RAILS_ENV'] = ENV.fetch('RAILS_ENV', nil)

ENV['RAILS_ENV'] = 'test'
ENV['RUNNING_MINITEST'] = '1'
Expand All @@ -10,7 +10,7 @@
Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)

if ENV['DO_COVERAGE']
ENV['CODECOV_FLAG'] = ENV['CIRCLE_STAGE']
ENV['CODECOV_FLAG'] = ENV.fetch('CIRCLE_STAGE', nil)
SimpleCov.start 'rails' do
# NOTE: Keep filters in sync with spec/support/coverage.rb
add_filter '/app/indices/'
Expand Down Expand Up @@ -66,14 +66,14 @@

def backend_config
backend_dir_suffix = ''
backend_dir_suffix = '_development' if ENV['origin_RAILS_ENV'] == 'development'
"#{ENV['OBS_BACKEND_TEMP']}/config#{backend_dir_suffix}"
backend_dir_suffix = '_development' if ENV.fetch('origin_RAILS_ENV', nil) == 'development'
"#{ENV.fetch('OBS_BACKEND_TEMP', nil)}/config#{backend_dir_suffix}"
end

def backend_data
backend_dir_suffix = ''
backend_dir_suffix = '_development' if ENV['origin_RAILS_ENV'] == 'development'
"#{ENV['OBS_BACKEND_TEMP']}/data#{backend_dir_suffix}"
backend_dir_suffix = '_development' if ENV.fetch('origin_RAILS_ENV', nil) == 'development'
"#{ENV.fetch('OBS_BACKEND_TEMP', nil)}/data#{backend_dir_suffix}"
end

def inject_build_job(project, package, repo, arch, extrabinary = nil)
Expand Down

0 comments on commit e084c32

Please sign in to comment.