fbe 0.0.27 → 0.0.29

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
  SHA256:
3
- metadata.gz: 0b7ed70e3e3d37780d727b9c269cd27a86179da0df8b781eb2cc8a339e443ac5
4
- data.tar.gz: 9635ce676a24efc7e63567d0b370588a4b8af12de34cbcc65bb5718991658c8e
3
+ metadata.gz: 3a53b788fa8aebdd8c99fafb67025447a67a8505a2d697fd13d1432ffd283dba
4
+ data.tar.gz: a69c498602b2b07157949b538260fbc2d0f2fc1d5f9071d979b9fc22c83f1ce3
5
5
  SHA512:
6
- metadata.gz: 5dfd3ace2f914dc4fa31869a743b41fd56851419f32e2d0b1077b1517b9faa9e8829ecc2c545653162161c0722856019ea112411133ec7c79a065eb046f376b1
7
- data.tar.gz: 87ffa308115144cf84cb725e084917473dce9ab3f73bca02dc2e231d160c74fb0a46cd4676791c0891d25b5406dc95f0313d08ffda13c8e6ff903fc625570798
6
+ metadata.gz: b47bdddfda8bd6d9c74280c51a9465f6924867c626ab44de5079c5e6ea5f2771385f23c9fa4f835eb122c77a407055583d6d82e50e045ef9c5e01514885ae2d0
7
+ data.tar.gz: cafad1b5e8ea0257f0ace46aa6782bfe9587d4a0fb06468554e569b5bd521f1e6ce01d1c65713428cd4918042cb38d2019b3cc56a3da05145f29d013788320cd
data/lib/fbe/award.rb CHANGED
@@ -148,9 +148,10 @@ class Fbe::Award
148
148
  v = to_val(@operands[0], bill)
149
149
  a = to_val(@operands[1], bill)
150
150
  b = to_val(@operands[2], bill)
151
- v = b if v > b
152
- v = a if v < a
153
- v
151
+ min, max = [a, b].minmax
152
+ return 0 if (v.positive? && v < min) || (v.negative? && v > max)
153
+
154
+ v.clamp(min, max)
154
155
  else
155
156
  raise "Unknown term '#{@op}'"
156
157
  end
data/lib/fbe/octo.rb CHANGED
@@ -37,16 +37,24 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
37
37
  if options.testing.nil?
38
38
  o = Octokit::Client.new
39
39
  token = options.github_token
40
- loog.debug("The 'github_token' option is not provided") if token.nil?
41
- token = ENV.fetch('GITHUB_TOKEN', nil) if token.nil?
42
- loog.debug("The 'GITHUB_TOKEN' environment variable is not set") if token.nil?
40
+ if token.nil?
41
+ loog.debug("The 'github_token' option is not provided")
42
+ token = ENV.fetch('GITHUB_TOKEN', nil)
43
+ if token.nil?
44
+ loog.debug("The 'GITHUB_TOKEN' environment variable is not set")
45
+ else
46
+ loog.debug("The 'GITHUB_TOKEN' environment was provided")
47
+ end
48
+ else
49
+ loog.debug("The 'github_token' option was provided")
50
+ end
43
51
  if token.nil?
44
52
  loog.warn('Accessing GitHub API without a token!')
45
53
  elsif token.empty?
46
54
  loog.warn('The GitHub API token is an empty string, won\'t use it')
47
55
  else
48
56
  o = Octokit::Client.new(access_token: token)
49
- loog.info("Accessing GitHub API with a token (#{token.length} chars)")
57
+ loog.info("Accessing GitHub API with a token (#{token.length} chars, ending by #{token[-4..]})")
50
58
  end
51
59
  o.auto_paginate = true
52
60
  o.per_page = 100
@@ -59,9 +67,11 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
59
67
  stack = Faraday::RackBuilder.new do |builder|
60
68
  builder.use(
61
69
  Faraday::Retry::Middleware,
62
- exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::Error],
63
- max: 5,
64
- interval: ENV['RACK_ENV'] == 'test' ? 0.1 : 10,
70
+ exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [
71
+ Octokit::TooManyRequests, Octokit::ServiceUnavailable
72
+ ],
73
+ max: 4,
74
+ interval: ENV['RACK_ENV'] == 'test' ? 0.01 : 4,
65
75
  methods: [:get],
66
76
  backoff_factor: 2
67
77
  )
@@ -138,9 +148,10 @@ class Fbe::FakeOctokit
138
148
  end
139
149
 
140
150
  def user(name)
151
+ name = name == 526_301 ? 'yegor256' : 'torvalds' if name.is_a?(Integer)
141
152
  {
142
153
  id: 444,
143
- login: 'yegor256',
154
+ login: name,
144
155
  type: name == 29_139_614 ? 'Bot' : 'User'
145
156
  }
146
157
  end
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.27'
30
+ VERSION = '0.0.29'
31
31
  end
@@ -79,7 +79,7 @@ class TestAward < Minitest::Test
79
79
  '(let x 25)' => 0,
80
80
  '(award (give 25 "for being a good boy"))' => 25,
81
81
  '(award (give (between 42 -10 -50) "empty"))' => -10,
82
- '(award (give (between -3 -10 -50) "empty"))' => -10,
82
+ '(award (give (between -3 -10 -50) "empty"))' => 0,
83
83
  '(award (give (between -100 -50 -10) "empty"))' => -50
84
84
  }.each do |q, v|
85
85
  a = Fbe::Award.new(q)
@@ -87,6 +87,20 @@ class TestAward < Minitest::Test
87
87
  end
88
88
  end
89
89
 
90
+ def test_must_not_give_anything_when_too_small_value
91
+ {
92
+ '(award (give (between 13 5 20)))' => 13,
93
+ '(award (give (between 3 5 20)))' => 0,
94
+ '(award (give (between 25 5 20)))' => 20,
95
+ '(award (give (between -2 -10 -30)))' => 0,
96
+ '(award (give (between -15 -10 -30)))' => -15,
97
+ '(award (give (between -50 -10 -30)))' => -30
98
+ }.each do |q, v|
99
+ a = Fbe::Award.new(q)
100
+ assert_equal(v, a.bill.points, q)
101
+ end
102
+ end
103
+
90
104
  def test_some_policies
91
105
  {
92
106
  '(award (let x_a 25) (set z (plus x_a 1)) (give z "..."))' =>
data/test/fbe/test_who.rb CHANGED
@@ -38,6 +38,6 @@ class TestWho < Minitest::Test
38
38
  f.who = 444
39
39
  global = {}
40
40
  options = Judges::Options.new({ 'testing' => true })
41
- assert_equal('@yegor256', Fbe.who(f, global:, options:, loog: Loog::NULL))
41
+ assert_equal('@torvalds', Fbe.who(f, global:, options:, loog: Loog::NULL))
42
42
  end
43
43
  end
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.27
4
+ version: 0.0.29
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-07-22 00:00:00.000000000 Z
11
+ date: 2024-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace