zold 0.14.38 → 0.14.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3fc39017077100e9934e90a71f121139e4a1432
4
- data.tar.gz: da8496c1bdfa6398785e5a7ab464eff0a45e02a9
3
+ metadata.gz: 13cff3999d82e0c3230da3fe717537fdef3337e4
4
+ data.tar.gz: 307f20cb6d1cf11c963f94cae910540dac9f473a
5
5
  SHA512:
6
- metadata.gz: b2a9f4c3b526399c34bf84c05a66c90db67e39649ea6347abd74bf2428b848128991a73810ff06d9a421e2967140de674fa177b52bfa3f82d5e8bdf69fa4f25e
7
- data.tar.gz: 85720186b77dec3343a10968310d0001a94940722490e2041b55c593ee7b230f8ebb6a5f9112622e10b78e717abd9778cc24f1b0b142d7d79dec485717638c48
6
+ metadata.gz: bdcbe7adf732ea4aea112322a56420a1197aad5640dcd5f330ce3b0315be4021832aac1d5ed4e2d07642f141748b6e08ac7e52b1ad5085da2f5b12fabd7b0e56
7
+ data.tar.gz: 379b7ec0f166019354cd3ea276edbd455baff582ea8ca3f024eb0b307d3a6e5485021a7cc3beea3eb6a59d13a0aa62bb6a4fd22e084bb654758f8bb1759b05fc
@@ -157,6 +157,7 @@ module Zold
157
157
  Front.set(:logging, @log.debug?)
158
158
  Front.set(:halt, opts['halt-code'])
159
159
  Front.set(:home, Dir.pwd)
160
+ @log.info("Time: #{Time.now.utc.iso8601}")
160
161
  @log.info("Home directory: #{Dir.pwd}")
161
162
  @log.info("Ruby version: #{RUBY_VERSION}")
162
163
  @log.info("Zold gem version: #{Zold::VERSION}")
@@ -34,6 +34,7 @@ require_relative '../http'
34
34
  require_relative '../remotes'
35
35
  require_relative '../score'
36
36
  require_relative '../wallet'
37
+ require_relative '../gem'
37
38
 
38
39
  # REMOTE command.
39
40
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -223,7 +224,9 @@ Available options:"
223
224
  r.assert_score_ownership(score)
224
225
  r.assert_score_strength(score) unless opts['ignore-score-weakness']
225
226
  @remotes.rescore(score.host, score.port, score.value)
226
- if Semantic::Version.new(VERSION) < Semantic::Version.new(json['version'])
227
+ gem = Zold::Gem.new
228
+ if Semantic::Version.new(VERSION) < Semantic::Version.new(json['version']) ||
229
+ Semantic::Version.new(VERSION) < Semantic::Version.new(gem.last_version)
227
230
  if opts['reboot']
228
231
  @log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot! \
229
232
  (use --never-reboot to avoid this from happening)")
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'uri'
24
+ require 'net/http'
25
+ require_relative 'json_page'
26
+
27
+ # Class representing the Zold gem on Rubygems
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
30
+ # License:: MIT
31
+ module Zold
32
+ # Gem
33
+ class Gem
34
+ BASE_URI = 'rubygems.org'
35
+ API_VERSION = '/api/v1/'
36
+
37
+ def last_version
38
+ uri = URI(API_VERSION + 'versions/zold/latest.json')
39
+ http = Net::HTTP.new(BASE_URI)
40
+ path = uri.path
41
+ path += '?' + uri.query if uri.query
42
+ res = http.request_get(path)
43
+ JsonPage.new(res.body).to_hash['version']
44
+ end
45
+ end
46
+ end
@@ -69,7 +69,8 @@ module Zold
69
69
  end.join(', '),
70
70
  cleanup: @cleanup.status,
71
71
  pipeline: @pipeline.size,
72
- best: best.map(&:to_mnemo).join(', ')
72
+ best: best.map(&:to_mnemo).join(', '),
73
+ alive: @alive
73
74
  }
74
75
  end
75
76
 
@@ -103,7 +104,7 @@ module Zold
103
104
  @log.info("It's time to stop the cleanup thread (#{a.count} != #{max}, alive=#{@alive})...")
104
105
  break
105
106
  end
106
- VerboseThread.new(@log).run do
107
+ VerboseThread.new(@log).run(true) do
107
108
  cleanup(host, port, strength, threads)
108
109
  end
109
110
  end
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.14.38'
28
+ VERSION = '0.14.39'
29
29
  PROTOCOL = 2
30
30
  end
@@ -61,6 +61,10 @@ class TestRemote < Minitest::Test
61
61
  stub_request(:get, 'http://localhost:999/remotes').to_return(
62
62
  status: 404
63
63
  )
64
+ stub_request(:get, 'http://rubygems.org/api/v1/versions/zold/latest.json').to_return(
65
+ status: 200,
66
+ body: '{"version": "0.0.0"}'
67
+ )
64
68
  cmd = Zold::Remote.new(remotes: remotes, log: test_log)
65
69
  cmd.run(%w[remote clean])
66
70
  assert(remotes.all.empty?)
@@ -72,6 +76,40 @@ class TestRemote < Minitest::Test
72
76
  end
73
77
  end
74
78
 
79
+ def test_new_version_rubygems
80
+ Dir.mktmpdir do |dir|
81
+ remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
82
+ zero = Zold::Score::ZERO
83
+ stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
84
+ status: 200,
85
+ body: {
86
+ version: Zold::VERSION,
87
+ score: zero.to_h,
88
+ all: [
89
+ { host: zero.host, port: zero.port }
90
+ ]
91
+ }.to_json
92
+ )
93
+ stub_request(:get, 'http://rubygems.org/api/v1/versions/zold/latest.json').to_return(
94
+ status: 200,
95
+ body: '{"version": "9.9.9"}'
96
+ )
97
+ log = Minitest::Test::TestLogger.new
98
+ cmd = Zold::Remote.new(remotes: remotes, log: log)
99
+ cmd.run(%w[remote clean])
100
+ cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
101
+ cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping', '--reboot'])
102
+ assert(log.msg.to_s.include?(', reboot!'))
103
+ log.msg = []
104
+ stub_request(:get, 'http://rubygems.org/api/v1/versions/zold/latest.json').to_return(
105
+ status: 200,
106
+ body: "{\"version\": \"#{Zold::VERSION}\"}"
107
+ )
108
+ cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping', '--reboot'])
109
+ assert(!log.msg.to_s.include?(', reboot!'))
110
+ end
111
+ end
112
+
75
113
  def test_elects_a_remote
76
114
  Dir.mktmpdir do |dir|
77
115
  zero = Zold::Score::ZERO
@@ -111,6 +149,10 @@ class TestRemote < Minitest::Test
111
149
  ]
112
150
  }.to_json
113
151
  )
152
+ stub_request(:get, 'http://rubygems.org/api/v1/versions/zold/latest.json').to_return(
153
+ status: 200,
154
+ body: '{"version": "0.0.0"}'
155
+ )
114
156
  stub_request(:get, 'http://localhost:8883/remotes').to_return(status: 404)
115
157
  cmd = Zold::Remote.new(remotes: remotes, log: test_log)
116
158
  cmd.run(%w[remote clean])
File without changes
@@ -91,5 +91,18 @@ module Minitest
91
91
  @test_log = Zold::Log::Quiet.new if ENV['TEST_QUIET_LOG']
92
92
  Zold::Log::Sync.new(@test_log)
93
93
  end
94
+
95
+ class TestLogger
96
+ attr_accessor :msg
97
+ def initialize
98
+ @msg = []
99
+ end
100
+
101
+ def info(msg)
102
+ @msg << msg
103
+ end
104
+
105
+ def debug(msg); end
106
+ end
94
107
  end
95
108
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/zold/gem'
4
+ require 'webmock/minitest'
5
+ require 'minitest/autorun'
6
+
7
+ class TestGem < Minitest::Test
8
+ def test_last_version
9
+ gem = Zold::Gem.new
10
+ version = (1..3).map { rand(9).to_s } .join('.')
11
+ stub_request(:get, 'http://rubygems.org/api/v1/versions/zold/latest.json').to_return(
12
+ status: 200,
13
+ body: "{\"version\": \"#{version}\"}"
14
+ )
15
+ assert_equal(version, gem.last_version)
16
+ end
17
+ end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.38
4
+ version: 0.14.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-17 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cachy
@@ -484,6 +484,7 @@ files:
484
484
  - lib/zold/commands/show.rb
485
485
  - lib/zold/commands/taxes.rb
486
486
  - lib/zold/copies.rb
487
+ - lib/zold/gem.rb
487
488
  - lib/zold/hexnum.rb
488
489
  - lib/zold/http.rb
489
490
  - lib/zold/hungry_wallets.rb
@@ -556,6 +557,7 @@ files:
556
557
  - test/test_atomic_file.rb
557
558
  - test/test_backtrace.rb
558
559
  - test/test_copies.rb
560
+ - test/test_gem.rb
559
561
  - test/test_hexnum.rb
560
562
  - test/test_http.rb
561
563
  - test/test_id.rb
@@ -650,6 +652,7 @@ test_files:
650
652
  - test/test_atomic_file.rb
651
653
  - test/test_backtrace.rb
652
654
  - test/test_copies.rb
655
+ - test/test_gem.rb
653
656
  - test/test_hexnum.rb
654
657
  - test/test_http.rb
655
658
  - test/test_id.rb