fbe 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b87495cdbc9d14a665375e86f7ff41abe3c437b3652275865aea95e1c85ef2b
4
- data.tar.gz: 5850f13fae6766c49d13977c08de32ef215428152ece1054cce1ea361cea3306
3
+ metadata.gz: 82aa4fc845f2c9cae3e6eab0134f2a3c222f69d5a9a758f9d7781ba55f4fd454
4
+ data.tar.gz: cfb626ee801720ea0085645eb10a8b46b57e9a9e863177071e649631559a7f9f
5
5
  SHA512:
6
- metadata.gz: '019491772bc7ecf4d1c889622de991184da5f3b74725cb9facfac40c579e53aac8cea42e7cb5037e0d972feeb6b619e3310ec0f7a6503d455e99accb958f6614'
7
- data.tar.gz: 95aa42ad2d82ab4d68120320a77c561443edc4443a3970f5e380a423d2c79fbd0deccff2e8af834181d5311fa099dda6c5e00055421ddc0a308a12bb8a4f2330
6
+ metadata.gz: 0a62d4ad1d1af3230b90b18af6dec389f0fee81e3a2850a59794c0981f0ba31428c2ff7474450085d4060a4f584d86ebc9f0301f92442d9179429f008eeb18d2
7
+ data.tar.gz: d443ad05ef6b5d75f920d597c232b50a8bce3fdb05eefd154a0d2dd2e636af9bc37d35ece6dc0a5165a2872965f7643f02424c336c6f112b6c63f89ab73219c1
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
@@ -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
@@ -84,24 +84,28 @@ 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
- next if restarted.include?(repo)
90
+ if restarted.include?(repo)
91
+ @loog.debug("Already restared #{repo}, won't iterate it anymore")
92
+ next
93
+ end
90
94
  seen[repo] = 0 if seen[repo].nil?
91
95
  if seen[repo] >= @repeats
92
96
  @loog.debug("We've seen too many in the #{repo} repo, time to move to the next one")
93
97
  next
94
98
  end
95
99
  rid = oct.repo_id_by_name(repo)
96
- before = Fbe.fb.query(
100
+ before = fb.query(
97
101
  "(agg (and (eq what '#{@label}') (eq where 'github') (eq repository #{rid})) (first latest))"
98
102
  ).one
99
- Fbe.fb.query("(and (eq what '#{@label}') (eq where 'github') (eq repository #{rid}))").delete!
103
+ fb.query("(and (eq what '#{@label}') (eq where 'github') (eq repository #{rid}))").delete!
100
104
  before = before.nil? ? @since : before.first
101
- nxt = Fbe.fb.query(@query).one(before:, repository: rid)
105
+ nxt = fb.query(@query).one(before:, repository: rid)
102
106
  after =
103
107
  if nxt.nil?
104
- @loog.debug("Next is nil, starting from the beginning at #{@since}")
108
+ @loog.debug("Next element after ##{before} not suggested, re-starting from ##{@since}: #{@query}")
105
109
  restarted << repo
106
110
  @since
107
111
  else
@@ -109,15 +113,15 @@ class Fbe::Iterate
109
113
  yield(rid, nxt)
110
114
  end
111
115
  raise "Iterator must return an Integer, while #{after.class} returned" unless after.is_a?(Integer)
112
- f = Fbe.fb.insert
116
+ f = fb.insert
113
117
  f.where = 'github'
114
118
  f.repository = rid
115
119
  f.latest =
116
120
  if after.nil?
117
- @loog.debug("After is nil at #{repo}, setting the `latest` to nxt: ##{nxt}")
121
+ @loog.debug("After is nil at #{repo}, setting the 'latest' to ##{nxt}")
118
122
  nxt
119
123
  else
120
- @loog.debug("After is ##{after} at #{repo}, setting the `latest` to it")
124
+ @loog.debug("After is ##{after} at #{repo}, setting the 'latest' to it")
121
125
  after
122
126
  end
123
127
  f.what = @label
@@ -135,6 +139,10 @@ class Fbe::Iterate
135
139
  @loog.debug('No more repos to scan, quitting')
136
140
  break
137
141
  end
142
+ if restarted.size == repos.size
143
+ @loog.debug("All #{repos.size} repos restarted, quitting")
144
+ break
145
+ end
138
146
  end
139
147
  @loog.debug("Finished scanning #{repos.size} repos: #{seen.map { |k, v| "#{k}:#{v}" }.join(', ')}")
140
148
  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.12'
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
+ fb = Fbe.fb
68
+ fb.insert.foo = 1
69
+ options = Judges::Options.new
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,53 @@ 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', 'testing=true'])
55
+ cycles = 0
56
+ Fbe.iterate(fb: Factbase.new, loog: Loog::NULL, global: {}, options: opts) do
57
+ as 'labels-were-scanned'
58
+ by '(plus 1 1)'
59
+ repeats 5
60
+ over do |_, nxt|
61
+ cycles += 1
62
+ nxt
63
+ end
64
+ end
65
+ assert_equal(5, cycles)
66
+ end
67
+
68
+ def test_with_restart
69
+ opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
70
+ cycles = 0
71
+ fb = Factbase.new
72
+ f = fb.insert
73
+ f.foo = 42
74
+ Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts) do
75
+ as 'labels-were-scanned'
76
+ by '(agg (and (eq foo 42) (not (exists bar))) (max foo))'
77
+ repeats 10
78
+ over do |_, nxt|
79
+ cycles += 1
80
+ f.bar = 1
81
+ nxt
82
+ end
83
+ end
84
+ assert_equal(1, cycles)
52
85
  end
53
86
  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.12
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