fbe 0.24.2 → 0.24.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fbe/conclude.rb +16 -13
- data/lib/fbe/octo.rb +10 -2
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_conclude.rb +44 -0
- data/test/fbe/test_octo.rb +47 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce758baa2b569c87b5c6318bd2a58df0a5041c578164bb07f337c197a83ef4a7
|
4
|
+
data.tar.gz: fa85c249bc4ea36ecf435e0412bccd9a1c8885ed222f0538be0c02ebd4f59ccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43e184c1ee6955ca80cd5a4ba01aa47cf5e59ce8ad1767c03e535c77c253a1bb9223d6603825ef99c6d094828d03e3ae7b6a68e3cc4b7766cfb108c3058fa714
|
7
|
+
data.tar.gz: f1399b8d6b1022a2460f6c1049bd2b58aa924933773c0bdbec3cc21ba65e28aeca6712d382fdd070e0ec5f44f8c5ac3608aacdb9d87857c11f00b45bc6efd728
|
data/Gemfile.lock
CHANGED
data/lib/fbe/conclude.rb
CHANGED
@@ -17,13 +17,13 @@ require_relative 'if_absent'
|
|
17
17
|
# @param [Judges::Options] options The options coming from the +judges+ tool
|
18
18
|
# @param [Loog] loog The logging facility
|
19
19
|
# @yield [Factbase::Fact] The fact
|
20
|
-
def Fbe.conclude(fb: Fbe.fb, judge: $judge, loog: $loog, options: $options, global: $global, &)
|
20
|
+
def Fbe.conclude(fb: Fbe.fb, judge: $judge, loog: $loog, options: $options, global: $global, time: Time, &)
|
21
21
|
raise 'The fb is nil' if fb.nil?
|
22
22
|
raise 'The $judge is not set' if judge.nil?
|
23
23
|
raise 'The $global is not set' if global.nil?
|
24
24
|
raise 'The $options is not set' if options.nil?
|
25
25
|
raise 'The $loog is not set' if loog.nil?
|
26
|
-
c = Fbe::Conclude.new(fb:, judge:, loog:, options:, global:)
|
26
|
+
c = Fbe::Conclude.new(fb:, judge:, loog:, options:, global:, time:)
|
27
27
|
c.instance_eval(&)
|
28
28
|
end
|
29
29
|
|
@@ -58,7 +58,8 @@ class Fbe::Conclude
|
|
58
58
|
# @param [Hash] global The hash for global caching
|
59
59
|
# @param [Judges::Options] options The options coming from the +judges+ tool
|
60
60
|
# @param [Loog] loog The logging facility
|
61
|
-
|
61
|
+
# @param [Time] time The time
|
62
|
+
def initialize(fb:, judge:, global:, options:, loog:, time: Time)
|
62
63
|
@fb = fb
|
63
64
|
@judge = judge
|
64
65
|
@loog = loog
|
@@ -68,6 +69,7 @@ class Fbe::Conclude
|
|
68
69
|
@follows = []
|
69
70
|
@quota_aware = false
|
70
71
|
@timeout = 60
|
72
|
+
@time = time
|
71
73
|
end
|
72
74
|
|
73
75
|
# Make this block aware of GitHub API quota.
|
@@ -180,22 +182,23 @@ class Fbe::Conclude
|
|
180
182
|
# end
|
181
183
|
def roll(&)
|
182
184
|
passed = 0
|
183
|
-
start =
|
185
|
+
start = @time.now
|
184
186
|
oct = Fbe.octo(loog: @loog, options: @options, global: @global)
|
185
187
|
@fb.query(@query).each do |a|
|
188
|
+
if @quota_aware && oct.off_quota?
|
189
|
+
@loog.debug('We ran out of GitHub quota, must stop here')
|
190
|
+
break
|
191
|
+
end
|
192
|
+
now = @time.now
|
193
|
+
if now > start + @timeout
|
194
|
+
@loog.debug("We've spent more than #{start.ago}, must stop here")
|
195
|
+
break
|
196
|
+
end
|
186
197
|
@fb.txn do |fbt|
|
187
|
-
if @quota_aware && oct.off_quota?
|
188
|
-
@loog.debug('We ran out of GitHub quota, must stop here')
|
189
|
-
throw :commit
|
190
|
-
end
|
191
|
-
if Time.now > start + @timeout
|
192
|
-
@loog.debug("We've spent more than #{start.ago}, must stop here")
|
193
|
-
throw :commit
|
194
|
-
end
|
195
198
|
n = yield fbt, a
|
196
199
|
@loog.info("#{n.what}: #{n.details}") unless n.nil?
|
197
|
-
passed += 1
|
198
200
|
end
|
201
|
+
passed += 1
|
199
202
|
end
|
200
203
|
@loog.debug("Found and processed #{passed} facts by: #{@query}")
|
201
204
|
passed
|
data/lib/fbe/octo.rb
CHANGED
@@ -665,7 +665,8 @@ class Fbe::FakeOctokit
|
|
665
665
|
user: { login: 'yegor256', id: 526_301, type: 'User' },
|
666
666
|
created_at: Time.parse('2025-06-01 12:00:55 UTC'),
|
667
667
|
updated_at: Time.parse('2025-06-01 15:47:18 UTC'),
|
668
|
-
closed_at: Time.parse('2025-06-02 15:00:00 UTC')
|
668
|
+
closed_at: Time.parse('2025-06-02 15:00:00 UTC'),
|
669
|
+
closed_by: { id: 526_301, login: 'yegor256' }
|
669
670
|
}
|
670
671
|
elsif number == 143
|
671
672
|
{
|
@@ -676,7 +677,8 @@ class Fbe::FakeOctokit
|
|
676
677
|
pull_request: { merged_at: nil },
|
677
678
|
created_at: Time.parse('2025-05-29 17:00:55 UTC'),
|
678
679
|
updated_at: Time.parse('2025-05-29 19:00:00 UTC'),
|
679
|
-
closed_at: Time.parse('2025-06-01 18:20:00 UTC')
|
680
|
+
closed_at: Time.parse('2025-06-01 18:20:00 UTC'),
|
681
|
+
closed_by: { id: 526_301, login: 'yegor256' }
|
680
682
|
}
|
681
683
|
else
|
682
684
|
{
|
@@ -708,6 +710,11 @@ class Fbe::FakeOctokit
|
|
708
710
|
repo: {
|
709
711
|
full_name: repo
|
710
712
|
},
|
713
|
+
base: {
|
714
|
+
repo: {
|
715
|
+
full_name: repo
|
716
|
+
}
|
717
|
+
},
|
711
718
|
state: 'closed',
|
712
719
|
user: { login: 'yegor256', id: 526_301, type: 'User' },
|
713
720
|
head: { ref: 'master', sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e' },
|
@@ -716,6 +723,7 @@ class Fbe::FakeOctokit
|
|
716
723
|
changed_files: 3,
|
717
724
|
comments: 2,
|
718
725
|
review_comments: 2,
|
726
|
+
closed_at: Time.parse('2024-12-20'),
|
719
727
|
merged_at: Time.parse('2024-12-20'),
|
720
728
|
created_at: Time.parse('2024-09-20')
|
721
729
|
}
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_conclude.rb
CHANGED
@@ -125,4 +125,48 @@ class TestConclude < Fbe::Test
|
|
125
125
|
end
|
126
126
|
assert_equal(2, fb.size)
|
127
127
|
end
|
128
|
+
|
129
|
+
def test_stop_if_timeout_exceeded
|
130
|
+
$fb = Factbase.new
|
131
|
+
$fb.insert.then do |f|
|
132
|
+
f._id = 1
|
133
|
+
f.foo = 5
|
134
|
+
end
|
135
|
+
$fb.insert.then do |f|
|
136
|
+
f._id = 2
|
137
|
+
f.foo = 4
|
138
|
+
end
|
139
|
+
$fb.insert.then do |f|
|
140
|
+
f._id = 3
|
141
|
+
f.bar = 3
|
142
|
+
end
|
143
|
+
$fb.insert.then do |f|
|
144
|
+
f._id = 4
|
145
|
+
f.foo = 2
|
146
|
+
end
|
147
|
+
$fb.insert.then do |f|
|
148
|
+
f._id = 5
|
149
|
+
f.foo = 1
|
150
|
+
end
|
151
|
+
$global = {}
|
152
|
+
$options = Judges::Options.new({ 'testing' => true })
|
153
|
+
$loog = Loog::NULL
|
154
|
+
$judge = ''
|
155
|
+
total = 0
|
156
|
+
now = Time.now
|
157
|
+
time = Minitest::Mock.new
|
158
|
+
time.expect(:now, now)
|
159
|
+
time.expect(:now, now + 4)
|
160
|
+
time.expect(:now, now + 8)
|
161
|
+
time.expect(:now, now + 12)
|
162
|
+
Fbe.conclude(time: time) do
|
163
|
+
on '(exists foo)'
|
164
|
+
timeout 10
|
165
|
+
consider do |f|
|
166
|
+
total += f.foo
|
167
|
+
end
|
168
|
+
end
|
169
|
+
assert_equal(9, total)
|
170
|
+
time.verify
|
171
|
+
end
|
128
172
|
end
|
data/test/fbe/test_octo.rb
CHANGED
@@ -662,4 +662,51 @@ class TestOcto < Fbe::Test
|
|
662
662
|
https://github.com/octokit/octokit.rb/blob/ea3413c3174571e87c83d358fc893cc7613091fa/lib/octokit/connection.rb#L109-L119
|
663
663
|
MSG
|
664
664
|
end
|
665
|
+
|
666
|
+
def test_octo_cache_still_available_on_duration_of_age
|
667
|
+
WebMock.disable_net_connect!
|
668
|
+
now = Time.now
|
669
|
+
age = 60
|
670
|
+
stub_request(:get, 'https://api.github.com/rate_limit')
|
671
|
+
.to_return(
|
672
|
+
status: 200, headers: { 'Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '5000' },
|
673
|
+
body: { 'rate' => { 'limit' => 5000, 'remaining' => 5000, 'reset' => 1_672_531_200 } }.to_json
|
674
|
+
)
|
675
|
+
Dir.mktmpdir do |dir|
|
676
|
+
sqlite_cache = File.expand_path('t.db', dir)
|
677
|
+
o = Fbe.octo(loog: fake_loog, global: {}, options: Judges::Options.new({ 'sqlite_cache' => sqlite_cache }))
|
678
|
+
stub_request(:get, 'https://api.github.com/repositories/798641472').to_return(
|
679
|
+
status: 200,
|
680
|
+
body: { id: 798_641_472, name: 'factbase' }.to_json,
|
681
|
+
headers: {
|
682
|
+
'Date' => now.httpdate,
|
683
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
684
|
+
'Cache-Control' => "public, max-age=#{age}, s-maxage=#{age}",
|
685
|
+
'Etag' => 'W/"f5f1ea995fd7266816f681aca5a81f539420c469070a47568bebdaa3055487bc"',
|
686
|
+
'Last-Modified' => 'Fri, 04 Jul 2025 13:39:42 GMT'
|
687
|
+
}
|
688
|
+
).times(1).then.to_raise('no more request to /repositories/798641472')
|
689
|
+
assert_equal('factbase', o.repo(798_641_472)['name'])
|
690
|
+
Time.stub(:now, now + age - 1) do
|
691
|
+
assert_equal('factbase', o.repo(798_641_472)['name'])
|
692
|
+
end
|
693
|
+
stub_request(:get, 'https://api.github.com/repositories/798641472').to_return(
|
694
|
+
status: 200,
|
695
|
+
body: { id: 798_641_472, name: 'factbase_changed' }.to_json,
|
696
|
+
headers: {
|
697
|
+
'Date' => (now + age).httpdate,
|
698
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
699
|
+
'Cache-Control' => "public, max-age=#{age}, s-maxage=#{age}",
|
700
|
+
'Etag' => 'W/"f5f1ea995fd7266816f681aca5a81f539420c469070a47568bebdaa3055487be"',
|
701
|
+
'Last-Modified' => 'Fri, 04 Jul 2025 13:39:42 GMT'
|
702
|
+
}
|
703
|
+
).times(1).then.to_raise('no more request to /repositories/798641472')
|
704
|
+
Time.stub(:now, now + age) do
|
705
|
+
assert_equal('factbase_changed', o.repo(798_641_472)['name'])
|
706
|
+
end
|
707
|
+
Time.stub(:now, now + (2 * age) - 1) do
|
708
|
+
assert_equal('factbase_changed', o.repo(798_641_472)['name'])
|
709
|
+
end
|
710
|
+
end
|
711
|
+
end
|
665
712
|
end
|