hu 1.4.11 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33b55c8d9c5a0a4667d153b0b5567a090814bcd1
4
- data.tar.gz: 2bcc81e9bbc8c0364e4605061c195268e157d79d
3
+ metadata.gz: 6557353ee775641b7cc3fa63278f38b3155edebf
4
+ data.tar.gz: 4aeba96fe3689162d4f23899ddce1195595753ed
5
5
  SHA512:
6
- metadata.gz: 0ce41d13c9a6b9aaef68200391942ce7ce36c1bbf4dd498123ef12b55af86b9f69fbe8363bdc08ed31861ac8ab7b50bc10fd8e7ac6027d2f26300006ff80d0e7
7
- data.tar.gz: 53c40c071a9fa36df148ecf2d31cd77429744620f84c20f9374a7545afd26d2881c5d22f8ee75e38d99e9b95036c809ff3412bf3fada2c2c5a91585b4771243e
6
+ metadata.gz: 0f9c7d354e153072613326a4ea391fd89e4e4285797be9471f88e3451142c0fc0d7617c2c029c62cf01b4fc2f4525d554f28cba42014fdf32bf4799af9be5849
7
+ data.tar.gz: bb420ac4c9181c07dcaa17607237808c6395105237653917538d25ecc26aa6dede3149053d0ba1b152af8971e93f12a5c9721864286461c727596b01c87d3621
data/.rubocop.yml CHANGED
@@ -12,3 +12,7 @@ Metrics/ClassLength:
12
12
  Metrics/AbcSize:
13
13
  Max: 500
14
14
 
15
+ Metrics/PerceivedComplexity:
16
+ Max: 100
17
+
18
+
data/.rubocop_todo.yml CHANGED
@@ -13,10 +13,6 @@ Metrics/CyclomaticComplexity:
13
13
  Metrics/MethodLength:
14
14
  Max: 500
15
15
 
16
- # Offense count: 4
17
- Metrics/PerceivedComplexity:
18
- Max: 43
19
-
20
16
  # Offense count: 4
21
17
  Style/ClassVars:
22
18
  Exclude:
data/lib/hu/cli.rb CHANGED
@@ -9,6 +9,7 @@ require 'platform-api'
9
9
  require 'hu/common'
10
10
  require 'hu/collab'
11
11
  require 'hu/deploy'
12
+ require 'hu/scale'
12
13
 
13
14
  module Hu
14
15
  class Cli < Optix::Cli
data/lib/hu/collab.rb CHANGED
@@ -66,10 +66,10 @@ module Hu
66
66
  if s[:method].nil?
67
67
  color = "\e[0m"
68
68
  msg = '<-- Can not resolve this (NO-OP)'
69
- icon = "⚠️"
69
+ icon = '⚠️'
70
70
  elsif s[:invalid]
71
71
  color = "\e[0m"
72
- icon = "⚠️"
72
+ icon = '⚠️'
73
73
  end
74
74
  STDERR.printf "%1s %s%6s %-30s %-15s %-30s %s\e[0m\n", icon, color, s[:op_name], s[:app_name], s[:role], s[:value], msg
75
75
  if s[:invalid]
data/lib/hu/deploy.rb CHANGED
@@ -31,7 +31,7 @@ module Hu
31
31
  @@spinner = nil
32
32
  @@home_branch = nil
33
33
 
34
- #MINIMUM_GIT_VERSION = Versionomy.parse('2.9.0')
34
+ # MINIMUM_GIT_VERSION = Versionomy.parse('2.9.0')
35
35
 
36
36
  text 'Interactive deployment.'
37
37
  desc 'Interactive deployment'
@@ -150,7 +150,7 @@ module Hu
150
150
  unless develop_can_be_merged_into_master?
151
151
  puts
152
152
  puts "ERROR: It looks like a merge of 'develop' into 'master' would fail.".color(:red)
153
- puts " Aborting early to prevent a merge conflict.".color(:red)
153
+ puts ' Aborting early to prevent a merge conflict.'.color(:red)
154
154
  puts
155
155
  exit 1
156
156
  end
@@ -445,12 +445,12 @@ module Hu
445
445
  end
446
446
 
447
447
  git_version_warning = ''
448
- #if current_git_version < MINIMUM_GIT_VERSION
448
+ # if current_git_version < MINIMUM_GIT_VERSION
449
449
  # git_version_warning = " (your git is outdated. please upgrade to v#{MINIMUM_GIT_VERSION}!)".color(:black).bright
450
- #end
450
+ # end
451
451
 
452
452
  puts "\e[H\e[2J" if clear
453
- puts " PIPELINE #{pipeline_name} ".inverse+git_version_warning
453
+ puts " PIPELINE #{pipeline_name} ".inverse + git_version_warning
454
454
  puts
455
455
 
456
456
  puts table.render(:unicode, padding: [0, 1, 0, 1], multiline: true)
@@ -856,7 +856,7 @@ module Hu
856
856
  end
857
857
 
858
858
  def return_to_home_branch
859
- return if @@home_branch.nil? or @@home_branch == current_branch_name
859
+ return if @@home_branch.nil? || @@home_branch == current_branch_name
860
860
  run_each <<-EOS.strip_heredoc
861
861
  :quiet
862
862
  :nospinner
@@ -879,12 +879,12 @@ module Hu
879
879
  end
880
880
 
881
881
  def current_branch_name
882
- @git.head.name.sub(/^refs\/heads\//, '')
882
+ @git.head.name.sub(%r{^refs\/heads\/}, '')
883
883
  end
884
884
 
885
- #def current_git_version
885
+ # def current_git_version
886
886
  # Versionomy.parse(`git --version`.chomp.split(' ')[-1])
887
- #end
887
+ # end
888
888
 
889
889
  def create_changelog(env)
890
890
  if File.executable? '.hu/hooks/changelog'
data/lib/hu/scale.rb ADDED
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'netrc'
4
+ require 'platform-api'
5
+ require 'rainbow'
6
+
7
+ module Hu
8
+ class Cli < Optix::Cli
9
+ # Heroku Scale
10
+ class Scale < Optix::Cli
11
+ DYNO_TYPES = [
12
+ {
13
+ id: 'free',
14
+ sleeps: true,
15
+ pro: false,
16
+ ram: 512,
17
+ cpu: 1,
18
+ dedicated: false,
19
+ usd: 0
20
+ },
21
+ {
22
+ id: 'hobby',
23
+ sleeps: false,
24
+ pro: false,
25
+ ram: 512,
26
+ cpu: 1,
27
+ dedicated: false,
28
+ usd: 7
29
+ },
30
+ {
31
+ id: 'standard-1x',
32
+ sleeps: false,
33
+ pro: true,
34
+ ram: 512,
35
+ cpu: 1,
36
+ dedicated: false,
37
+ usd: 25
38
+ },
39
+ {
40
+ id: 'standard-2x',
41
+ sleeps: false,
42
+ pro: true,
43
+ ram: 1024,
44
+ cpu: 4,
45
+ dedicated: false,
46
+ usd: 50
47
+ },
48
+ {
49
+ id: 'performance-m',
50
+ sleeps: false,
51
+ pro: true,
52
+ ram: 2560,
53
+ cpu: 11,
54
+ dedicated: true,
55
+ usd: 250
56
+ },
57
+ {
58
+ id: 'performance-l',
59
+ sleeps: false,
60
+ pro: true,
61
+ ram: 14_336,
62
+ cpu: 46,
63
+ dedicated: true,
64
+ usd: 500
65
+ }
66
+ ].freeze
67
+
68
+ DYNO_TYPES.each_with_index do |dt, i|
69
+ dt[:index] = i
70
+ end
71
+
72
+ text 'Print dyno formation.'
73
+ desc 'Print dyno formation'
74
+ if Hu::API_TOKEN.nil?
75
+ text ''
76
+ text "\e[1mWARNING: Environment variable 'HEROKU_API_KEY' must be set.\e[0m"
77
+ end
78
+ filter do |_cmd, _opts, _argv|
79
+ if Hu::API_TOKEN.nil?
80
+ STDERR.puts "\e[0;31;1mERROR: Environment variable 'HEROKU_API_KEY' must be set.\e[0m"
81
+ exit 1
82
+ end
83
+ end
84
+
85
+ def scale(_cmd, _opts, _args)
86
+ print_types
87
+ puts
88
+ print_state heroku_state
89
+ end
90
+
91
+ def print_types
92
+ cols = %w(id ram cpu dedicated sleeps usd)
93
+ tpl = "%-16s %5s %4s %11s %7s %5s\n"
94
+ puts
95
+ puts ' Available Dyno Types '.inverse
96
+ puts
97
+ printf tpl.bright, *cols
98
+ DYNO_TYPES.each do |dyno_type|
99
+ printf tpl, *cols.map { |col| dyno_type[col.to_sym] }
100
+ end
101
+ end
102
+
103
+ def print_state(state)
104
+ cols = ['$/mo', 'fH12ML', 'formation']
105
+ rows = []
106
+
107
+ total_cost = 0
108
+ max_app_name_len = state.keys.reduce(0) { |a, e| [a, e.length].max }
109
+ state.sort.each do |app_name, dyno_types|
110
+ next if ignored_app?(app_name)
111
+ row = { 'app' => app_name, 'fH12ML' => '......', 'formation' => "heroku ps:scale -a #{app_name.ljust(max_app_name_len).color(:green).bright}" }
112
+ cost = 0
113
+ dyno_types.each do |dyno_type, dynos|
114
+ dynos.each do |dyno|
115
+ row = Marshal.load(Marshal.dump(row))
116
+ dyno_type_str = dyno[:type]
117
+ quant_colon_type = "#{dyno[:quantity]}:#{dyno_type}"
118
+ if dyno[:quantity] == 0
119
+ dyno_type_str = dyno_type_str.color(:black).bright
120
+ quant_colon_type = quant_colon_type.color(:black).bright
121
+ else
122
+ dyno_type_str = dyno_type_str.color(:yellow)
123
+ quant_colon_type = quant_colon_type.color(:yellow)
124
+ row['fH12ML'][DYNO_TYPES.find { |e| e[:id] == dyno_type }[:index]] = '*'
125
+ end
126
+ row['formation'] += " #{dyno_type_str}" + '='.color(:black).bright + quant_colon_type.to_s
127
+ cost += DYNO_TYPES.find { |e| e[:id] == dyno_type }[:usd] * dyno[:quantity]
128
+ end
129
+ end
130
+ total_cost += cost
131
+ row['$/mo'] = format '%4d', cost
132
+ rows << row
133
+ end
134
+
135
+ puts
136
+ puts ' Current Dyno Formation '.inverse
137
+ puts
138
+
139
+ tpl = "%-5s %6s %s\n"
140
+ printf tpl.bright, *cols
141
+ rows.each do |row|
142
+ printf tpl, *cols.map { |col| row[col] }
143
+ end
144
+ puts
145
+ puts "Total: $#{total_cost} USD/mo"
146
+ puts
147
+ end
148
+
149
+ def ignored_app?(app_name)
150
+ ENV.fetch('HU_IGNORE_APPS', '').split(' ').each do |p|
151
+ return true if File.fnmatch(p, app_name)
152
+ end
153
+ false
154
+ end
155
+
156
+ def heroku_state(force_refresh = false)
157
+ return @heroku_state unless force_refresh || @heroku_state.nil?
158
+ data = {}
159
+ app_names = h.app.list.map { |e| e['name'] }.reject { |e| ignored_app?(e) }
160
+ threads = []
161
+ app_names.each_with_index do |app_name, _i|
162
+ threads << Thread.new do
163
+ h.formation.list(app_name).each do |dyno|
164
+ dyno_size = dyno['size'].downcase
165
+ data[app_name] ||= {}
166
+ data[app_name][dyno_size] ||= []
167
+ data[app_name][dyno_size] << { type: dyno['type'], quantity: dyno['quantity'] }
168
+ end
169
+ end
170
+ end
171
+ threads.each_with_index do |t, _i|
172
+ t.join
173
+ end
174
+ @heroku_state = data
175
+ end
176
+
177
+ def h
178
+ @h ||= PlatformAPI.connect_oauth(Hu::API_TOKEN)
179
+ end
180
+ end
181
+ end
182
+ end
data/lib/hu/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hu
3
- VERSION = '1.4.11'
3
+ VERSION = '1.5.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.11
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - moe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -339,6 +339,7 @@ files:
339
339
  - lib/hu/collab.rb
340
340
  - lib/hu/common.rb
341
341
  - lib/hu/deploy.rb
342
+ - lib/hu/scale.rb
342
343
  - lib/hu/telemetry.rb
343
344
  - lib/hu/version.rb
344
345
  homepage: https://github.com/busyloop/hu