fbe 0.0.22 → 0.0.24

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: '0049f50b79fc11504fa48a1b8bf6f3245ec73673068254b639a342996467d3ae'
4
- data.tar.gz: dae993c649a54a5e8a653d4a55128482d1350bbf07a9942cc5bce674a92f85b8
3
+ metadata.gz: 37b5cbcd563d2e31074d5f6625d32fd118a5302a4bcd021492639573e657b03e
4
+ data.tar.gz: 1045c3932e3952740ed611c42e0ed034de522281496cb7a5bc9953b1aa821eef
5
5
  SHA512:
6
- metadata.gz: b0b56a583dc6236fe4539192b10954cb5d16c3acad9f9193de6ed0d77fb14caab012fda9dbf25bfb416cd88ae601cdc710d28312f454ea93cb3144ee75cb3114
7
- data.tar.gz: 1393af02f45e78b354d0bba98706427bba9c769ffa39f029973ef209e85b401ac9d021421af08ab9f5a3f997e51ce8b4f0861ca0ba42b2a184645671ae56143f
6
+ metadata.gz: 4fb03336064109e32074c267d9a21520e1e24e5b4ced00ab38f06df2b6f6d80f9d9c4cb899fb2e35cf3706d78f2d24b99351e6a096b0eafe00aced686b7bda31
7
+ data.tar.gz: 898b56d6e5ad162e52fa457582014106d9155499a10d5b8b5448f41bf8dc094cf16df3d2ef13d9601eec606b0293ca3f276fd750897069e0a1f4c383d26d1cc6
data/Gemfile CHANGED
@@ -32,4 +32,5 @@ gem 'rubocop-performance', '1.21.1', require: false
32
32
  gem 'rubocop-rspec', '3.0.3', require: false
33
33
  gem 'simplecov', '0.22.0', require: false
34
34
  gem 'simplecov-cobertura', '2.1.0', require: false
35
+ gem 'webmock', '3.23.1', require: false
35
36
  gem 'yard', '0.9.36', require: false
data/Gemfile.lock CHANGED
@@ -55,6 +55,9 @@ GEM
55
55
  builder (3.3.0)
56
56
  concurrent-ruby (1.3.3)
57
57
  connection_pool (2.4.1)
58
+ crack (1.0.0)
59
+ bigdecimal
60
+ rexml
58
61
  crass (1.0.6)
59
62
  decoor (0.0.1)
60
63
  diff-lcs (1.5.1)
@@ -87,7 +90,8 @@ GEM
87
90
  ffi (1.17.0-x64-mingw-ucrt)
88
91
  ffi (1.17.0-x86_64-darwin)
89
92
  ffi (1.17.0-x86_64-linux-gnu)
90
- gli (2.21.3)
93
+ gli (2.21.5)
94
+ hashdiff (1.1.0)
91
95
  i18n (1.14.5)
92
96
  concurrent-ruby (~> 1.0)
93
97
  io-console (0.7.2)
@@ -241,6 +245,10 @@ GEM
241
245
  verbose (0.0.2)
242
246
  loog (~> 0.2)
243
247
  tago (~> 0.0)
248
+ webmock (3.23.1)
249
+ addressable (>= 2.8.0)
250
+ crack (>= 0.3.2)
251
+ hashdiff (>= 0.4.0, < 2.0.0)
244
252
  webrick (1.8.1)
245
253
  yaml (0.3.0)
246
254
  yard (0.9.36)
@@ -263,6 +271,7 @@ DEPENDENCIES
263
271
  rubocop-rspec (= 3.0.3)
264
272
  simplecov (= 0.22.0)
265
273
  simplecov-cobertura (= 2.1.0)
274
+ webmock (= 3.23.1)
266
275
  yard (= 0.9.36)
267
276
 
268
277
  BUNDLED WITH
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # FactBase Extended
1
+ # FactBase Extended (FBE)
2
2
 
3
3
  [![DevOps By Rultor.com](http://www.rultor.com/b/zerocracy/fbe)](http://www.rultor.com/p/zerocracy/fbe)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
@@ -13,12 +13,14 @@
13
13
 
14
14
  It's a collection of tools for
15
15
  [zerocracy/judges-action](https://github.com/zerocracy/judges-action).
16
+ You are not supposed to use it directly, but only in a combination
17
+ with other tools of Zerocracy.
16
18
 
17
19
  ## How to contribute
18
20
 
19
21
  Read
20
22
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
21
- Make sure you build is green before you contribute
23
+ Make sure your build is green before you contribute
22
24
  your pull request. You will need to have
23
25
  [Ruby](https://www.ruby-lang.org/en/) 3.2+ and
24
26
  [Bundler](https://bundler.io/) installed. Then:
data/lib/fbe/award.rb CHANGED
@@ -24,7 +24,25 @@
24
24
 
25
25
  require 'factbase/syntax'
26
26
 
27
- # Award generator.
27
+ # A generator of awards.
28
+ #
29
+ # First, you should create a policy, using the same Lisp-ish syntax as
30
+ # we use in queries to a Factbase, for example:
31
+ #
32
+ # require 'fbe/award'
33
+ # a = Fbe::Award.new('(award (in loc "lines") (give (times loc 5) "for LoC"))')
34
+ #
35
+ # Then, you can either get a bill from it:
36
+ #
37
+ # b = a.bill(loc: 345)
38
+ # puts b.points # how many points to reward, a number
39
+ # puts b.greeting # how to explain the reward, a text
40
+ #
41
+ # Or else, you can get a policy text:
42
+ #
43
+ # p = a.policy
44
+ # puts p.markdown # Markdown of the policy
45
+ #
28
46
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
47
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
48
  # License:: MIT
@@ -266,7 +284,14 @@ class Fbe::Award
266
284
 
267
285
  def greeting
268
286
  items = @lines.map { |l| "#{format('%+d', l[:v])} #{l[:t]}" }
269
- "You've earned #{format('%+d', points)} points for this: #{items.join('; ')}. "
287
+ case items.size
288
+ when 0
289
+ "You've earned nothing. "
290
+ when 1
291
+ "You've earned #{format('%+d', points)} points. "
292
+ else
293
+ "You've earned #{format('%+d', points)} points for this: #{items.join('; ')}. "
294
+ end
270
295
  end
271
296
  end
272
297
 
@@ -289,7 +314,7 @@ class Fbe::Award
289
314
  end
290
315
 
291
316
  def line(line)
292
- line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| @lets[Regexp.last_match[1].to_sym] }
317
+ line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" }
293
318
  @lines << line
294
319
  end
295
320
 
data/lib/fbe/octo.rb CHANGED
@@ -57,9 +57,14 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
57
57
  }
58
58
  }
59
59
  stack = Faraday::RackBuilder.new do |builder|
60
- builder.use(Faraday::Retry::Middleware)
61
- builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false)
60
+ builder.use(
61
+ Faraday::Retry::Middleware,
62
+ exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::TooManyRequests],
63
+ max: 5, interval: 1
64
+ )
65
+ builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false, logger: Loog::NULL)
62
66
  builder.use(Octokit::Response::RaiseError)
67
+ builder.use(Faraday::Response::Logger, Loog::NULL)
63
68
  builder.adapter(Faraday.default_adapter)
64
69
  end
65
70
  o.middleware = stack
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.22'
30
+ VERSION = '0.0.24'
31
31
  end
@@ -92,10 +92,20 @@ class TestAward < Minitest::Test
92
92
  '(award (let x_a 25) (set z (plus x_a 1)) (give z "..."))' =>
93
93
  'First, let _x-a_ be equal to **25**. Then, set _z_ to _x-a_ + **1**, and award _z_.',
94
94
  '(award (aka (let x 17) (give x "hey") "add ${x} when necessary"))' =>
95
- 'Just add 17 when necessary'
95
+ 'Just add **17** when necessary'
96
96
  }.each do |q, t|
97
97
  md = Fbe::Award.new(q).policy.markdown
98
98
  assert(md.include?(t), md)
99
99
  end
100
100
  end
101
+
102
+ def test_shorten_when_one_number
103
+ g = Fbe::Award.new('(award (give 23 "for love"))').bill.greeting
104
+ assert_equal('You\'ve earned +23 points. ', g, g)
105
+ end
106
+
107
+ def test_shorten_when_nothing
108
+ g = Fbe::Award.new('(award (give 0 "for none"))').bill.greeting
109
+ assert_equal('You\'ve earned nothing. ', g, g)
110
+ end
101
111
  end
@@ -24,6 +24,7 @@
24
24
 
25
25
  require 'minitest/autorun'
26
26
  require 'judges/options'
27
+ require 'webmock/minitest'
27
28
  require 'loog'
28
29
  require_relative '../test__helper'
29
30
  require_relative '../../lib/fbe/octo'
@@ -54,8 +55,34 @@ class TestOcto < Minitest::Test
54
55
  assert_equal(100, o.rate_limit.remaining)
55
56
  end
56
57
 
58
+ def test_caching
59
+ WebMock.disable_net_connect!
60
+ global = {}
61
+ o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
62
+ stub_request(:get, 'https://api.github.com/users/yegor256')
63
+ .to_return(status: 200, body: '{}', headers: { 'Cache-Control' => 'public, max-age=60', 'etag' => 'abc' })
64
+ .times(1)
65
+ .then
66
+ .to_raise('second request should be cached, not passed to GitHub API!')
67
+ o.user('yegor256')
68
+ o.user('yegor256')
69
+ end
70
+
71
+ def test_retrying
72
+ WebMock.disable_net_connect!
73
+ global = {}
74
+ o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
75
+ stub_request(:get, 'https://api.github.com/users/yegor256')
76
+ .to_raise(Octokit::TooManyRequests.new)
77
+ .times(1)
78
+ .then
79
+ .to_return(status: 200, body: '{}')
80
+ o.user('yegor256')
81
+ end
82
+
57
83
  def test_with_broken_token
58
84
  skip # it's a "live" test, run it manually if you need it
85
+ WebMock.enable_net_connect!
59
86
  global = {}
60
87
  options = Judges::Options.new({ 'github_token' => 'incorrect-value' })
61
88
  o = Fbe.octo(loog: Loog::NULL, global:, options:)
@@ -64,6 +91,7 @@ class TestOcto < Minitest::Test
64
91
 
65
92
  def test_commit_pulls
66
93
  skip # it's a "live" test, run it manually if you need it
94
+ WebMock.enable_net_connect!
67
95
  o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
68
96
  assert_equal(1, o.commit_pulls('zerocracy/fbe', '0b7d0699bd744b62c0731064c2adaad0c58e1416').size)
69
97
  assert_equal(0, o.commit_pulls('zerocracy/fbe', '16b3ea6b71c6e932ba7666c40ca846ecaa6d6f0d').size)
data/test/test__helper.rb CHANGED
@@ -22,6 +22,9 @@
22
22
 
23
23
  $stdout.sync = true
24
24
 
25
+ require 'minitest/reporters'
26
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
27
+
25
28
  require 'simplecov'
26
29
  SimpleCov.start
27
30
 
@@ -29,6 +32,3 @@ require 'simplecov-cobertura'
29
32
  SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
30
33
 
31
34
  require 'minitest/autorun'
32
-
33
- require 'minitest/reporters'
34
- Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
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.22
4
+ version: 0.0.24
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-19 00:00:00.000000000 Z
11
+ date: 2024-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace