fbe 0.0.42 → 0.0.44

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
  SHA256:
3
- metadata.gz: '095a45978ce9e57eae04c5d10dc974071b3400dfe5f3fe0ce5da88acf87d6fd1'
4
- data.tar.gz: 63e430609dab7392f310b9772f35a427d8ec8799717da1a7fb70c4552d92a44c
3
+ metadata.gz: e48e27db602678e608a7b2301e9a70e801c4651fef5cbca3c9f0e17082109572
4
+ data.tar.gz: ca468197e588f5267e7d9c33c169a0e156bed76d71a6bd0f03d7125e341f08c1
5
5
  SHA512:
6
- metadata.gz: 223d399f84eb5a6290b4c0e13d0e04124a6ebd449964ce60b439942b73e6fda71db43ddead097b0a8ca15adea0e37bf9e6d5938a281d602ba3333fd4634bcdda
7
- data.tar.gz: 405c244aa9637bda9fb035051248c54edf9c6eba6008f4c371e435a34ab5e80c7d93b4796e55650335714b30062cbf66b211acb7bdf48a8270fbeb5fd0c29ae7
6
+ metadata.gz: d2efed7f06e47435b287774682305f856194426271dc6afe5e2c2763877066f2e0c389812ff6ee1d8ff19addb51f71c6d127e42509728107e01d45a3511762d1
7
+ data.tar.gz: d23a168fcbaeec4ac9e8541f25d3ac212b65c0f92f968926942fa4dc593d7a52635945b67592e0f59745ca2f131702b6951716573c4982eb42d52840b94cfab1
@@ -26,13 +26,20 @@ require 'faraday'
26
26
 
27
27
  # Faraday Middleware that monitors GitHub API rate limits.
28
28
  class Fbe::Middleware::Quota < Faraday::Middleware
29
- def initialize(app, logger: Loog::NULL, pause: 60, limit: 100, rate: 5)
29
+ def initialize(app, loog: Loog::NULL, pause: 60, limit: 100, rate: 5)
30
30
  super(app)
31
- @limit = limit
32
31
  @requests = 0
33
32
  @app = app
34
- @logger = logger
33
+ raise 'The "loog" cannot be nil' if loog.nil?
34
+ @loog = loog
35
+ raise 'The "pause" cannot be nil' if pause.nil?
36
+ raise 'The "pause" must be a positive integer' unless pause.positive?
35
37
  @pause = pause
38
+ raise 'The "limit" cannot be nil' if limit.nil?
39
+ raise 'The "limit" must be a positive integer' unless limit.positive?
40
+ @limit = limit
41
+ raise 'The "rate" cannot be nil' if rate.nil?
42
+ raise 'The "rate" must be a positive integer' unless rate.positive?
36
43
  @rate = rate
37
44
  end
38
45
 
@@ -40,7 +47,7 @@ class Fbe::Middleware::Quota < Faraday::Middleware
40
47
  @requests += 1
41
48
  response = @app.call(env)
42
49
  if out_of_limit?(env)
43
- @logger.info(
50
+ @loog.info(
44
51
  "Too much GitHub API quota consumed, pausing for #{@pause} seconds"
45
52
  )
46
53
  sleep(@pause)
data/lib/fbe/octo.rb CHANGED
@@ -33,6 +33,15 @@ require_relative '../fbe'
33
33
  require_relative 'middleware'
34
34
  require_relative 'middleware/quota'
35
35
 
36
+ # Interface to GitHub API.
37
+ #
38
+ # It is supposed to be used instead of Octokit client, because it
39
+ # is pre-configured and enables additional fearues, such as retrying,
40
+ # logging, and caching.
41
+ #
42
+ # @param [Judges::Options] options The options available globally
43
+ # @param [Hash] global Hash of global options
44
+ # @param [Loog] loog Logging facility
36
45
  def Fbe.octo(options: $options, global: $global, loog: $loog)
37
46
  raise 'The $global is not set' if global.nil?
38
47
  global[:octo] ||=
@@ -79,11 +88,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
79
88
  methods: [:get],
80
89
  backoff_factor: 2
81
90
  )
82
- builder.use(
83
- Fbe::Middleware::Quota,
84
- logger: loog,
85
- pause: options.github_api_pause
86
- )
91
+ builder.use(Fbe::Middleware::Quota, loog:, pause: options.github_api_pause || 60)
87
92
  builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false, logger: Loog::NULL)
88
93
  builder.use(Octokit::Response::RaiseError)
89
94
  builder.use(Faraday::Response::Logger, Loog::NULL)
@@ -353,6 +358,8 @@ class Fbe::FakeOctokit
353
358
  }
354
359
  else
355
360
  {
361
+ total_count: 1,
362
+ incomplete_results: false,
356
363
  items: [
357
364
  {
358
365
  number: 42,
data/lib/fbe/overwrite.rb CHANGED
@@ -38,11 +38,12 @@ require_relative 'fb'
38
38
  # @param [String] property The name of the property to set
39
39
  # @param [Any] vqlue The value to set
40
40
  def Fbe.overwrite(fact, property, value, fb: Fbe.fb)
41
+ raise 'The fact is nil' if fact.nil?
41
42
  before = {}
42
43
  fact.all_properties.each do |prop|
43
44
  before[prop.to_s] = fact[prop]
44
45
  end
45
- id = fact['_id'].first
46
+ id = fact['_id']&.first
46
47
  raise 'There is no _id in the fact, cannot use Fbe.overwrite' if id.nil?
47
48
  raise "No facts by _id = #{id}" if fb.query("(eq _id #{id})").delete!.zero?
48
49
  n = fb.insert
data/lib/fbe.rb CHANGED
@@ -27,5 +27,5 @@
27
27
  # License:: MIT
28
28
  module Fbe
29
29
  # Current version of the gem (changed by .rultor.yml on every release)
30
- VERSION = '0.0.42'
30
+ VERSION = '0.0.44'
31
31
  end
@@ -45,9 +45,9 @@ class QuotaTest < Minitest::Test
45
45
 
46
46
  def test_quota_middleware_pauses_when_quota_low
47
47
  loog = Loog::NULL
48
- pause = 0
48
+ pause = 1
49
49
  app = FakeApp.new
50
- middleware = Fbe::Middleware::Quota.new(app, logger: loog, pause:)
50
+ middleware = Fbe::Middleware::Quota.new(app, loog:, pause:)
51
51
  start_time = Time.now
52
52
  105.times do
53
53
  env = Judges::Options.new(
@@ -66,7 +66,7 @@ class QuotaTest < Minitest::Test
66
66
  log_output = StringIO.new
67
67
  loog = Logger.new(log_output)
68
68
  app = FakeApp.new
69
- middleware = Fbe::Middleware::Quota.new(app, logger: loog, pause:)
69
+ middleware = Fbe::Middleware::Quota.new(app, loog:, pause:)
70
70
  105.times do
71
71
  env = Judges::Options.new(
72
72
  'method' => :get,
@@ -54,6 +54,14 @@ class TestOverwrite < Minitest::Test
54
54
  assert_equal(42, fb.query('(always)').each.to_a.first['foo'].first)
55
55
  end
56
56
 
57
+ def test_without_id
58
+ fb = Factbase.new
59
+ f = fb.insert
60
+ assert_raises do
61
+ Fbe.overwrite(f, :foo, 42, fb:)
62
+ end
63
+ end
64
+
57
65
  def test_safe_insert
58
66
  fb = Factbase.new
59
67
  f1 = fb.insert
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.42
4
+ version: 0.0.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-07 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace