Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
Some code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
KrauseFx committed Jul 20, 2015
1 parent c6a43cf commit b1877ab
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 42 deletions.
32 changes: 16 additions & 16 deletions lib/pilot/commands_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,39 @@ def run
end
end

command :import do |c|
c.syntax = "import"
c.description = "Create external testers from a CSV file"
command :find do |c|
c.syntax = "find"
c.description = "Find a tester (internal or external) by their email address"
c.action do |_args, options|
config = FastlaneCore::Configuration.create(Pilot::Options.available_options, convert_options(options))
Pilot::TesterImporter.new.import_testers(config)
Pilot::TesterManager.new.find_tester(config)
end
end

command :export do |c|
c.syntax = "export"
c.description = "Exports all external testers to a CSV file"
command :remove do |c|
c.syntax = "remove"
c.description = "Remove an external tester by their email address"
c.action do |_args, options|
config = FastlaneCore::Configuration.create(Pilot::Options.available_options, convert_options(options))
Pilot::TesterExporter.new.export_testers(config)
Pilot::TesterManager.new.remove_tester(config)
end
end

command :find do |c|
c.syntax = "find"
c.description = "Find a tester (internal or external) by their email address"
command :export do |c|
c.syntax = "export"
c.description = "Exports all external testers to a CSV file"
c.action do |_args, options|
config = FastlaneCore::Configuration.create(Pilot::Options.available_options, convert_options(options))
Pilot::TesterManager.new.find_tester(config)
Pilot::TesterExporter.new.export_testers(config)
end
end

command :remove do |c|
c.syntax = "remove"
c.description = "Remove an external tester by their email address"
command :import do |c|
c.syntax = "import"
c.description = "Create external testers from a CSV file"
c.action do |_args, options|
config = FastlaneCore::Configuration.create(Pilot::Options.available_options, convert_options(options))
Pilot::TesterManager.new.remove_tester(config)
Pilot::TesterImporter.new.import_testers(config)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/pilot/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def self.available_options
short_option: "-c",
env_name: "PILOT_TESTERS_FILE",
description: "Path to a CSV file of testers",
default_value: "./testers.csv",
optional: true,
verify_block: proc do |_value|
end)
Expand Down
18 changes: 3 additions & 15 deletions lib/pilot/tester_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,14 @@ def export_testers(options)

group_names = ""
if groups && groups.length > 0
names << groups.map { |group| group["name"]["value"] }
names = groups.map { |group| group["name"]["value"] }
group_names = names.join(';')
end

install_version = ""
install_date = ""

latest_installed_date = tester.raw_data.get("latestInstalledDate")
if latest_installed_date
install_date = Time.at((latest_installed_date / 1000)).strftime("%m/%d/%y %H:%M")

latest_installed_version = tester.raw_data.get("latestInstalledVersion")
latest_installed_short_version = tester.raw_data.get("latestInstalledShortVersion")
install_version = "#{latest_installed_version} (#{latest_installed_short_version})"
end

csv << [tester.first_name, tester.last_name, tester.email, tester.devices.count, group_names, install_version, install_date]
csv << [tester.first_name, tester.last_name, tester.email, tester.devices.count, group_names]
end

Helper.log.info "Exported CSV to #{file}".green
Helper.log.info "Successfully exported CSV to #{file}".green
end

end
Expand Down
21 changes: 10 additions & 11 deletions lib/pilot/tester_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ def import_testers(options)
tester_manager = Pilot::TesterManager.new
imported_tester_count = 0

is_first = true
CSV.foreach(file, "r") do |row|

begin
first_name = row[0]
last_name = row[1]
email = row[2]
rescue => ex
Helper.log.error "Invalid format for row: #{row}".red
if is_first
is_first = false
next
end

if email.nil?
Helper.log.error "No email in row: #{row}".red
first_name, last_name, email = row

unless email
Helper.log.error "No email found in row: #{row}".red
next
end

# Add this the existing config hash to pass it to the TesterManager
config[:first_name] = first_name
config[:last_name] = last_name
config[:email] = email
Expand All @@ -41,8 +41,7 @@ def import_testers(options)

end

Helper.log.info "Imported #{imported_tester_count} testers from #{file}".green

Helper.log.info "Successfully imported #{imported_tester_count} testers from #{file}".green
end
end
end

0 comments on commit b1877ab

Please sign in to comment.