Module: GreenHat::GitLab
- Defined in:
- lib/greenhat/accessors/gitlab.rb
Overview
GitLab App Helpers
Class Method Summary collapse
- .identify_node(archive) ⇒ Object
- .node_types ⇒ Object
-
.services(archive, indent = 0) ⇒ Object
Show GitLab Services in a grid / include versions rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity.
-
.services_markdown(archive) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity.
Class Method Details
.identify_node(archive) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/greenhat/accessors/gitlab.rb', line 27 def self.identify_node(archive) gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }&.data&.keys hostname = archive.things.find { |x| x.type == 'hostname' }.data.first.chomp { host: hostname, services: gitlab_status || [] } end |
.node_types ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/greenhat/accessors/gitlab.rb', line 4 def self.node_types [ { name: 'Web Service', pattern: %w[puma unicorn] }, { name: 'Sidekiq', pattern: %w[sidekiq] }, { name: 'Gitaly', pattern: %w[gitaly] }, { name: 'Redis', pattern: %w[redis] }, { name: 'PostgreSQL', pattern: %w[postgresql] }, { name: 'PGBouncer', pattern: %w[pgbouncer] } ] end |
.services(archive, indent = 0) ⇒ Object
Show GitLab Services in a grid / include versions rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/greenhat/accessors/gitlab.rb', line 39 def self.services(archive, indent = 0) manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' } gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' } # Dont' show invalid return nil if gitlab_status.data.to_s.include? "Could not find 'bundler'" return nil unless gitlab_status list = gitlab_status.data.keys.sort.map do |service| color = gitlab_status.data.dig(service, 0, :status) == 'run' ? :green : :red status = gitlab_status.data.dig(service, 0, :status) == 'run' ? '↑' : '↓' # Collect Service version from manifest version = manifest.data.software[service.to_sym]&.display_version # If able to identify version use / fallback if version [ "#{service}#{status}".pastel(color), "(#{version})".pastel(:bright_black) ].join(' ') else service.pastel(color) end end # Keep Alphabetical Sort groups = list.each_slice((list.size / 3.to_f).round).to_a table = TTY::Table.new do |t| loop do break if groups.all?(&:empty?) t << groups.map(&:shift) end end table.render(:unicode, padding: [0, 1, 0, 1], indent: indent) end |
.services_markdown(archive) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/greenhat/accessors/gitlab.rb', line 80 def self.services_markdown(archive) # manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' } gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' } list = gitlab_status.data.keys.sort.map do |service| status = gitlab_status.data.dig(service, 0, :status) == 'run' ? '↑' : '↓' "#{service}#{status}" end # Keep Alphabetical Sort groups = list.each_slice((list.size / 3.to_f).round).to_a table = TTY::Table.new do |t| loop do break if groups.all?(&:empty?) t << groups.map(&:shift) end end "```\n#{table.render(:basic)}\n```" end |