Skip to content

Commit

Permalink
RuboCop: apply Style/FetchEnvVar rule throughout codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerluan committed Aug 17, 2023
1 parent 42f0790 commit e122484
Show file tree
Hide file tree
Showing 74 changed files with 223 additions and 223 deletions.
2 changes: 1 addition & 1 deletion cert/lib/cert/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class << self
Boolean = Fastlane::Boolean
ROOT = Pathname.new(File.expand_path('../../..', __FILE__))

ENV['FASTLANE_TEAM_ID'] ||= ENV["CERT_TEAM_ID"]
ENV['FASTLANE_TEAM_ID'] ||= ENV.fetch("CERT_TEAM_ID", nil)
end
6 changes: 3 additions & 3 deletions cert/lib/cert/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Runner
def launch
run

installed = FastlaneCore::CertChecker.installed?(ENV["CER_FILE_PATH"], in_keychain: ENV["CER_KEYCHAIN_PATH"])
installed = FastlaneCore::CertChecker.installed?(ENV.fetch("CER_FILE_PATH", nil), in_keychain: ENV.fetch("CER_KEYCHAIN_PATH", nil))
UI.message("Verifying the certificate is properly installed locally...")
UI.user_error!("Could not find the newly generated certificate installed", show_github_issues: true) unless installed
UI.success("Successfully installed certificate #{ENV['CER_CERTIFICATE_ID']}")
return ENV["CER_FILE_PATH"]
UI.success("Successfully installed certificate #{ENV.fetch('CER_CERTIFICATE_ID', nil)}")
return ENV.fetch("CER_FILE_PATH", nil)
end

def login
Expand Down
8 changes: 4 additions & 4 deletions cert/spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
Cert.config = FastlaneCore::Configuration.create(Cert::Options.available_options, options)

Cert::Runner.new.launch
expect(ENV["CER_CERTIFICATE_ID"]).to eq("cert_id")
expect(ENV["CER_FILE_PATH"]).to eq(certificate_path)
expect(ENV["CER_KEYCHAIN_PATH"]).to eq(keychain_path)
File.delete(ENV["CER_FILE_PATH"])
expect(ENV.fetch("CER_CERTIFICATE_ID", nil)).to eq("cert_id")
expect(ENV.fetch("CER_FILE_PATH", nil)).to eq(certificate_path)
expect(ENV.fetch("CER_KEYCHAIN_PATH", nil)).to eq(keychain_path)
File.delete(ENV.fetch("CER_FILE_PATH", nil))
end

it "correctly selects expired certificates" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def default_prefix?

def user
if default_prefix?
@user ||= ENV["FASTLANE_USER"]
@user ||= ENV["DELIVER_USER"]
@user ||= ENV.fetch("FASTLANE_USER", nil)
@user ||= ENV.fetch("DELIVER_USER", nil)
@user ||= AppfileConfig.try_fetch_value(:apple_id)
end

Expand All @@ -39,7 +39,7 @@ def user
end

def fetch_password_from_env
password = ENV["FASTLANE_PASSWORD"] || ENV["DELIVER_PASSWORD"]
password = ENV["FASTLANE_PASSWORD"] || ENV.fetch("DELIVER_PASSWORD", nil)
return password if password.to_s.length > 0
return nil
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def self.already_printed_debug_information
end

def fallback_to_default_values
data[:apple_id] ||= ENV["FASTLANE_USER"] || ENV["DELIVER_USER"] || ENV["DELIVER_USERNAME"]
data[:apple_id] ||= ENV["FASTLANE_USER"] || ENV["DELIVER_USER"] || ENV.fetch("DELIVER_USERNAME", nil)
end

def data
Expand Down
2 changes: 1 addition & 1 deletion deliver/lib/deliver/commands_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def deliverfile_options(skip_verification: false)

def self.force_overwrite_metadata?(options, path)
res = options[:force]
res ||= ENV["DELIVER_FORCE_OVERWRITE"] # for backward compatibility
res ||= ENV.fetch("DELIVER_FORCE_OVERWRITE", nil) # for backward compatibility
res ||= UI.confirm("Do you want to overwrite existing metadata on path '#{File.expand_path(path)}'?") if UI.interactive?
res
end
Expand Down
2 changes: 1 addition & 1 deletion deliver/lib/deliver/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Options
def self.available_options
user = CredentialsManager::AppfileConfig.try_fetch_value(:itunes_connect_id)
user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)
user ||= ENV["DELIVER_USER"]
user ||= ENV.fetch("DELIVER_USER", nil)

[
FastlaneCore::ConfigItem.new(key: :api_key_path,
Expand Down
6 changes: 3 additions & 3 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ lane :bump do |options|
ensure_git_branch(branch: "master")
ensure_git_status_clean

github_api_token = ENV["FL_GITHUB_RELEASE_API_TOKEN"]
github_api_token = ENV.fetch("FL_GITHUB_RELEASE_API_TOKEN", nil)
UI.user_error!("Please provide a GitHub API token using `FL_GITHUB_RELEASE_API_TOKEN`") if github_api_token.to_s.length == 0
paths_for_commit = []

Expand Down Expand Up @@ -338,7 +338,7 @@ private_lane :send_mac_app_ci_reminder do
slack_url: ENV['FABRIC_SLACK_URL'],
channel: 'deployment-tools',
default_payloads: [],
message: "Please run the Fastlane Mac App Package CI job in TeamCity\n#{ENV['FABRIC_MAC_APP_CI_JOB_URL']}"
message: "Please run the Fastlane Mac App Package CI job in TeamCity\n#{ENV.fetch('FABRIC_MAC_APP_CI_JOB_URL', nil)}"
)
end
end
Expand Down Expand Up @@ -511,7 +511,7 @@ lane :update_docs do |options|

# Submit the pull request
pr_url = create_pull_request(
api_token: ENV["FL_GITHUB_RELEASE_API_TOKEN"],
api_token: ENV.fetch("FL_GITHUB_RELEASE_API_TOKEN", nil),
repo: "fastlane/docs",
title: "[Bot] Update docs for latest fastlane release #{version} (actions.md, available-plugins.md) 馃殌",
body: "Auto-generated by _fastlane_ bot 馃"
Expand Down
4 changes: 2 additions & 2 deletions fastlane/helper/plugin_scores_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def append_github_data
builder.use(FaradayMiddleware::FollowRedirects)
builder.adapter(Faraday.default_adapter)
end
conn.basic_auth(ENV["GITHUB_USER_NAME"], ENV["GITHUB_API_TOKEN"])
conn.basic_auth(ENV.fetch("GITHUB_USER_NAME", nil), ENV.fetch("GITHUB_API_TOKEN", nil))
response = conn.get('')
repo_details = JSON.parse(response.body)

Expand All @@ -260,7 +260,7 @@ def append_github_data
builder.adapter(Faraday.default_adapter)
end

conn.basic_auth(ENV["GITHUB_USER_NAME"], ENV["GITHUB_API_TOKEN"])
conn.basic_auth(ENV.fetch("GITHUB_USER_NAME", nil), ENV.fetch("GITHUB_API_TOKEN", nil))
response = conn.get('')
contributor_details = JSON.parse(response.body)

Expand Down
4 changes: 2 additions & 2 deletions fastlane/lib/fastlane/actions/apteligent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def self.upload_url(app_id)

def self.dsym_path(params)
file_path = params[:dsym]
file_path ||= Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] || ENV[SharedValues::DSYM_OUTPUT_PATH.to_s]
file_path ||= Actions.lane_context[SharedValues::DSYM_ZIP_PATH] || ENV[SharedValues::DSYM_ZIP_PATH.to_s]
file_path ||= Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] || ENV.fetch(SharedValues::DSYM_OUTPUT_PATH.to_s, nil)
file_path ||= Actions.lane_context[SharedValues::DSYM_ZIP_PATH] || ENV.fetch(SharedValues::DSYM_ZIP_PATH.to_s, nil)

if file_path
expanded_file_path = File.expand_path(file_path)
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/commit_github_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def self.available_options
conflicting_options: [:api_bearer],
sensitive: true,
code_gen_sensitive: true,
default_value: ENV["GITHUB_API_TOKEN"],
default_value: ENV.fetch("GITHUB_API_TOKEN", nil),
default_value_dynamic: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :api_bearer,
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/create_pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def self.available_options
description: "Personal API Token for GitHub - generate one at https://github.com/settings/tokens",
sensitive: true,
code_gen_sensitive: true,
default_value: ENV["GITHUB_API_TOKEN"],
default_value: ENV.fetch("GITHUB_API_TOKEN", nil),
default_value_dynamic: true,
conflicting_options: [:api_bearer],
optional: true),
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/environment_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.run(params)
end

# finally, get the variable we requested
return ENV[value_to_get] unless value_to_get.nil?
return ENV.fetch(value_to_get, nil) unless value_to_get.nil?

# if no variable is requested, just return empty string
return ""
Expand Down
4 changes: 2 additions & 2 deletions fastlane/lib/fastlane/actions/get_certificates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def self.run(params)
Cert.config = params # we alread have the finished config

Cert::Runner.new.launch
cert_file_path = ENV["CER_FILE_PATH"]
certificate_id = ENV["CER_CERTIFICATE_ID"]
cert_file_path = ENV.fetch("CER_FILE_PATH", nil)
certificate_id = ENV.fetch("CER_CERTIFICATE_ID", nil)
Actions.lane_context[SharedValues::CERT_FILE_PATH] = cert_file_path
Actions.lane_context[SharedValues::CERT_CERTIFICATE_ID] = certificate_id

Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/get_github_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def self.available_options
env_name: "FL_GITHUB_RELEASE_API_TOKEN",
sensitive: true,
code_gen_sensitive: true,
default_value: ENV["GITHUB_API_TOKEN"],
default_value: ENV.fetch("GITHUB_API_TOKEN", nil),
default_value_dynamic: true,
description: "GitHub Personal Token (required for private repositories)",
conflicting_options: [:api_bearer],
Expand Down
6 changes: 3 additions & 3 deletions fastlane/lib/fastlane/actions/get_provisioning_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def self.run(values)
Actions.lane_context[SharedValues::SIGH_PROFILE_PATHS] ||= []
Actions.lane_context[SharedValues::SIGH_PROFILE_PATHS] << path

uuid = ENV["SIGH_UUID"] || ENV["SIGH_UDID"] # the UUID of the profile
name = ENV["SIGH_NAME"] # the name of the profile
uuid = ENV["SIGH_UUID"] || ENV.fetch("SIGH_UDID", nil) # the UUID of the profile
name = ENV.fetch("SIGH_NAME", nil) # the name of the profile
Actions.lane_context[SharedValues::SIGH_UUID] = Actions.lane_context[SharedValues::SIGH_UDID] = uuid if uuid
Actions.lane_context[SharedValues::SIGH_NAME] = Actions.lane_context[SharedValues::SIGH_NAME] = name if name

set_profile_type(values, ENV["SIGH_PROFILE_ENTERPRISE"])
set_profile_type(values, ENV.fetch("SIGH_PROFILE_ENTERPRISE", nil))

return uuid # returs uuid of profile
end
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/github_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def available_options
conflicting_options: [:api_bearer],
sensitive: true,
code_gen_sensitive: true,
default_value: ENV["GITHUB_API_TOKEN"],
default_value: ENV.fetch("GITHUB_API_TOKEN", nil),
default_value_dynamic: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :api_bearer,
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/install_xcode_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.run(params)

zip_path = File.join(Dir.tmpdir, 'plugin.zip')
sh("curl -Lso #{zip_path} #{params[:url]}")
plugins_path = "#{ENV['HOME']}/Library/Application Support/Developer/Shared/Xcode/Plug-ins"
plugins_path = "#{ENV.fetch('HOME', nil)}/Library/Application Support/Developer/Shared/Xcode/Plug-ins"
FileUtils.mkdir_p(plugins_path)
Action.sh("unzip -qo '#{zip_path}' -d '#{plugins_path}'")

Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/ipa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def self.params_to_build_args(config)
end

def self.fill_in_default_values(params)
embed = Actions.lane_context[Actions::SharedValues::SIGH_PROFILE_PATH] || ENV["SIGH_PROFILE_PATH"]
embed = Actions.lane_context[Actions::SharedValues::SIGH_PROFILE_PATH] || ENV.fetch("SIGH_PROFILE_PATH", nil)
params[:embed] ||= embed if embed
params
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.run(params)

if Helper.ci? || Helper.test?
# The "BUILD_URL" environment variable is set automatically by Jenkins in every build
jenkins_api_url = URI(ENV["BUILD_URL"] + "api/json\?wrapper\=changes\&xpath\=//changeSet//comment")
jenkins_api_url = URI(ENV.fetch("BUILD_URL", nil) + "api/json?wrapper=changes&xpath=//changeSet//comment")
begin
json = JSON.parse(Net::HTTP.get(jenkins_api_url))
json['changeSet']['items'].each do |item|
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/notarize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def self.notarytool(params, package_path, bundle_id, skip_stapling, print_log, v
auth_parts << "--issuer #{api_key.issuer_id}"
else
auth_parts << "--apple-id #{params[:username]}"
auth_parts << "--password #{ENV['FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD']}"
auth_parts << "--password #{ENV.fetch('FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD', nil)}"
auth_parts << "--team-id #{params[:asc_provider]}"
end

Expand Down
8 changes: 4 additions & 4 deletions fastlane/lib/fastlane/actions/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,28 @@ def self.available_options
description: "AWS Access Key ID ",
sensitive: true,
optional: true,
default_value: ENV['AWS_ACCESS_KEY_ID'],
default_value: ENV.fetch('AWS_ACCESS_KEY_ID', nil),
default_value_dynamic: true),
FastlaneCore::ConfigItem.new(key: :secret_access_key,
env_name: "S3_SECRET_ACCESS_KEY",
description: "AWS Secret Access Key ",
sensitive: true,
optional: true,
default_value: ENV['AWS_SECRET_ACCESS_KEY'],
default_value: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
default_value_dynamic: true),
FastlaneCore::ConfigItem.new(key: :bucket,
env_name: "S3_BUCKET",
description: "AWS bucket name",
optional: true,
code_gen_sensitive: true,
default_value: ENV['AWS_BUCKET_NAME'],
default_value: ENV.fetch('AWS_BUCKET_NAME', nil),
default_value_dynamic: true),
FastlaneCore::ConfigItem.new(key: :region,
env_name: "S3_REGION",
description: "AWS region (for bucket creation) ",
optional: true,
code_gen_sensitive: true,
default_value: ENV['AWS_REGION'],
default_value: ENV.fetch('AWS_REGION', nil),
default_value_dynamic: true),
FastlaneCore::ConfigItem.new(key: :path,
env_name: "S3_PATH",
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/set_github_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def self.available_options
conflicting_options: [:api_bearer],
sensitive: true,
code_gen_sensitive: true,
default_value: ENV["GITHUB_API_TOKEN"],
default_value: ENV.fetch("GITHUB_API_TOKEN", nil),
default_value_dynamic: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :api_bearer,
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/setup_ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.setup_output_paths
return
end

root = Pathname.new(ENV["FL_OUTPUT_DIR"])
root = Pathname.new(ENV.fetch("FL_OUTPUT_DIR", nil))
ENV["SCAN_OUTPUT_DIRECTORY"] = (root + "scan").to_s
ENV["GYM_OUTPUT_DIRECTORY"] = (root + "gym").to_s
ENV["FL_BUILDLOG_PATH"] = (root + "buildlogs").to_s
Expand Down
4 changes: 2 additions & 2 deletions fastlane/lib/fastlane/actions/splunkmint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def self.upload_progress(params)

def self.dsym_path(params)
file_path = params[:dsym]
file_path ||= Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] || ENV[SharedValues::DSYM_OUTPUT_PATH.to_s]
file_path ||= Actions.lane_context[SharedValues::DSYM_ZIP_PATH] || ENV[SharedValues::DSYM_ZIP_PATH.to_s]
file_path ||= Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] || ENV.fetch(SharedValues::DSYM_OUTPUT_PATH.to_s, nil)
file_path ||= Actions.lane_context[SharedValues::DSYM_ZIP_PATH] || ENV.fetch(SharedValues::DSYM_ZIP_PATH.to_s, nil)

if file_path
expanded_file_path = File.expand_path(file_path)
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/sync_code_signing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.define_provisioning_profile_mapping(params)
app_identifier = "maccatalyst.#{app_identifier}"
end

mapping[app_identifier] = ENV[env_variable_name]
mapping[app_identifier] = ENV.fetch(env_variable_name, nil)
end

Actions.lane_context[SharedValues::MATCH_PROVISIONING_PROFILE_MAPPING] = mapping
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/update_info_plist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self.available_options
env_name: 'FL_UPDATE_PLIST_APP_IDENTIFIER',
description: 'The App Identifier of your app',
code_gen_sensitive: true,
default_value: ENV['PRODUCE_APP_IDENTIFIER'],
default_value: ENV.fetch('PRODUCE_APP_IDENTIFIER', nil),
default_value_dynamic: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :display_name,
Expand Down
4 changes: 2 additions & 2 deletions fastlane/lib/fastlane/actions/update_project_code_signing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def self.available_options
deprecated: "Use `:uuid` instead",
env_name: "FL_PROJECT_SIGNING_UDID",
code_gen_sensitive: true,
default_value: ENV["SIGH_UUID"],
default_value: ENV.fetch("SIGH_UUID", nil),
default_value_dynamic: true),
FastlaneCore::ConfigItem.new(key: :uuid,
env_name: "FL_PROJECT_SIGNING_UUID",
description: "The UUID of the provisioning profile you want to use",
code_gen_sensitive: true,
default_value: ENV["SIGH_UUID"],
default_value: ENV.fetch("SIGH_UUID", nil),
default_value_dynamic: true)
]
end
Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/auto_complete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AutoComplete
# while optionally adding custom commands for which to enable auto complete
# @param [Array] options An array of all options (e.g. --custom fl)
def self.execute(args, options)
shell = ENV['SHELL']
shell = ENV.fetch('SHELL', nil)

if shell.end_with?("fish")
fish_completions_dir = "~/.config/fish/completions"
Expand Down
4 changes: 2 additions & 2 deletions fastlane/lib/fastlane/environment_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def self.print_system_locale
if ENV[e].nil?
env_icon = ""
end
env_table << "| #{e} | #{ENV[e]} | #{env_icon} |\n"
env_table << "| #{e} | #{ENV.fetch(e, nil)} | #{env_icon} |\n"
end
if !found_one
table = "| Error |\n"
Expand Down Expand Up @@ -283,7 +283,7 @@ def self.print_fastlane_files
env_output
end

def self.anonymized_path(path, home = ENV['HOME'])
def self.anonymized_path(path, home = ENV.fetch('HOME', nil))
return home ? path.gsub(%r{^#{home}(?=/(.*)|$)}, '~\2') : path
end

Expand Down
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/helper/adb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AdbHelper
attr_accessor :devices

def initialize(adb_path: nil, adb_host: nil)
android_home = ENV['ANDROID_HOME'] || ENV['ANDROID_SDK_ROOT'] || ENV['ANDROID_SDK']
android_home = ENV['ANDROID_HOME'] || ENV['ANDROID_SDK_ROOT'] || ENV.fetch('ANDROID_SDK', nil)
if (adb_path.nil? || adb_path == "adb") && android_home
adb_path = File.join(android_home, "platform-tools", "adb")
end
Expand Down

0 comments on commit e122484

Please sign in to comment.