fbe 0.0.26 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/lib/fbe/award.rb +4 -3
- data/lib/fbe/octo.rb +17 -6
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_award.rb +15 -1
- data/test/fbe/test_octo.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd990128519eca8f209d125189adf9c6478747eacf3f1c38b78453a41b6fc743
|
4
|
+
data.tar.gz: d19077d3747061780cb14f45efbbc8ab84399e8c959d11c2bfaf197ce215b1d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74f4e2a03f13db7d934e29ebbee0357796b6c192401a65ac3bdeb01422a920b80c4e24c70191bf4ffb2ffb482131026cac0c43fdfbff1bd5d448e8df1368fb83
|
7
|
+
data.tar.gz: 5918f4ea19d6b979411cae675a37f290894ac139fef72a4c021222001f96a52963150e0ae362b4bbb5d24d09b46694491f4d64efb4edc89224cb0396ef9350be
|
data/Rakefile
CHANGED
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
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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[-(token.size - 4)..]})")
|
50
58
|
end
|
51
59
|
o.auto_paginate = true
|
52
60
|
o.per_page = 100
|
@@ -59,8 +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::
|
63
|
-
max: 5,
|
70
|
+
exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::Error],
|
71
|
+
max: 5,
|
72
|
+
interval: ENV['RACK_ENV'] == 'test' ? 0.1 : 10,
|
73
|
+
methods: [:get],
|
74
|
+
backoff_factor: 2
|
64
75
|
)
|
65
76
|
builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false, logger: Loog::NULL)
|
66
77
|
builder.use(Octokit::Response::RaiseError)
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_award.rb
CHANGED
@@ -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"))' =>
|
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_octo.rb
CHANGED
@@ -80,6 +80,18 @@ class TestOcto < Minitest::Test
|
|
80
80
|
o.user('yegor256')
|
81
81
|
end
|
82
82
|
|
83
|
+
def test_retrying_on_error_response
|
84
|
+
WebMock.disable_net_connect!
|
85
|
+
global = {}
|
86
|
+
o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
|
87
|
+
stub_request(:get, 'https://api.github.com/users/yegor256')
|
88
|
+
.to_return(status: 503)
|
89
|
+
.times(1)
|
90
|
+
.then
|
91
|
+
.to_return(status: 200, body: '{}')
|
92
|
+
o.user('yegor256')
|
93
|
+
end
|
94
|
+
|
83
95
|
def test_with_broken_token
|
84
96
|
skip # it's a "live" test, run it manually if you need it
|
85
97
|
WebMock.enable_net_connect!
|
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.
|
4
|
+
version: 0.0.28
|
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-
|
11
|
+
date: 2024-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|