fbe 0.48.3 → 0.48.4

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.
data/lib/fbe/award.rb CHANGED
@@ -37,7 +37,7 @@ class Fbe::Award
37
37
  # @param [Judges::Options] options The options coming from the +judges+ tool
38
38
  # @param [Loog] loog The logging facility
39
39
  def initialize(query = nil, judge: $judge, global: $global, options: $options, loog: $loog)
40
- query = Fbe.pmp(fb: Fbe.fb, global:, options:, loog:).hr.send(judge.tr('-', '_')) if query.nil?
40
+ query = Fbe.pmp(fb: Fbe.fb, global:, options:, loog:).hr.public_send(judge.tr('-', '_')) if query.nil?
41
41
  @query = query
42
42
  end
43
43
 
@@ -109,26 +109,26 @@ class Fbe::Award
109
109
  @operands.each do |o|
110
110
  o.bill_to(bill)
111
111
  rescue StandardError => e
112
- raise "Failure in #{o}: #{e.message}"
112
+ raise(Fbe::Error, "Failure in #{o}: #{e.message}")
113
113
  end
114
114
  when :aka
115
115
  @operands[0..-2].each do |o|
116
116
  o.bill_to(bill)
117
117
  rescue StandardError => e
118
- raise "Failure in #{o}: #{e.message}"
118
+ raise(Fbe::Error, "Failure in #{o}: #{e.message}")
119
119
  end
120
120
  when :let, :set
121
121
  v = to_val(@operands[1], bill)
122
- raise "Can't #{@op.inspect} #{@operands[0].inspect} to nil" if v.nil?
122
+ raise(Fbe::Error, "Can't #{@op.inspect} #{@operands[0].inspect} to nil") if v.nil?
123
123
  bill.set(@operands[0], v)
124
124
  when :give
125
125
  text = @operands[1]
126
126
  text = '' if text.nil?
127
127
  bill.line(to_val(@operands[0], bill), text)
128
128
  when :explain, :in
129
- # nothing, just ignore
129
+ nil
130
130
  else
131
- raise "Unknown term '#{@op}'"
131
+ raise(Fbe::Error, "Unknown term '#{@op}'")
132
132
  end
133
133
  end
134
134
 
@@ -147,7 +147,7 @@ class Fbe::Award
147
147
  any.calc(bill)
148
148
  elsif any.is_a?(Symbol)
149
149
  v = bill.vars[any]
150
- raise "Unknown name #{any.inspect} among: #{bill.vars.keys.map(&:inspect).joined}" if v.nil?
150
+ raise(Fbe::Error, "Unknown name #{any.inspect} among: #{bill.vars.keys.map(&:inspect).joined}") if v.nil?
151
151
  v
152
152
  else
153
153
  any
@@ -169,7 +169,7 @@ class Fbe::Award
169
169
  # term = Factbase::Syntax.new('(times x y)').to_term
170
170
  # term.redress!(Fbe::Award::BTerm)
171
171
  # term.calc(bill) #=> 50
172
- def calc(bill)
172
+ def calc(bill) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
173
173
  case @op
174
174
  when :total
175
175
  bill.points
@@ -211,23 +211,23 @@ class Fbe::Award
211
211
  return 0 if (!v.negative? && v < min) || (!v.positive? && v > max)
212
212
  v.clamp(min, max)
213
213
  else
214
- raise "Unknown term '#{@op}'"
214
+ raise(Fbe::Error, "Unknown term '#{@op}'")
215
215
  end
216
216
  end
217
217
  end
218
218
 
219
219
  # A term for bylaw.
220
220
  module PTerm
221
- def to_s
221
+ def to_s # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
222
222
  case @op
223
223
  when :total
224
224
  'total'
225
225
  when :if
226
226
  "if #{to_p(@operands[0])} then #{to_p(@operands[1])} else #{to_p(@operands[2])}"
227
227
  when :and
228
- @operands.map(&:to_s).join(' and ')
228
+ @operands.join(' and ')
229
229
  when :or
230
- @operands.map(&:to_s).join(' or ')
230
+ @operands.join(' or ')
231
231
  when :not
232
232
  "not #{@operands[0]}"
233
233
  when :eq
@@ -255,7 +255,7 @@ class Fbe::Award
255
255
  when :between
256
256
  "at least #{to_p(@operands[0])} and at most #{to_p(@operands[1])}"
257
257
  else
258
- raise "Unknown term '#{@op}'"
258
+ raise(Fbe::Error, "Unknown term '#{@op}'")
259
259
  end
260
260
  end
261
261
 
@@ -273,16 +273,16 @@ class Fbe::Award
273
273
  @operands.each do |o|
274
274
  o.publish_to(bylaw)
275
275
  rescue StandardError => e
276
- raise "Failure in #{o}: #{e.message}"
276
+ raise(Fbe::Error, "Failure in #{o}: #{e.message}")
277
277
  end
278
278
  when :aka
279
279
  @operands[0..-2].each do |o|
280
280
  o.publish_to(bylaw)
281
281
  rescue StandardError => e
282
- raise "Failure in #{o}: #{e.message}"
282
+ raise(Fbe::Error, "Failure in #{o}: #{e.message}")
283
283
  end
284
284
  bylaw.revert(@operands.size - 1)
285
- bylaw.line(to_p(@operands[@operands.size - 1]))
285
+ bylaw.line(to_p(@operands[-1]))
286
286
  when :explain
287
287
  bylaw.intro(to_p(@operands[0]))
288
288
  when :in
@@ -295,7 +295,7 @@ class Fbe::Award
295
295
  when :give
296
296
  bylaw.line("award #{to_p(@operands[0])}")
297
297
  else
298
- raise "Unknown term '#{@op}'"
298
+ raise(Fbe::Error, "Unknown term '#{@op}'")
299
299
  end
300
300
  end
301
301
 
@@ -305,19 +305,8 @@ class Fbe::Award
305
305
  any.to_s
306
306
  when Symbol
307
307
  s = any.to_s
308
- subs = {
309
- 0 => '₀',
310
- 1 => '₁',
311
- 2 => '₂',
312
- 3 => '₃',
313
- 4 => '₄',
314
- 5 => '₅',
315
- 6 => '₆',
316
- 7 => '₇',
317
- 8 => '₈',
318
- 9 => '₉'
319
- }
320
- s.gsub!(/([a-z]+)([0-9])/) { |_| "#{Regexp.last_match[1]}#{subs[Regexp.last_match[2].to_i]}" }
308
+ subs = { 0 => '₀', 1 => '₁', 2 => '₂', 3 => '₃', 4 => '₄', 5 => '₅', 6 => '₆', 7 => '₇', 8 => '₈', 9 => '₉' }
309
+ s.gsub!(/([a-z]+)([0-9])/) { |_| "#{Regexp.last_match[1]}#{subs[Integer(Regexp.last_match[2], 10)]}" }
321
310
  "_#{s.tr('_', '-')}_"
322
311
  when Integer, Float
323
312
  "**#{any}**"
@@ -333,7 +322,6 @@ class Fbe::Award
333
322
  # for each award component. It provides methods to calculate total points
334
323
  # and generate a human-readable summary of the rewards.
335
324
  class Bill
336
- # @return [Hash] Variables set in this bill
337
325
  attr_reader :vars
338
326
 
339
327
  # Creates a new empty bill.
@@ -380,7 +368,7 @@ class Fbe::Award
380
368
  # bill.line(42.5, "for answer")
381
369
  # bill.points #=> 43
382
370
  def points
383
- @lines.sum { |l| l[:v] }.to_f.round.to_i
371
+ Integer(Float(@lines.sum { |l| l[:v] }).round.to_s, 10)
384
372
  end
385
373
 
386
374
  # Generates a human-readable summary of the bill.
@@ -410,7 +398,6 @@ class Fbe::Award
410
398
  # introductions, calculation steps, and variable substitutions.
411
399
  # It produces Markdown-formatted output describing how awards are calculated.
412
400
  class Bylaw
413
- # @return [Hash] Variables defined in this bylaw
414
401
  attr_reader :vars
415
402
 
416
403
  # Creates a new empty bylaw.
data/lib/fbe/bylaws.rb CHANGED
@@ -36,15 +36,15 @@ require_relative '../fbe'
36
36
  # bylaws['dud-was-punished']
37
37
  # # => "award { -16 * anger }"
38
38
  def Fbe.bylaws(anger: 2, love: 2, paranoia: 2)
39
- raise "The 'anger' must be in the [0..4] interval: #{anger.inspect}" unless !anger.negative? && anger < 5
40
- raise "The 'love' must be in the [0..4] interval: #{love.inspect}" unless !love.negative? && love < 5
41
- raise "The 'paranoia' must be in the [1..4] interval: #{paranoia.inspect}" unless paranoia.positive? && paranoia < 5
39
+ raise(Fbe::Error, "The 'anger' must be in the [0..4] interval: #{anger.inspect}") unless !anger.negative? && anger < 5
40
+ raise(Fbe::Error, "The 'love' must be in the [0..4] interval: #{love.inspect}") unless !love.negative? && love < 5
41
+ unless paranoia.positive? && paranoia < 5
42
+ raise(Fbe::Error, "The 'paranoia' must be in the [1..4] interval: #{paranoia.inspect}")
43
+ end
42
44
  home = File.join(__dir__, '../../assets/bylaws')
43
- raise "The directory with templates is absent #{home.inspect}" unless File.exist?(home)
45
+ raise(Fbe::Error, "The directory with templates is absent #{home.inspect}") unless File.exist?(home)
44
46
  Dir[File.join(home, '*.fe.liquid')].to_h do |f|
45
- formula = Liquid::Template.parse(File.read(f)).render(
46
- 'anger' => anger, 'love' => love, 'paranoia' => paranoia
47
- )
47
+ formula = Liquid::Template.parse(File.read(f)).render('anger' => anger, 'love' => love, 'paranoia' => paranoia)
48
48
  [File.basename(f).gsub(/\.fe.liquid$/, ''), formula]
49
49
  end
50
50
  end
data/lib/fbe/conclude.rb CHANGED
@@ -24,11 +24,11 @@ def Fbe.conclude(
24
24
  fb: Fbe.fb, judge: $judge, loog: $loog, options: $options, global: $global,
25
25
  epoch: $epoch || Time.now, kickoff: $kickoff || Time.now, &
26
26
  )
27
- raise 'The fb is nil' if fb.nil?
28
- raise 'The $judge is not set' if judge.nil?
29
- raise 'The $global is not set' if global.nil?
30
- raise 'The $options is not set' if options.nil?
31
- raise 'The $loog is not set' if loog.nil?
27
+ raise(Fbe::Error, 'The fb is nil') if fb.nil?
28
+ raise(Fbe::Error, 'The $judge is not set') if judge.nil?
29
+ raise(Fbe::Error, 'The $global is not set') if global.nil?
30
+ raise(Fbe::Error, 'The $options is not set') if options.nil?
31
+ raise(Fbe::Error, 'The $loog is not set') if loog.nil?
32
32
  c = Fbe::Conclude.new(fb:, judge:, loog:, options:, global:, epoch:, kickoff:)
33
33
  c.instance_eval(&)
34
34
  end
@@ -76,9 +76,9 @@ class Fbe::Conclude
76
76
  @kickoff = kickoff
77
77
  @query = nil
78
78
  @follows = []
79
- @lifetime_aware = true
80
- @timeout_aware = true
81
- @quota_aware = true
79
+ @lifetime = true
80
+ @timeout = true
81
+ @quota = true
82
82
  end
83
83
 
84
84
  # Make this block not aware of GitHub API quota.
@@ -88,7 +88,7 @@ class Fbe::Conclude
88
88
  #
89
89
  # @return [nil] Nothing is returned
90
90
  def quota_unaware
91
- @quota_aware = false
91
+ @quota = false
92
92
  end
93
93
 
94
94
  # Make this block NOT aware of lifetime limitations.
@@ -97,7 +97,7 @@ class Fbe::Conclude
97
97
  #
98
98
  # @return [nil] Nothing is returned
99
99
  def lifetime_unaware
100
- @lifetime_aware = false
100
+ @lifetime = false
101
101
  end
102
102
 
103
103
  # Make this block NOT aware of timeout limitations.
@@ -106,7 +106,7 @@ class Fbe::Conclude
106
106
  #
107
107
  # @return [nil] Nothing is returned
108
108
  def timeout_unaware
109
- @timeout_aware = false
109
+ @timeout = false
110
110
  end
111
111
 
112
112
  # Set the query that should find the facts in the factbase.
@@ -114,7 +114,7 @@ class Fbe::Conclude
114
114
  # @param [String] query The query to execute
115
115
  # @return [nil] Nothing is returned
116
116
  def on(query)
117
- raise 'Query is already set' unless @query.nil?
117
+ raise(Fbe::Error, 'Query is already set') unless @query.nil?
118
118
  @query = query
119
119
  end
120
120
 
@@ -170,7 +170,7 @@ class Fbe::Conclude
170
170
  # @return [Integer] The count of the facts processed
171
171
  def consider(&)
172
172
  roll do |_fbt, a|
173
- yield a
173
+ yield(a)
174
174
  nil
175
175
  end
176
176
  end
@@ -198,16 +198,16 @@ class Fbe::Conclude
198
198
  def roll(&)
199
199
  return 0 if Fbe.over?(
200
200
  global: @global, options: @options, loog: @loog, epoch: @epoch, kickoff: @kickoff,
201
- quota_aware: @quota_aware, lifetime_aware: @lifetime_aware, timeout_aware: @timeout_aware
201
+ quota_aware: @quota, lifetime_aware: @lifetime, timeout_aware: @timeout
202
202
  )
203
203
  passed = 0
204
204
  @fb.query(@query).each do |a|
205
205
  break if Fbe.over?(
206
206
  global: @global, options: @options, loog: @loog, epoch: @epoch, kickoff: @kickoff,
207
- quota_aware: @quota_aware, lifetime_aware: @lifetime_aware, timeout_aware: @timeout_aware
207
+ quota_aware: @quota, lifetime_aware: @lifetime, timeout_aware: @timeout
208
208
  )
209
209
  @fb.txn do |fbt|
210
- n = yield fbt, a
210
+ n = yield(fbt, a)
211
211
  @loog.info("#{n.what}: #{n.details}") unless n.nil?
212
212
  end
213
213
  passed += 1
@@ -242,10 +242,10 @@ class Fbe::Conclude
242
242
  # end
243
243
  def fill(fact, prev)
244
244
  @follows.each do |follow|
245
- v = prev.send(follow)
246
- fact.send(:"#{follow}=", v)
245
+ v = prev.public_send(follow)
246
+ fact.public_send(:"#{follow}=", v)
247
247
  end
248
- r = yield fact, prev
248
+ r = yield(fact, prev)
249
249
  return unless r.is_a?(String)
250
250
  fact.details = r
251
251
  fact.what = @judge
data/lib/fbe/consider.rb CHANGED
@@ -25,7 +25,7 @@ def Fbe.consider(
25
25
  lifetime_aware: true, timeout_aware: true, &
26
26
  )
27
27
  Fbe.conclude(fb:, judge:, loog:, options:, global:, epoch:, kickoff:) do
28
- on query
28
+ on(query)
29
29
  timeout_unaware unless timeout_aware
30
30
  lifetime_unaware unless lifetime_aware
31
31
  consider(&)
data/lib/fbe/copy.rb CHANGED
@@ -24,15 +24,15 @@ require_relative 'fb'
24
24
  # count = Fbe.copy(source, target, except: ['_time', '_id'])
25
25
  # puts "Copied #{count} property values"
26
26
  def Fbe.copy(source, target, except: [])
27
- raise 'The source is nil' if source.nil?
28
- raise 'The target is nil' if target.nil?
29
- raise 'The except is nil' if except.nil?
27
+ raise(Fbe::Error, 'The source is nil') if source.nil?
28
+ raise(Fbe::Error, 'The target is nil') if target.nil?
29
+ raise(Fbe::Error, 'The except is nil') if except.nil?
30
30
  copied = 0
31
31
  source.all_properties.each do |k|
32
32
  next unless target[k].nil?
33
33
  next if except.include?(k)
34
34
  source[k].each do |v|
35
- target.send(:"#{k}=", v)
35
+ target.public_send(:"#{k}=", v)
36
36
  copied += 1
37
37
  end
38
38
  end
data/lib/fbe/delete.rb CHANGED
@@ -23,10 +23,10 @@ require_relative 'fb'
23
23
  # new_fact = Fbe.delete(fact, 'age', 'city')
24
24
  # # new_fact will have all properties except 'age' and 'city'
25
25
  def Fbe.delete(fact, *props, fb: Fbe.fb, id: '_id')
26
- raise 'The fact is nil' if fact.nil?
26
+ raise(Fbe::Error, 'The fact is nil') if fact.nil?
27
27
  return if props.all? { |k| fact[k].nil? }
28
28
  i = fact[id]
29
- raise "There is no #{id.inspect} in the fact" if i.nil?
29
+ raise(Fbe::Error, "There is no #{id.inspect} in the fact") if i.nil?
30
30
  i = i.first
31
31
  before = {}
32
32
  fact.all_properties.each do |k|
@@ -40,7 +40,7 @@ def Fbe.delete(fact, *props, fb: Fbe.fb, id: '_id')
40
40
  before.each do |k, vv|
41
41
  next unless c[k].nil?
42
42
  vv.each do |v|
43
- c.send(:"#{k}=", v)
43
+ c.public_send(:"#{k}=", v)
44
44
  end
45
45
  end
46
46
  end
@@ -19,9 +19,9 @@ require_relative 'fb'
19
19
  # @param [String] id The property name used as unique identifier (defaults to '_id')
20
20
  # @return [nil] Nothing
21
21
  def Fbe.delete_one(fact, prop, value, fb: Fbe.fb, id: '_id')
22
- raise 'The fact is nil' if fact.nil?
22
+ raise(Fbe::Error, 'The fact is nil') if fact.nil?
23
23
  i = fact[id]
24
- raise "There is no #{id.inspect} in the fact" if i.nil?
24
+ raise(Fbe::Error, "There is no #{id.inspect} in the fact") if i.nil?
25
25
  i = i.first
26
26
  before = {}
27
27
  fact.all_properties.each do |k|
@@ -36,7 +36,7 @@ def Fbe.delete_one(fact, prop, value, fb: Fbe.fb, id: '_id')
36
36
  before.each do |k, vv|
37
37
  next unless c[k].nil?
38
38
  vv.each do |v|
39
- c.send(:"#{k}=", v)
39
+ c.public_send(:"#{k}=", v)
40
40
  end
41
41
  end
42
42
  end
data/lib/fbe/enter.rb CHANGED
@@ -26,11 +26,11 @@ require_relative '../fbe'
26
26
  # validate_payment(data)
27
27
  # end
28
28
  def Fbe.enter(badge, why, options: $options, loog: $loog, &)
29
- raise 'The badge is nil' if badge.nil?
30
- raise 'The why is nil' if why.nil?
31
- raise 'The $options is not set' if options.nil?
32
- raise 'The $loog is not set' if loog.nil?
29
+ raise(Fbe::Error, 'The badge is nil') if badge.nil?
30
+ raise(Fbe::Error, 'The why is nil') if why.nil?
31
+ raise(Fbe::Error, 'The $options is not set') if options.nil?
32
+ raise(Fbe::Error, 'The $loog is not set') if loog.nil?
33
33
  return yield unless options.testing.nil?
34
34
  baza = BazaRb.new('api.zerocracy.com', 443, options.zerocracy_token, loog:)
35
- baza.enter(options.job_name, badge, why, options.job_id.to_i, &)
35
+ baza.enter(options.job_name, badge, why, options.job_id.nil? ? 0 : Integer(options.job_id.to_s, 10), &)
36
36
  end
data/lib/fbe/fb.rb CHANGED
@@ -27,10 +27,10 @@ require_relative '../fbe'
27
27
  # @param [Loog] loog The logging facility
28
28
  # @return [Factbase] The global factbase
29
29
  def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog)
30
- raise 'The fb is nil' if fb.nil?
31
- raise 'The $global is not set' if global.nil?
32
- raise 'The $options is not set' if options.nil?
33
- raise 'The $loog is not set' if loog.nil?
30
+ raise(Fbe::Error, 'The fb is nil') if fb.nil?
31
+ raise(Fbe::Error, 'The $global is not set') if global.nil?
32
+ raise(Fbe::Error, 'The $options is not set') if options.nil?
33
+ raise(Fbe::Error, 'The $loog is not set') if loog.nil?
34
34
  global[:fb] ||=
35
35
  begin
36
36
  rules = Dir.glob(File.join(File.join(__dir__, '../../rules'), '*.fe')).map { |f| File.read(f) }
@@ -44,12 +44,8 @@ def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog)
44
44
  max = fbt.query('(max _id)').one
45
45
  f._id = (max.nil? ? 0 : max) + 1
46
46
  f._time = Time.now
47
- f._version = [
48
- Factbase::VERSION,
49
- Judges::VERSION,
50
- options.action_version
51
- ].compact.join('/')
52
- f._job = options.job_id.to_i if options.job_id
47
+ f._version = [Factbase::VERSION, Judges::VERSION, options.action_version].compact.join('/')
48
+ f._job = Integer(options.job_id.to_s, 10) if options.job_id
53
49
  end
54
50
  Factbase::Impatient.new(
55
51
  Factbase::Logged.new(
@@ -29,7 +29,7 @@ end
29
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
30
  # Copyright:: Copyright (c) 2024-2026 Zerocracy
31
31
  # License:: MIT
32
- class Fbe::Graph
32
+ class Fbe::Graph # rubocop:disable Metrics/ClassLength
33
33
  def initialize(token:, host: 'api.github.com')
34
34
  @token = token
35
35
  @host = host
@@ -85,9 +85,9 @@ class Fbe::Graph
85
85
  }
86
86
  GRAPHQL
87
87
  )
88
- result&.to_h&.dig('repository', 'pullRequest', 'reviewThreads', 'nodes')&.select do |thread|
89
- thread['isResolved']
90
- end || []
88
+ nodes = result&.to_h&.dig('repository', 'pullRequest', 'reviewThreads', 'nodes')
89
+ return [] if nodes.nil?
90
+ nodes.select { |thread| thread['isResolved'] }
91
91
  end
92
92
 
93
93
  # Gets the total number of commits in a branch.
@@ -111,11 +111,13 @@ class Fbe::Graph
111
111
  # puts result #=>
112
112
  # [{"owner"=>"zerocracy", "name"=>"fbe", "branch"=>"master", "total_commits"=>754},
113
113
  # {"owner"=>"zerocracy", "name"=>"judges-action", "branch"=>"master", "total_commits"=>2251}]
114
- def total_commits(owner = nil, name = nil, branch = nil, repos: nil)
115
- raise 'Need owner, name and branch or repos' if owner.nil? && name.nil? && branch.nil? && repos.nil?
116
- raise 'Owner, name and branch is required' if (owner.nil? || name.nil? || branch.nil?) && repos.nil?
117
- raise 'Repos list cannot be empty' if owner.nil? && name.nil? && branch.nil? && repos&.empty?
118
- raise 'Need only owner, name and branch or repos' if (!owner.nil? || !name.nil? || !branch.nil?) && !repos.nil?
114
+ def total_commits(owner = nil, name = nil, branch = nil, repos: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
115
+ raise(Fbe::Error, 'Need owner, name and branch or repos') if owner.nil? && name.nil? && branch.nil? && repos.nil?
116
+ raise(Fbe::Error, 'Owner, name and branch is required') if (owner.nil? || name.nil? || branch.nil?) && repos.nil?
117
+ raise(Fbe::Error, 'Repos list cannot be empty') if owner.nil? && name.nil? && branch.nil? && repos&.empty?
118
+ if (!owner.nil? || !name.nil? || !branch.nil?) && !repos.nil?
119
+ raise(Fbe::Error, 'Need only owner, name and branch or repos')
120
+ end
119
121
  repos ||= [[owner, name, branch]]
120
122
  requests =
121
123
  repos.each_with_index.map do |(owner, name, branch), i|
@@ -136,12 +138,12 @@ class Fbe::Graph
136
138
  result = query("{\n#{requests.join("\n")}\n}")
137
139
  if owner && name && branch
138
140
  ref = result.repo_0&.ref
139
- raise "Repository '#{owner}/#{name}' or branch '#{branch}' not found" unless ref&.target&.history
141
+ raise(Fbe::Error, "Repository '#{owner}/#{name}' or branch '#{branch}' not found") unless ref&.target&.history
140
142
  ref.target.history.total_count
141
143
  else
142
144
  repos.each_with_index.map do |(owner, name, branch), i|
143
- ref = result.send(:"repo_#{i}")&.ref
144
- raise "Repository '#{owner}/#{name}' or branch '#{branch}' not found" unless ref&.target&.history
145
+ ref = result.public_send(:"repo_#{i}")&.ref
146
+ raise(Fbe::Error, "Repository '#{owner}/#{name}' or branch '#{branch}' not found") unless ref&.target&.history
145
147
  {
146
148
  'owner' => owner,
147
149
  'name' => name,
@@ -230,7 +232,7 @@ class Fbe::Graph
230
232
  ).to_h
231
233
  return unless result['node']
232
234
  type = result.dig('node', '__typename')
233
- prev_issue_type =
235
+ previous =
234
236
  if type == 'IssueTypeChangedEvent'
235
237
  {
236
238
  'id' => result.dig('node', 'prevIssueType', 'id'),
@@ -246,7 +248,7 @@ class Fbe::Graph
246
248
  'name' => result.dig('node', 'issueType', 'name'),
247
249
  'description' => result.dig('node', 'issueType', 'description')
248
250
  },
249
- 'prev_issue_type' => prev_issue_type,
251
+ 'prev_issue_type' => previous,
250
252
  'actor' => {
251
253
  'login' => result.dig('node', 'actor', 'login'),
252
254
  'type' => result.dig('node', 'actor', '__typename'),
@@ -311,8 +313,8 @@ class Fbe::Graph
311
313
  {
312
314
  'pulls_with_reviews' => result
313
315
  .dig('repository', 'pullRequests', 'nodes')
314
- .reject { _1.dig('timelineItems', 'nodes').empty? }
315
- .map do |pull|
316
+ .filter_map do |pull|
317
+ next if pull.dig('timelineItems', 'nodes').empty?
316
318
  {
317
319
  'id' => pull['id'],
318
320
  'number' => pull['number']
@@ -579,11 +581,7 @@ class Fbe::Graph
579
581
  # fake.resolved_conversations('zerocracy', 'baza', 42)
580
582
  # # => [conversation data for zerocracy_baza]
581
583
  def resolved_conversations(owner, name, _number)
582
- data = {
583
- zerocracy_baza: [
584
- conversation('PRRT_kwDOK2_4A85BHZAR')
585
- ]
586
- }
584
+ data = { zerocracy_baza: [conversation('PRRT_kwDOK2_4A85BHZAR')] }
587
585
  data[:"#{owner}_#{name}"] || []
588
586
  end
589
587
 
@@ -609,11 +607,13 @@ class Fbe::Graph
609
607
  # @param [String] branch Branch name
610
608
  # @param [Array<Array<String, String, String>>] repos List of owner, name, branch
611
609
  # @return [Integer, Array<Hash>] Returns 1484 for single repo or array of hashes
612
- def total_commits(owner = nil, name = nil, branch = nil, repos: nil)
613
- raise 'Need owner, name and branch or repos' if owner.nil? && name.nil? && branch.nil? && repos.nil?
614
- raise 'Owner, name and branch is required' if (owner.nil? || name.nil? || branch.nil?) && repos.nil?
615
- raise 'Repos list cannot be empty' if owner.nil? && name.nil? && branch.nil? && repos&.empty?
616
- raise 'Need only owner, name and branch or repos' if (!owner.nil? || !name.nil? || !branch.nil?) && !repos.nil?
610
+ def total_commits(owner = nil, name = nil, branch = nil, repos: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
611
+ raise(Fbe::Error, 'Need owner, name and branch or repos') if owner.nil? && name.nil? && branch.nil? && repos.nil?
612
+ raise(Fbe::Error, 'Owner, name and branch is required') if (owner.nil? || name.nil? || branch.nil?) && repos.nil?
613
+ raise(Fbe::Error, 'Repos list cannot be empty') if owner.nil? && name.nil? && branch.nil? && repos&.empty?
614
+ if (!owner.nil? || !name.nil? || !branch.nil?) && !repos.nil?
615
+ raise(Fbe::Error, 'Need only owner, name and branch or repos')
616
+ end
617
617
  if owner && name && branch
618
618
  1484
619
619
  else
data/lib/fbe/if_absent.rb CHANGED
@@ -54,14 +54,14 @@ def Fbe.if_absent(fb: Fbe.fb, always: false)
54
54
  if k.end_with?('=')
55
55
  k = k[0..-2].to_sym
56
56
  v = args[1]
57
- raise "Can't set #{k} to nil" if v.nil?
58
- raise "Can't set #{k} to empty string" if v.is_a?(String) && v.empty?
57
+ raise(Fbe::Error, "Can't set #{k} to nil") if v.nil?
58
+ raise(Fbe::Error, "Can't set #{k} to empty string") if v.is_a?(String) && v.empty?
59
59
  @map[k] = v
60
60
  else
61
61
  @map[k.to_sym]
62
62
  end
63
63
  end
64
- yield f
64
+ yield(f)
65
65
  q = attrs.except('_id', '_time', '_version').map do |k, v|
66
66
  vv = v.to_s
67
67
  if v.is_a?(String)
@@ -76,6 +76,6 @@ def Fbe.if_absent(fb: Fbe.fb, always: false)
76
76
  return before if before && always
77
77
  return nil if before
78
78
  n = fb.insert
79
- attrs.each { |k, v| n.send(:"#{k}=", v) }
79
+ attrs.each { |k, v| n.public_send(:"#{k}=", v) }
80
80
  n
81
81
  end
data/lib/fbe/issue.rb CHANGED
@@ -28,15 +28,15 @@ require_relative 'octo'
28
28
  # issue_fact.issue = 42 # Issue number
29
29
  # puts Fbe.issue(issue_fact) # => "zerocracy/fbe#42"
30
30
  def Fbe.issue(fact, options: $options, global: $global, loog: $loog)
31
- raise 'The fact is nil' if fact.nil?
32
- raise 'The $global is not set' if global.nil?
33
- raise 'The $options is not set' if options.nil?
34
- raise 'The $loog is not set' if loog.nil?
31
+ raise(Fbe::Error, 'The fact is nil') if fact.nil?
32
+ raise(Fbe::Error, 'The $global is not set') if global.nil?
33
+ raise(Fbe::Error, 'The $options is not set') if options.nil?
34
+ raise(Fbe::Error, 'The $loog is not set') if loog.nil?
35
35
  rid = fact['repository']
36
- raise "There is no 'repository' property" if rid.nil?
37
- rid = rid.first.to_i
36
+ raise(Fbe::Error, "There is no 'repository' property") if rid.nil?
37
+ rid = Integer(rid.first.to_s, 10)
38
38
  issue = fact['issue']
39
- raise "There is no 'issue' property" if issue.nil?
40
- issue = issue.first.to_i
39
+ raise(Fbe::Error, "There is no 'issue' property") if issue.nil?
40
+ issue = Integer(issue.first.to_s, 10)
41
41
  "#{Fbe.octo(global:, options:, loog:).repo_name_by_id(rid)}##{issue}"
42
42
  end