Module: ReleaseRobot
- Defined in:
- lib/release_robot.rb,
lib/release_robot/main.rb,
lib/release_robot/printer.rb,
lib/release_robot/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
- .create_settings_file_if_nonexistent ⇒ Object
- .envars ⇒ Object
- .envars_help ⇒ Object
- .fetch_envars_from_config ⇒ Object
- .get_envar(key) ⇒ Object
- .get_missing_envars ⇒ Object
- .parse(args) ⇒ Object
- .root ⇒ Object
- .run(args) ⇒ Object
- .settings_file_path ⇒ Object
- .should_not_strip?(key) ⇒ Boolean
- .write_missing_envars(missing_envars = {}) ⇒ Object
Class Method Details
.create_settings_file_if_nonexistent ⇒ Object
108 109 110 |
# File 'lib/release_robot.rb', line 108 def create_settings_file_if_nonexistent File.new(settings_file_path, "w+") unless File.file?(settings_file_path) end |
.envars ⇒ Object
120 121 122 |
# File 'lib/release_robot.rb', line 120 def envars envars_help.keys end |
.envars_help ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/release_robot.rb', line 124 def envars_help { 'GITHUB_USERNAME' => "Your username for github.com\n\n", 'GITHUB_PASSWORD' => "Your password for github.com\n\n", } end |
.fetch_envars_from_config ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/release_robot.rb', line 85 def fetch_envars_from_config return unless envars = YAML.load_file(settings_file_path) envars.each_pair do |key, value| value.strip! unless should_not_strip?(key) ENV[key.upcase] = value end end |
.get_envar(key) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/release_robot.rb', line 66 def get_envar(key) if key =~ /GITHUB_PASSWORD/ env_value = ask("Enter your #{key}: ") { |q| q.echo = "*" } else print "Enter your #{key}: " env_value = gets.chomp end env_value.strip! unless should_not_strip?(key) if env_value.length == 0 puts 'Invalid input. This is a required field.' exit end env_value end |
.get_missing_envars ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/release_robot.rb', line 55 def get_missing_envars missing_envars = {} ReleaseRobot.envars.each do |key| next if ENV[key] missing_envars[key] = get_envar(key) end return missing_envars end |
.parse(args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/release_robot.rb', line 30 def parse(args) = OpenStruct.new opt_parser = OptionParser.new do |opts| opts.separator '' opts. = 'Usage: release_robot [options]' opts.separator '' opts.separator 'Common options:' opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end opts.on_tail('-v', '--version', 'Show version') do puts ReleaseRobot::VERSION exit end end opt_parser.parse!(args) end |
.root ⇒ Object
116 117 118 |
# File 'lib/release_robot.rb', line 116 def root File.dirname __dir__ end |
.run(args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/release_robot.rb', line 12 def run(args) = ReleaseRobot.parse(args) create_settings_file_if_nonexistent fetch_envars_from_config missing_envars = get_missing_envars write_missing_envars(missing_envars) if missing_envars.any? robot = ReleaseRobot::Main.new pull_requests = robot.start client = robot.client ReleaseRobot::Printer.new(pull_requests, client).print_all end |
.settings_file_path ⇒ Object
112 113 114 |
# File 'lib/release_robot.rb', line 112 def settings_file_path File.join(ENV['HOME'], '.release_robot_settings.yml') end |
.should_not_strip?(key) ⇒ Boolean
81 82 83 |
# File 'lib/release_robot.rb', line 81 def should_not_strip?(key) false end |
.write_missing_envars(missing_envars = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/release_robot.rb', line 93 def write_missing_envars(missing_envars={}) puts "\nTo avoid entering setup information each time, the following configuration has been stored in `#{settings_file_path}`:" missing_envars.each_pair do |key, value| if key =~ /password|token/i puts "\t#{key}=[FILTERED]" else puts "\t#{key}=#{value}" end data = YAML.load_file(settings_file_path) || {} ENV[key.upcase] = data[key.downcase] = value File.open(settings_file_path, 'w') { |f| YAML.dump(data, f) } end end |