fbe 0.29.0 → 0.29.1
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/.github/workflows/typos.yml +1 -1
- data/lib/fbe/iterate.rb +40 -26
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_iterate.rb +171 -1
- 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: f08a090d74c79938d45d53b09d1cdb6fafada89c54b5c33b2b4154a1174ac38c
|
4
|
+
data.tar.gz: d927725171355f731620718cc2d7125e1f8e961af53e01c4d36e03c288fcd640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32999571b725d7b68de93231ea2bdb1731ddc2a8d2c84bbf84d248fd25fae5223a3fb3b6cb85c73364815548019055420344d2bc3bba4ef14e57450f131026c5
|
7
|
+
data.tar.gz: 6e26bb3ba8c15c24912b46c3a7841ebd59ab17a9ee3f530e7d19968efdbc8da9d20acaefa9fdece7c61999240118972277588b9ceda5e5a033cb4ef9be94166f
|
data/.github/workflows/typos.yml
CHANGED
data/lib/fbe/iterate.rb
CHANGED
@@ -69,7 +69,7 @@ end
|
|
69
69
|
# iterator.over(timeout: 600) do |repo_id, pr_number|
|
70
70
|
# # Process pull request
|
71
71
|
# fetch_and_store_pr(repo_id, pr_number)
|
72
|
-
# pr_number # Return next PR number to process
|
72
|
+
# pr_number + 1 # Return next PR number to process
|
73
73
|
# end
|
74
74
|
#
|
75
75
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -204,9 +204,25 @@ class Fbe::Iterate
|
|
204
204
|
@loog.debug('We are off GitHub quota, cannot even start, sorry')
|
205
205
|
return
|
206
206
|
end
|
207
|
-
repos = Fbe.unmask_repos(
|
207
|
+
repos = Fbe.unmask_repos(
|
208
|
+
loog: @loog, options: @options, global: @global, quota_aware: @quota_aware
|
209
|
+
).map { |n| oct.repo_id_by_name(n) }
|
208
210
|
restarted = []
|
209
211
|
start = Time.now
|
212
|
+
before =
|
213
|
+
repos.to_h do |repo|
|
214
|
+
[
|
215
|
+
repo,
|
216
|
+
@fb.query(
|
217
|
+
"(agg (and
|
218
|
+
(eq what '#{@label}')
|
219
|
+
(eq where 'github')
|
220
|
+
(eq repository #{repo}))
|
221
|
+
(first latest))"
|
222
|
+
).one&.first || @since
|
223
|
+
]
|
224
|
+
end
|
225
|
+
starts = before.dup
|
210
226
|
loop do
|
211
227
|
if @quota_aware && oct.off_quota?
|
212
228
|
@loog.info("We are off GitHub quota, time to stop after #{start.ago}")
|
@@ -231,35 +247,19 @@ class Fbe::Iterate
|
|
231
247
|
@loog.debug("We've seen too many (#{seen[repo]}) in #{repo}, let's see next one")
|
232
248
|
next
|
233
249
|
end
|
234
|
-
|
235
|
-
before =
|
236
|
-
"(agg (and (eq what '#{@label}') (eq where 'github') (eq repository #{rid})) (first latest))"
|
237
|
-
).one
|
238
|
-
@fb.query("(and (eq what '#{@label}') (eq where 'github') (eq repository #{rid}))").delete!
|
239
|
-
before = before.nil? ? @since : before.first
|
240
|
-
nxt = @fb.query(@query).one(@fb, before:, repository: rid)
|
241
|
-
after =
|
250
|
+
nxt = @fb.query(@query).one(@fb, before: before[repo], repository: repo)
|
251
|
+
before[repo] =
|
242
252
|
if nxt.nil?
|
243
|
-
@loog.debug("Next element after ##{before} not suggested, re-starting from ##{@since}: #{@query}")
|
253
|
+
@loog.debug("Next element after ##{before[repo]} not suggested, re-starting from ##{@since}: #{@query}")
|
244
254
|
restarted << repo
|
245
255
|
@since
|
246
256
|
else
|
247
|
-
@loog.debug("Next is ##{nxt}, starting from it
|
248
|
-
yield(
|
249
|
-
end
|
250
|
-
raise "Iterator must return an Integer, while #{after.class} returned" unless after.is_a?(Integer)
|
251
|
-
f = @fb.insert
|
252
|
-
f.where = 'github'
|
253
|
-
f.repository = rid
|
254
|
-
f.latest =
|
255
|
-
if after.nil?
|
256
|
-
@loog.debug("After is nil at #{repo}, setting the 'latest' to ##{nxt}")
|
257
|
-
nxt
|
258
|
-
else
|
259
|
-
@loog.debug("After is ##{after} at #{repo}, setting the 'latest' to it")
|
260
|
-
after
|
257
|
+
@loog.debug("Next is ##{nxt}, starting from it")
|
258
|
+
yield(repo, nxt)
|
261
259
|
end
|
262
|
-
|
260
|
+
unless before[repo].is_a?(Integer)
|
261
|
+
raise "Iterator must return an Integer, but #{before[repo].class} was returned"
|
262
|
+
end
|
263
263
|
seen[repo] += 1
|
264
264
|
end
|
265
265
|
unless seen.any? { |r, v| v < @repeats && !restarted.include?(r) }
|
@@ -271,6 +271,20 @@ class Fbe::Iterate
|
|
271
271
|
break
|
272
272
|
end
|
273
273
|
end
|
274
|
+
repos.each do |repo|
|
275
|
+
next if before[repo] == starts[repo]
|
276
|
+
@fb.query(
|
277
|
+
"(and
|
278
|
+
(eq what '#{@label}')
|
279
|
+
(eq where 'github')
|
280
|
+
(eq repository #{repo}))"
|
281
|
+
).delete!
|
282
|
+
f = @fb.insert
|
283
|
+
f.where = 'github'
|
284
|
+
f.repository = repo
|
285
|
+
f.latest = before[repo]
|
286
|
+
f.what = @label
|
287
|
+
end
|
274
288
|
@loog.debug("Finished scanning #{repos.size} repos in #{start.ago}: #{seen.map { |k, v| "#{k}:#{v}" }.joined}")
|
275
289
|
end
|
276
290
|
end
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_iterate.rb
CHANGED
@@ -39,8 +39,9 @@ class TestIterate < Fbe::Test
|
|
39
39
|
as 'labels-were-scanned'
|
40
40
|
by '(agg (always) (max foo))'
|
41
41
|
repeats 2
|
42
|
-
over(timeout: 0.1) do
|
42
|
+
over(timeout: 0.1) do |i|
|
43
43
|
sleep 0.2
|
44
|
+
i
|
44
45
|
end
|
45
46
|
end
|
46
47
|
assert_equal(2, fb.size)
|
@@ -80,4 +81,173 @@ class TestIterate < Fbe::Test
|
|
80
81
|
end
|
81
82
|
assert_equal(1, cycles)
|
82
83
|
end
|
84
|
+
|
85
|
+
def test_quota_aware_continues_when_quota_available
|
86
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
87
|
+
fb = Factbase.new
|
88
|
+
cycles = 0
|
89
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
90
|
+
as 'quota-test'
|
91
|
+
by '(plus 1 1)'
|
92
|
+
quota_aware
|
93
|
+
repeats 5
|
94
|
+
over do |_, nxt|
|
95
|
+
cycles += 1
|
96
|
+
nxt + 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
assert_equal(5, cycles)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_raises_when_label_not_set
|
103
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
104
|
+
fb = Factbase.new
|
105
|
+
assert_raises(StandardError) do
|
106
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
107
|
+
by '(plus 1 1)'
|
108
|
+
over { |_, nxt| nxt }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_raises_when_query_not_set
|
114
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
115
|
+
fb = Factbase.new
|
116
|
+
assert_raises(StandardError) do
|
117
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
118
|
+
as 'no-query-test'
|
119
|
+
over { |_, nxt| nxt }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_raises_when_block_returns_non_integer
|
125
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
126
|
+
fb = Factbase.new
|
127
|
+
assert_raises(StandardError) do
|
128
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
129
|
+
as 'non-integer-test'
|
130
|
+
by '(plus 1 1)'
|
131
|
+
over { |_, _| 'not-an-integer' }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_raises_when_label_set_twice
|
137
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
138
|
+
fb = Factbase.new
|
139
|
+
assert_raises(StandardError) do
|
140
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
141
|
+
as 'first-label'
|
142
|
+
as 'second-label'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_raises_when_query_set_twice
|
148
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
149
|
+
fb = Factbase.new
|
150
|
+
assert_raises(StandardError) do
|
151
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
152
|
+
by '(plus 1 1)'
|
153
|
+
by '(plus 2 2)'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_raises_when_repeats_is_nil
|
159
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
160
|
+
fb = Factbase.new
|
161
|
+
assert_raises(StandardError) do
|
162
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
163
|
+
as 'nil-repeats-test'
|
164
|
+
by '(plus 1 1)'
|
165
|
+
repeats nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_raises_when_repeats_is_not_positive
|
171
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
172
|
+
fb = Factbase.new
|
173
|
+
assert_raises(StandardError) do
|
174
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
175
|
+
as 'zero-repeats-test'
|
176
|
+
by '(plus 1 1)'
|
177
|
+
repeats 0
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_raises_when_label_is_nil
|
183
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
184
|
+
fb = Factbase.new
|
185
|
+
assert_raises(StandardError) do
|
186
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
187
|
+
as nil
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_raises_when_query_is_nil
|
193
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
194
|
+
fb = Factbase.new
|
195
|
+
assert_raises(StandardError) do
|
196
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
197
|
+
by nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_persists_marker_facts
|
203
|
+
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
|
204
|
+
fb = Factbase.new
|
205
|
+
fb.insert.num = 10
|
206
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
207
|
+
as 'marker-test'
|
208
|
+
by '(agg (always) (max num))'
|
209
|
+
repeats 1
|
210
|
+
over do |_, nxt|
|
211
|
+
nxt + 5
|
212
|
+
end
|
213
|
+
end
|
214
|
+
markers = fb.query("(and (eq what 'marker-test') (eq where 'github'))").each.to_a
|
215
|
+
assert_equal(1, markers.size)
|
216
|
+
assert_equal(15, markers.first.latest)
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_multiple_repositories_with_different_progress
|
220
|
+
opts = Judges::Options.new(['repositories=foo/bar,foo/baz', 'testing=true'])
|
221
|
+
fb = Factbase.new
|
222
|
+
results = []
|
223
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
224
|
+
as 'multi-repo-test'
|
225
|
+
by '(plus 1 1)'
|
226
|
+
repeats 2
|
227
|
+
over do |repo, nxt|
|
228
|
+
results << [repo, nxt]
|
229
|
+
nxt + 1
|
230
|
+
end
|
231
|
+
end
|
232
|
+
assert_equal(4, results.size)
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_all_repos_restart_causes_exit
|
236
|
+
opts = Judges::Options.new(['repositories=foo/bar,foo/baz', 'testing=true'])
|
237
|
+
fb = Factbase.new
|
238
|
+
cycles = 0
|
239
|
+
restarts = 0
|
240
|
+
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
|
241
|
+
as 'all-restart-test'
|
242
|
+
by '(agg (eq foo 123) (first foo))'
|
243
|
+
repeats 10
|
244
|
+
over do |_, nxt|
|
245
|
+
cycles += 1
|
246
|
+
restarts += 1 if nxt.nil?
|
247
|
+
nxt || 0
|
248
|
+
end
|
249
|
+
end
|
250
|
+
assert_equal(0, cycles)
|
251
|
+
assert_equal(0, restarts)
|
252
|
+
end
|
83
253
|
end
|