fbe 0.0.11 → 0.0.13

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: 9b87495cdbc9d14a665375e86f7ff41abe3c437b3652275865aea95e1c85ef2b
4
- data.tar.gz: 5850f13fae6766c49d13977c08de32ef215428152ece1054cce1ea361cea3306
3
+ metadata.gz: ddb68efaa2108636f7d036c7ce41054cb2df54b5dbb080c44fca22dc7afb0b56
4
+ data.tar.gz: 6f6e8fd827d6d9728a9149ccab9e2c70bc5cbefba0ec96845f5d1bf5f6dc7381
5
5
  SHA512:
6
- metadata.gz: '019491772bc7ecf4d1c889622de991184da5f3b74725cb9facfac40c579e53aac8cea42e7cb5037e0d972feeb6b619e3310ec0f7a6503d455e99accb958f6614'
7
- data.tar.gz: 95aa42ad2d82ab4d68120320a77c561443edc4443a3970f5e380a423d2c79fbd0deccff2e8af834181d5311fa099dda6c5e00055421ddc0a308a12bb8a4f2330
6
+ metadata.gz: 917d79f1b09563a98a7ef0dbfa86155de181c79dec11768854eef48b0f03d8ae7e23432ab01b69266ea498abf987d5723f3e0d54d694be2ce21e2686af9e47c9
7
+ data.tar.gz: ebe3be674f88f238e9d7d6506c2a0c03f27589ced7ee7eb899d1a869bca1964c752a7544299e0aebf6d080052b3bcf6b31bcd8c2224212b00bd3c202a8acf5ca
data/Gemfile.lock CHANGED
@@ -89,7 +89,7 @@ GEM
89
89
  i18n (1.14.5)
90
90
  concurrent-ruby (~> 1.0)
91
91
  io-console (0.7.2)
92
- irb (1.13.2)
92
+ irb (1.14.0)
93
93
  rdoc (>= 4.0.0)
94
94
  reline (>= 0.4.2)
95
95
  iri (0.8.0)
data/README.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/zerocracy/fbe)](https://hitsofcode.com/view/github/zerocracy/fbe)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/zerocracy/fbe/blob/master/LICENSE.txt)
13
13
 
14
- It's a collection of tools.
14
+ It's a collection of tools for
15
+ [zerocracy/judges-action](https://github.com/zerocracy/judges-action).
15
16
 
16
17
  ## How to contribute
17
18
 
data/fbe.gemspec CHANGED
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'English'
23
24
  require_relative 'lib/fbe'
24
25
 
25
26
  Gem::Specification.new do |s|
data/lib/fbe/conclude.rb CHANGED
@@ -38,7 +38,7 @@ end
38
38
  # Copyright:: Copyright (c) 2024 Zerocracy
39
39
  # License:: MIT
40
40
  class Fbe::Conclude
41
- def initialize(fb: Fbe.fb, judge: $judge, loog: $loog, options: $options, global: $global)
41
+ def initialize(fb:, judge:, loog:, options:, global:)
42
42
  @fb = fb
43
43
  @judge = judge
44
44
  @loog = loog
@@ -88,8 +88,8 @@ class Fbe::Conclude
88
88
  private
89
89
 
90
90
  def roll(&)
91
+ passed = 0
91
92
  catch :stop do
92
- passed = 0
93
93
  @fb.txn do |fbt|
94
94
  fbt.query(@query).each do |a|
95
95
  throw :stop if @quota_aware && Fbe.octo(loog: @loog, options: @options, global: @global).off_quota
@@ -99,6 +99,7 @@ class Fbe::Conclude
99
99
  end
100
100
  end
101
101
  end
102
+ @loog.debug("Found and processed #{passed} facts by: #{@query}")
102
103
  end
103
104
 
104
105
  def fill(fact, prev)
data/lib/fbe/fb.rb CHANGED
@@ -22,6 +22,7 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  # SOFTWARE.
24
24
 
25
+ require 'loog'
25
26
  require 'judges'
26
27
  require 'factbase'
27
28
  require 'factbase/looged'
data/lib/fbe/iterate.rb CHANGED
@@ -38,7 +38,7 @@ end
38
38
  # Copyright:: Copyright (c) 2024 Zerocracy
39
39
  # License:: MIT
40
40
  class Fbe::Iterate
41
- def initialize(fb: Fbe.fb, loog: $loog, options: $options, global: $global)
41
+ def initialize(fb:, loog:, options:, global:)
42
42
  @fb = fb
43
43
  @loog = loog
44
44
  @options = options
@@ -84,24 +84,25 @@ class Fbe::Iterate
84
84
  oct = Fbe.octo(loog: @loog, options: @options, global: @global)
85
85
  repos = Fbe.unmask_repos(loog: @loog, options: @options, global: @global)
86
86
  restarted = []
87
+ fb = Fbe.fb(fb: @fb, global: @global, options: @options)
87
88
  loop do
88
89
  repos.each do |repo|
89
90
  next if restarted.include?(repo)
90
91
  seen[repo] = 0 if seen[repo].nil?
91
92
  if seen[repo] >= @repeats
92
- @loog.debug("We've seen too many in the #{repo} repo, time to move to the next one")
93
+ @loog.debug("We've seen too many (#{seen[repo]}) in #{repo}, let's see next one")
93
94
  next
94
95
  end
95
96
  rid = oct.repo_id_by_name(repo)
96
- before = Fbe.fb.query(
97
+ before = fb.query(
97
98
  "(agg (and (eq what '#{@label}') (eq where 'github') (eq repository #{rid})) (first latest))"
98
99
  ).one
99
- Fbe.fb.query("(and (eq what '#{@label}') (eq where 'github') (eq repository #{rid}))").delete!
100
+ fb.query("(and (eq what '#{@label}') (eq where 'github') (eq repository #{rid}))").delete!
100
101
  before = before.nil? ? @since : before.first
101
- nxt = Fbe.fb.query(@query).one(before:, repository: rid)
102
+ nxt = fb.query(@query).one(before:, repository: rid)
102
103
  after =
103
104
  if nxt.nil?
104
- @loog.debug("Next is nil, starting from the beginning at #{@since}")
105
+ @loog.debug("Next element after ##{before} not suggested, re-starting from ##{@since}: #{@query}")
105
106
  restarted << repo
106
107
  @since
107
108
  else
@@ -109,15 +110,15 @@ class Fbe::Iterate
109
110
  yield(rid, nxt)
110
111
  end
111
112
  raise "Iterator must return an Integer, while #{after.class} returned" unless after.is_a?(Integer)
112
- f = Fbe.fb.insert
113
+ f = fb.insert
113
114
  f.where = 'github'
114
115
  f.repository = rid
115
116
  f.latest =
116
117
  if after.nil?
117
- @loog.debug("After is nil at #{repo}, setting the `latest` to nxt: ##{nxt}")
118
+ @loog.debug("After is nil at #{repo}, setting the 'latest' to ##{nxt}")
118
119
  nxt
119
120
  else
120
- @loog.debug("After is ##{after} at #{repo}, setting the `latest` to it")
121
+ @loog.debug("After is ##{after} at #{repo}, setting the 'latest' to it")
121
122
  after
122
123
  end
123
124
  f.what = @label
@@ -131,8 +132,12 @@ class Fbe::Iterate
131
132
  @loog.debug('We are off GitHub quota, time to stop')
132
133
  break
133
134
  end
134
- unless seen.values.any? { |v| v < @repeats }
135
- @loog.debug('No more repos to scan, quitting')
135
+ unless seen.any? { |r, v| v < @repeats && !restarted.include?(r) }
136
+ @loog.debug("No more repos to scan (out of #{repos.size}), quitting")
137
+ break
138
+ end
139
+ if restarted.size == repos.size
140
+ @loog.debug("All #{repos.size} repos restarted, quitting")
136
141
  break
137
142
  end
138
143
  end
@@ -52,6 +52,7 @@ module Fbe
52
52
  re = Fbe.mask_to_regex(mask[1..])
53
53
  repos.reject! { |r| re.match?(r) }
54
54
  end
55
+ raise "No repos found matching: #{options.repositories}" if repos.empty?
55
56
  loog.debug("Scanning #{repos.size} repositories: #{repos.join(', ')}...")
56
57
  repos
57
58
  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.11'
30
+ VERSION = '0.0.13'
31
31
  end
@@ -50,7 +50,7 @@ class TestConclude < Minitest::Test
50
50
  fb = Factbase.new
51
51
  fb.insert.foo = 1
52
52
  fb.insert.bar = 2
53
- Fbe.conclude(fb:, judge: 'judge-one', loog: Loog::NULL) do
53
+ Fbe.conclude(fb:, judge: 'judge-one', loog: Loog::NULL, global: {}, options: Judges::Options.new) do
54
54
  on '(exists foo)'
55
55
  draw do |n, prev|
56
56
  n.sum = prev.foo + 1
@@ -64,12 +64,10 @@ class TestConclude < Minitest::Test
64
64
  end
65
65
 
66
66
  def test_maybe
67
- $fb = Factbase.new
68
- $global = {}
69
- $options = Judges::Options.new
70
- $loog = Loog::NULL
71
- Fbe.fb.insert.foo = 1
72
- Fbe.conclude(judge: 'issue-was-opened', loog: Loog::NULL) do
67
+ options = Judges::Options.new
68
+ fb = Fbe.fb(global: {}, options:)
69
+ fb.insert.foo = 1
70
+ Fbe.conclude(fb:, judge: 'issue-was-opened', loog: Loog::NULL, options:, global: {}) do
73
71
  on '(exists foo)'
74
72
  maybe do |n, prev|
75
73
  n.repository = 111
@@ -80,24 +78,22 @@ class TestConclude < Minitest::Test
80
78
  "it's a test." * 20
81
79
  end
82
80
  end
83
- f = Fbe.fb.query('(exists issue)').each.to_a[0]
81
+ f = fb.query('(exists issue)').each.to_a[0]
84
82
  assert_equal(1, f.issue)
85
83
  assert(f._id.positive?)
86
84
  end
87
85
 
88
86
  def test_consider
89
- $fb = Factbase.new
90
- $global = {}
91
- $options = Judges::Options.new
92
- $loog = Loog::NULL
93
- Fbe.fb.insert.foo = 1
94
- Fbe.conclude(judge: 'issue-was-closed', loog: Loog::NULL) do
87
+ fb = Factbase.new
88
+ fb.insert.foo = 1
89
+ options = Judges::Options.new
90
+ Fbe.conclude(fb:, judge: 'issue-was-closed', loog: Loog::NULL, options:, global: {}) do
95
91
  on '(exists foo)'
96
92
  consider do |_prev|
97
- Fbe.fb.insert.bar = 42
93
+ fb.insert.bar = 42
98
94
  end
99
95
  end
100
- f = Fbe.fb.query('(exists bar)').each.to_a[0]
96
+ f = fb.query('(exists bar)').each.to_a[0]
101
97
  assert_equal(42, f.bar)
102
98
  end
103
99
  end
@@ -34,20 +34,54 @@ require_relative '../../lib/fbe/iterate'
34
34
  # License:: MIT
35
35
  class TestIterate < Minitest::Test
36
36
  def test_simple
37
- $options = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
38
- $global = {}
39
- $fb = Factbase.new
40
- $fb.insert.foo = 42
41
- Fbe.iterate(loog: Loog::NULL) do
37
+ opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
38
+ fb = Factbase.new
39
+ fb.insert.foo = 42
40
+ Fbe.iterate(fb:, loog: Loog::NULL, options: opts, global: {}) do
42
41
  as 'labels-were-scanned'
43
42
  by '(agg (always) (max foo))'
44
43
  repeats 2
45
44
  over do |_repository, foo|
46
- f = $fb.insert
45
+ f = fb.insert
47
46
  f.foo = foo + 1
48
47
  f.foo
49
48
  end
50
49
  end
51
- assert_equal(4, $fb.size)
50
+ assert_equal(4, fb.size)
51
+ end
52
+
53
+ def test_many_repeats
54
+ opts = Judges::Options.new(['repositories=foo/bar,foo/second', 'testing=true'])
55
+ cycles = 0
56
+ reps = 5
57
+ Fbe.iterate(fb: Factbase.new, loog: Loog::NULL, global: {}, options: opts) do
58
+ as 'labels-were-scanned'
59
+ by '(plus 1 1)'
60
+ repeats reps
61
+ over do |_, nxt|
62
+ cycles += 1
63
+ nxt
64
+ end
65
+ end
66
+ assert_equal(reps * 2, cycles)
67
+ end
68
+
69
+ def test_with_restart
70
+ opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
71
+ cycles = 0
72
+ fb = Factbase.new
73
+ f = fb.insert
74
+ f.foo = 42
75
+ Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
76
+ as 'labels-were-scanned'
77
+ by '(agg (and (eq foo 42) (not (exists bar))) (max foo))'
78
+ repeats 10
79
+ over do |_, nxt|
80
+ cycles += 1
81
+ f.bar = 1
82
+ nxt
83
+ end
84
+ end
85
+ assert_equal(1, cycles)
52
86
  end
53
87
  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.11
4
+ version: 0.0.13
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-06 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace