geordi 5.4.0 → 6.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -180,7 +180,7 @@ HEREDOC
180
180
  if @mysql_command.include? '-p'
181
181
  puts "Please enter your MySQL/MariaDB account 'root' for: DROP DATABASE #{db}"
182
182
  else
183
- Interaction.note "Dropping MySQL/MariaDB database #{db}"
183
+ puts "Dropping MySQL/MariaDB database #{db}"
184
184
  end
185
185
  `#{@mysql_command} -e 'DROP DATABASE \`#{db}\`;'`
186
186
  end
@@ -206,7 +206,7 @@ HEREDOC
206
206
  until %w[y n].include? proceed
207
207
  deletable_dbs = filter_whitelisted(dbtype, database_list)
208
208
  if deletable_dbs.empty?
209
- Interaction.note "No #{dbtype} databases found that were not whitelisted"
209
+ Interaction.note "No #{dbtype} databases found that were not whitelisted."
210
210
  if Interaction.prompt('Edit the whitelist? [y]es or [n]o') == 'y'
211
211
  proceed = 'e'
212
212
  else
@@ -214,11 +214,11 @@ HEREDOC
214
214
  end
215
215
  end
216
216
  if proceed.empty?
217
- Interaction.note "The following #{dbtype} databases are not whitelisted and could be deleted:"
217
+ Interaction.note "The following #{dbtype} databases are not whitelisted and can be deleted:"
218
218
  deletable_dbs.sort.each do |db|
219
219
  puts db
220
220
  end
221
- Interaction.note "Those #{dbtype} databases are not whitelisted and could be deleted."
221
+ Interaction.note "These #{dbtype} databases are not whitelisted and can be deleted."
222
222
  proceed = Interaction.prompt('Proceed? [y]es, [n]o or [e]dit whitelist')
223
223
  end
224
224
  case proceed
@@ -226,7 +226,7 @@ HEREDOC
226
226
  proceed = '' # reset user selection
227
227
  edit_whitelist dbtype
228
228
  when 'n'
229
- Interaction.success 'Not deleting anything'
229
+ Interaction.success 'Nothing deleted.'
230
230
  return []
231
231
  when 'y'
232
232
  return deletable_dbs
data/lib/geordi/docker.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'geordi/interaction'
2
2
  require 'geordi/cucumber'
3
3
  require 'yaml'
4
+ require 'open3'
4
5
 
5
6
  module Geordi
6
7
  class Docker
@@ -28,13 +29,61 @@ module Geordi
28
29
  end
29
30
 
30
31
  def vnc
31
- Cucumber.new.launch_vnc_viewer('::5967')
32
+ check_installation_and_config
33
+ launch_vnc_viewer('::5967')
34
+ end
35
+
36
+ def setup_vnc
37
+ `clear`
38
+ Interaction.note 'This script will help you install a VNC viewer.'
39
+ Interaction.note 'Please open a second shell to execute instructions.'
40
+ Interaction.prompt 'Continue ...'
41
+
42
+ Interaction.announce 'Setup VNC viewer'
43
+ vnc_viewer_installed = system('which vncviewer > /dev/null 2>&1')
44
+ if vnc_viewer_installed
45
+ Interaction.success 'It appears you already have a VNC viewer installed. Good job!'
46
+ else
47
+ puts 'Please run:'
48
+ Interaction.note_cmd 'sudo apt-get install xtightvncviewer'
49
+ Interaction.prompt 'Continue ...'
50
+ end
51
+
52
+ puts
53
+ puts Util.strip_heredoc <<-TEXT
54
+ Done. You can view the VNC window with `geordi docker vnc`.
55
+ TEXT
56
+
57
+ Interaction.success 'Happy cuking!'
32
58
  end
33
59
 
34
60
  private
35
61
 
62
+ def launch_vnc_viewer(source)
63
+ fail('VNC viewer not found. Install it with `geordi docker vnc --setup`.') unless command_exists?('vncviewer')
64
+
65
+ fork do
66
+ error = capture_stderr do
67
+ system("vncviewer #{source}")
68
+ end
69
+ unless $?.success?
70
+ if $?.exitstatus == 127
71
+ fail('VNC viewer not found. Install it with `geordi docker vnc --setup`.')
72
+ else
73
+ fail("VNC viewer could not be opened: #{error}")
74
+ end
75
+ end
76
+ end
77
+ exit 0
78
+ end
79
+
36
80
  def attach_to_running_shell
37
- running_containers = execute(:`, 'docker-compose ps').split("\n")
81
+ # The command line output of docker-compose ps changes depending on the container name length, this is
82
+ # caused by the varying terminal length and results in the longer outputs, e.g the container name and id
83
+ # to be cut after x characters and the rest being placed in the line below.
84
+
85
+ stdout_str, _error_str = execute(:capture, {'COLUMNS' => '400'}, 'docker-compose ps')
86
+ running_containers = stdout_str.split("\n")
38
87
  if (main_container_line = running_containers.grep(/_main_run/).first)
39
88
  container_name = main_container_line.split(' ').first
40
89
  execute(:exec, 'docker', 'exec', '-it', container_name, 'bash')
@@ -54,13 +103,17 @@ module Geordi
54
103
  def execute(kind, *args)
55
104
  if ENV['GEORDI_TESTING']
56
105
  puts "Stubbed run #{args.join(' ')}"
57
- if kind == :`
106
+ if kind == :` || kind == :capture
58
107
  mock_parse(*args)
59
108
  else
60
109
  mock_run(*args)
61
110
  end
62
111
  else
63
- send(kind, *args)
112
+ if kind == :capture
113
+ Open3.capture2(*args)
114
+ else
115
+ send(kind, *args)
116
+ end
64
117
  end
65
118
  end
66
119
 
@@ -112,5 +165,19 @@ module Geordi
112
165
  []
113
166
  end
114
167
  end
168
+
169
+ def capture_stderr
170
+ old_stderr = $stderr.dup
171
+ io = Tempfile.new('cuc')
172
+ $stderr.reopen(io)
173
+ yield
174
+ io.rewind
175
+ io.read
176
+ ensure
177
+ io.close
178
+ io.unlink
179
+ $stderr.reopen(old_stderr)
180
+ end
181
+
115
182
  end
116
183
  end
data/lib/geordi/gitpt.rb CHANGED
@@ -64,26 +64,41 @@ No staged changes. Will create an empty commit.
64
64
 
65
65
  def load_projects
66
66
  project_ids = settings.pivotal_tracker_project_ids
67
- project_ids.collect { |project_id| client.project(project_id) }
67
+ project_ids.collect do |project_id|
68
+ begin
69
+ client.project(project_id)
70
+ rescue TrackerApi::Errors::ClientError
71
+ puts # Start a new line
72
+ Geordi::Interaction.warn "Could not access project #{project_id}. Skipping."
73
+ end
74
+ end.compact
68
75
  end
69
76
 
70
77
  def applicable_stories
78
+ if Util.testing?
79
+ return ENV['GEORDI_TESTING_NO_PT_STORIES'] == 'true' ? [] : [OpenStruct.new(id: 12, name: 'Test Story')]
80
+ end
81
+
71
82
  projects = load_projects
72
83
  projects.collect do |project|
73
- project.stories(filter: 'state:started,finished,rejected')
84
+ project.stories(filter: 'state:started,finished,rejected', fields: ':default,owners(id,name)')
74
85
  end.flatten
75
86
  end
76
87
 
77
88
  def choose_story
78
- if Util.testing?
79
- return OpenStruct.new(id: 12, name: 'Test Story')
80
- end
81
-
82
89
  loading_message = 'Connecting to Pivotal Tracker ...'
83
90
  print(loading_message)
84
91
  stories = applicable_stories
85
92
  reset_loading_message = "\r#{' ' * (loading_message.length + stories.length)}\r"
86
93
 
94
+ Geordi::Interaction.fail('No stories to offer.') if stories.empty?
95
+
96
+ if Util.testing?
97
+ return stories[0]
98
+ end
99
+
100
+ my_id = client.me.id
101
+
87
102
  highline.choose do |menu|
88
103
  menu.header = 'Choose a story'
89
104
 
@@ -92,7 +107,7 @@ No staged changes. Will create an empty commit.
92
107
 
93
108
  state = story.current_state
94
109
  owners = story.owners
95
- owner_is_me = owners.collect(&:id).include?(client.me.id)
110
+ owner_is_me = owners.collect(&:id).include?(my_id)
96
111
 
97
112
  if state == 'started'
98
113
  state = HighLine::GREEN + state + HighLine::RESET
@@ -11,8 +11,9 @@ module Geordi
11
11
  puts "\e[4;34m#{message}\e[0m" # blue underline
12
12
  end
13
13
 
14
- # Any hints, comments, infos or explanations should be `note`d. Please do
15
- # not print any output (data, file contents, lists) with `note`.
14
+ # Any meta information, i.e. hints, comments, infos or explanations should
15
+ # be printed with `note`.
16
+ # Please do not use it for command output (data, file contents, lists etc).
16
17
  def note(text)
17
18
  puts '> ' + text
18
19
  end
@@ -38,7 +39,8 @@ module Geordi
38
39
  exit(1)
39
40
  end
40
41
 
41
- # When you're done, inform the user with a `success` and a short message
42
+ # When you're done, inform the user with a `success` and a short message. It
43
+ # should be a sentence (i.e. ending with [.!?]).
42
44
  def success(text)
43
45
  message = "\n> #{text}"
44
46
  puts "\e[32m#{message}\e[0m" # green
@@ -9,7 +9,9 @@ module Geordi
9
9
  LOCAL_SETTINGS_FILE_NAME = Util.testing? ? './tmp/local_settings.yml'.freeze : './.geordi.yml'.freeze
10
10
 
11
11
  ALLOWED_GLOBAL_SETTINGS = %w[ pivotal_tracker_api_key auto_update_chromedriver pivotal_tracker_project_ids ].freeze
12
- ALLOWED_LOCAL_SETTINGS = %w[ use_vnc pivotal_tracker_project_ids ].freeze
12
+ ALLOWED_LOCAL_SETTINGS = %w[ pivotal_tracker_project_ids ].freeze
13
+
14
+ SETTINGS_WARNED = 'GEORDI_INVALID_SETTINGS_WARNED'
13
15
 
14
16
  def initialize
15
17
  read_settings
@@ -34,13 +36,6 @@ module Geordi
34
36
  save_global_settings
35
37
  end
36
38
 
37
- # Local settings
38
- # They should not be changed by geordi to avoid unexpected diffs, therefore
39
- # there are no setters for these settings
40
- def use_vnc?
41
- @local_settings.fetch('use_vnc', true)
42
- end
43
-
44
39
  def pivotal_tracker_project_ids
45
40
  local_project_ids = @local_settings['pivotal_tracker_project_ids'] || pt_project_ids_old
46
41
  global_project_ids = @global_settings['pivotal_tracker_project_ids']
@@ -73,14 +68,20 @@ module Geordi
73
68
  global_path = GLOBAL_SETTINGS_FILE_NAME
74
69
  local_path = LOCAL_SETTINGS_FILE_NAME
75
70
 
76
- if File.exists?(global_path)
77
- global_settings = YAML.safe_load(File.read(global_path))
78
- check_for_invalid_keys(global_settings, ALLOWED_GLOBAL_SETTINGS, global_path)
71
+ global_settings = if File.exists?(global_path)
72
+ YAML.safe_load(File.read(global_path))
73
+ end
74
+ local_settings = if File.exists?(local_path)
75
+ YAML.safe_load(File.read(local_path))
79
76
  end
80
77
 
81
- if File.exists?(local_path)
82
- local_settings = YAML.safe_load(File.read(local_path))
78
+ # Prevent duplicate warnings caused by another instance of Settings
79
+ unless ENV[SETTINGS_WARNED]
80
+ check_for_invalid_keys(global_settings, ALLOWED_GLOBAL_SETTINGS, global_path)
83
81
  check_for_invalid_keys(local_settings, ALLOWED_LOCAL_SETTINGS, local_path)
82
+ Interaction.warn "Unsupported config file \".firefox-version\". Please remove it." if File.exists?('.firefox-version')
83
+
84
+ ENV[SETTINGS_WARNED] = 'true'
84
85
  end
85
86
 
86
87
  @global_settings = global_settings || {}
@@ -88,21 +89,12 @@ module Geordi
88
89
  end
89
90
 
90
91
  def check_for_invalid_keys(settings, allowed_keys, file)
92
+ return if settings.nil?
93
+
91
94
  invalid_keys = settings.keys - allowed_keys
92
95
  unless invalid_keys.empty?
93
- Geordi::Interaction.warn "Geordi detected unknown keys in #{file}.\n"
94
-
95
- invalid_keys.sort.each do |key|
96
- puts "* #{key}"
97
- end
98
-
99
- puts "\nAllowed keys are:"
100
- allowed_keys.sort.each do |key|
101
- puts "* #{key}"
102
- end
103
- puts
104
-
105
- exit 1
96
+ Interaction.warn "Unknown settings in #{file}: #{invalid_keys.join(", ")}"
97
+ Interaction.note "Supported settings in #{file} are: #{allowed_keys.join(", ")}"
106
98
  end
107
99
  end
108
100
 
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '5.4.0'.freeze
2
+ VERSION = '6.0.0-rc1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geordi
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 6.0.0.pre.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -32,12 +32,12 @@ executables:
32
32
  - b
33
33
  - dumple
34
34
  - geordi
35
- - launchy_browser
36
35
  extensions: []
37
36
  extra_rdoc_files: []
38
37
  files:
39
38
  - ".github/workflows/test.yml"
40
39
  - ".gitignore"
40
+ - ".rspec"
41
41
  - ".ruby-version"
42
42
  - CHANGELOG.md
43
43
  - Gemfile
@@ -48,14 +48,12 @@ files:
48
48
  - exe/b
49
49
  - exe/dumple
50
50
  - exe/geordi
51
- - exe/launchy_browser
52
51
  - geordi.gemspec
53
52
  - lib/geordi.rb
54
53
  - lib/geordi/COMMAND_TEMPLATE
55
54
  - lib/geordi/capistrano_config.rb
56
55
  - lib/geordi/chromedriver_updater.rb
57
56
  - lib/geordi/cli.rb
58
- - lib/geordi/commands/_setup_vnc.rb
59
57
  - lib/geordi/commands/apache_site.rb
60
58
  - lib/geordi/commands/branch.rb
61
59
  - lib/geordi/commands/bundle_install.rb
@@ -72,7 +70,6 @@ files:
72
70
  - lib/geordi/commands/docker.rb
73
71
  - lib/geordi/commands/drop_databases.rb
74
72
  - lib/geordi/commands/dump.rb
75
- - lib/geordi/commands/firefox.rb
76
73
  - lib/geordi/commands/migrate.rb
77
74
  - lib/geordi/commands/png_optimize.rb
78
75
  - lib/geordi/commands/rake.rb
@@ -86,14 +83,12 @@ files:
86
83
  - lib/geordi/commands/unit.rb
87
84
  - lib/geordi/commands/update.rb
88
85
  - lib/geordi/commands/version.rb
89
- - lib/geordi/commands/vnc.rb
90
86
  - lib/geordi/commands/with_rake.rb
91
87
  - lib/geordi/commands/yarn_install.rb
92
88
  - lib/geordi/cucumber.rb
93
89
  - lib/geordi/db_cleaner.rb
94
90
  - lib/geordi/docker.rb
95
91
  - lib/geordi/dump_loader.rb
96
- - lib/geordi/firefox_for_selenium.rb
97
92
  - lib/geordi/gitpt.rb
98
93
  - lib/geordi/interaction.rb
99
94
  - lib/geordi/remote.rb
@@ -104,7 +99,8 @@ homepage: https://makandra.com
104
99
  licenses:
105
100
  - MIT
106
101
  metadata: {}
107
- post_install_message:
102
+ post_install_message: " Support for sequential running of integration tests tagged
103
+ with @solo has been dropped.\n"
108
104
  rdoc_options: []
109
105
  require_paths:
110
106
  - lib
@@ -115,11 +111,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
111
  version: 2.2.0
116
112
  required_rubygems_version: !ruby/object:Gem::Requirement
117
113
  requirements:
118
- - - ">="
114
+ - - ">"
119
115
  - !ruby/object:Gem::Version
120
- version: '0'
116
+ version: 1.3.1
121
117
  requirements: []
122
- rubygems_version: 3.1.4
118
+ rubygems_version: 3.0.3
123
119
  signing_key:
124
120
  specification_version: 4
125
121
  summary: Collection of command line tools we use in our daily work with Ruby, Rails
data/exe/launchy_browser DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This script is a part of Geordi. It is used by the cucumber command to have
4
- # launchy open error pages from tests in the users browser, as apposed to
5
- # opening it within VNC.
6
-
7
- # For unknown reasons, #require cannot find 'geordi/cucumber', so we need to
8
- # require it this way. Hours have been spent trying to require 'geordi/cucumber'.
9
- require File.expand_path('../../lib/geordi/cucumber', __FILE__)
10
- Geordi::Cucumber.new.restore_env
11
-
12
- require 'rubygems'
13
- require 'launchy'
14
-
15
- Launchy.open(ARGV.first)
@@ -1,64 +0,0 @@
1
- desc '-setup-vnc', 'Setup VNC for running Selenium tests there', hide: true
2
- def _setup_vnc
3
- `clear`
4
-
5
- Interaction.note 'This script will help you install a VNC server and a VNC viewer.'
6
- puts
7
- puts Util.strip_heredoc <<-TEXT
8
- With those you will be able to use our cucumber script without being
9
- disturbed by focus-stealing Selenium windows. Instead, they will open
10
- inside a VNC session.
11
-
12
- You can still inspect everything with:
13
- TEXT
14
- Interaction.note_cmd 'geordi vnc'
15
- puts
16
- Interaction.note 'Please open a second shell to execute instructions.'
17
- Interaction.prompt 'Continue ...'
18
-
19
- Interaction.announce 'Setup VNC server'
20
-
21
- vnc_server_installed = system('which vncserver > /dev/null 2>&1')
22
- if vnc_server_installed
23
- Interaction.success 'It appears you already have a VNC server installed. Good job!'
24
- else
25
- puts 'Please run:'
26
- Interaction.note_cmd 'sudo apt-get install tightvncserver'
27
- puts 'In case this package is not available, you may try vnc4server instead.'
28
- Interaction.prompt 'Continue ...'
29
-
30
- puts
31
-
32
- Interaction.note 'We will now set a password for your VNC server.'
33
- puts Util.strip_heredoc <<-TEXT
34
- When running our cucumber script, this password will be used while also
35
- restricting access to the local machine. However, if you start a vncserver
36
- without our cucumber script, keep in mind that a user with this password
37
- can connect to your machine.
38
-
39
- TEXT
40
- puts 'Please run:'
41
- Interaction.note_cmd 'vncpasswd'
42
- Interaction.warn 'Enter a secure password!'
43
- Interaction.prompt 'Continue ...'
44
- end
45
-
46
- Interaction.announce 'Setup VNC viewer'
47
-
48
- vnc_viewer_installed = system('which vncviewer > /dev/null 2>&1')
49
- if vnc_viewer_installed
50
- Interaction.success 'It appears you already have a VNC viewer installed. Good job!'
51
- else
52
- puts 'Please run:'
53
- Interaction.note_cmd 'sudo apt-get install xtightvncviewer'
54
- Interaction.prompt 'Continue ...'
55
- end
56
-
57
- puts
58
- puts Util.strip_heredoc <<-TEXT
59
- All done. Our cucumber script will now automatically run Selenium features
60
- in VNC.
61
- TEXT
62
-
63
- Interaction.success 'Happy cuking!'
64
- end