fbe 0.0.53 → 0.0.55

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: 14aa27f165a2c6a7ca7cdf10127ba4f6f7aa4a84272316c3098a69381f0017c5
4
- data.tar.gz: f6a075f722a9ab583c64ddef3322eac30b3df54804fabb54c63ee6281c0455df
3
+ metadata.gz: 705cf29669f71d490c86421f566b0ec05c61fa1d8352b97d752ea26b8bcbb294
4
+ data.tar.gz: e68fc23391048fac0a41a5b26af5ac85c4a34b3c434845710736d093d7eeb714
5
5
  SHA512:
6
- metadata.gz: 9b712ed154e715c17a54b36b8fd40d163ec176d9f6c7ba7640f4748c92c8de3cb37deb988d513cf4d9a9abb11144513b2cf67aee4a92a15013c8c89ed5fdb8e5
7
- data.tar.gz: af7f077c96b1b1f528254b9ef084c3f71c0d0400cd4c2162e5c2ffa4f30d31abb1f2a78faa23b71e1d2633679cb52e24d4d006d21358fc13c01f5549b08a5514
6
+ metadata.gz: 20ca9dfe05821edf5df55fccc51303fa23598e81dd15361cfb8b8f23db99b399c9e984ed0a1e1e97f43a0ebd048bd0beec5d8f870163cf0cea5c264fc1a505fc
7
+ data.tar.gz: e8fdc7f6988f441cf0d0cb63c52f29a95f17c9681be435eb6c57012403e903e0ce65bd4b60402e802485221f3c7d7ca0cc847d1ba2f40e318af9be82ab989dcc
data/.rubocop.yml CHANGED
@@ -45,9 +45,9 @@ Metrics/BlockLength:
45
45
  Metrics/AbcSize:
46
46
  Enabled: false
47
47
  Metrics/CyclomaticComplexity:
48
- Max: 25
48
+ Enabled: false
49
49
  Metrics/PerceivedComplexity:
50
- Max: 30
50
+ Enabled: false
51
51
  Metrics/ClassLength:
52
52
  Enabled: false
53
53
  Layout/EmptyLineAfterGuardClause:
data/Gemfile CHANGED
@@ -24,7 +24,7 @@ source 'https://rubygems.org'
24
24
  gemspec
25
25
 
26
26
  gem 'graphql-client'
27
- gem 'minitest', '5.25.0', require: false
27
+ gem 'minitest', '5.25.1', require: false
28
28
  gem 'minitest-reporters', '1.7.1', require: false
29
29
  gem 'rake', '13.2.1', require: false
30
30
  gem 'rspec-rails', '6.1.4', require: false
data/Gemfile.lock CHANGED
@@ -141,7 +141,7 @@ GEM
141
141
  crass (~> 1.0.2)
142
142
  nokogiri (>= 1.12.0)
143
143
  loog (0.6.0)
144
- minitest (5.25.0)
144
+ minitest (5.25.1)
145
145
  minitest-reporters (1.7.1)
146
146
  ansi
147
147
  builder
@@ -287,7 +287,7 @@ PLATFORMS
287
287
  DEPENDENCIES
288
288
  fbe!
289
289
  graphql-client
290
- minitest (= 5.25.0)
290
+ minitest (= 5.25.1)
291
291
  minitest-reporters (= 1.7.1)
292
292
  rake (= 13.2.1)
293
293
  rspec-rails (= 6.1.4)
data/lib/fbe/award.rb CHANGED
@@ -300,7 +300,7 @@ class Fbe::Award
300
300
  end
301
301
 
302
302
  def points
303
- @lines.map { |l| l[:v] }.inject(&:+).to_i
303
+ @lines.map { |l| l[:v] }.inject(&:+).to_f.round.to_i
304
304
  end
305
305
 
306
306
  def greeting
data/lib/fbe/conclude.rb CHANGED
@@ -28,6 +28,12 @@ require_relative 'octo'
28
28
  require_relative 'if_absent'
29
29
 
30
30
  # Create a conclude code block.
31
+ #
32
+ # @param [Factbase] fb The factbase
33
+ # @param [String] judge The name of the judge, from the +judges+ tool
34
+ # @param [Hash] global The hash for global caching
35
+ # @param [Judges::Options] options The options coming from the +judges+ tool
36
+ # @param [Loog] logg The logging facility
31
37
  def Fbe.conclude(fb: Fbe.fb, judge: $judge, loog: $loog, options: $options, global: $global, &)
32
38
  c = Fbe::Conclude.new(fb:, judge:, loog:, options:, global:)
33
39
  c.instance_eval(&)
@@ -38,7 +44,14 @@ end
38
44
  # Copyright:: Copyright (c) 2024 Zerocracy
39
45
  # License:: MIT
40
46
  class Fbe::Conclude
41
- def initialize(fb:, judge:, loog:, options:, global:)
47
+ # Ctor.
48
+ #
49
+ # @param [Factbase] fb The factbase
50
+ # @param [String] judge The name of the judge, from the +judges+ tool
51
+ # @param [Hash] global The hash for global caching
52
+ # @param [Judges::Options] options The options coming from the +judges+ tool
53
+ # @param [Loog] logg The logging facility
54
+ def initialize(fb:, judge:, global:, options:, loog:)
42
55
  @fb = fb
43
56
  @judge = judge
44
57
  @loog = loog
@@ -106,7 +119,6 @@ class Fbe::Conclude
106
119
  @follows.each do |follow|
107
120
  v = prev.send(follow)
108
121
  fact.send("#{follow}=", v)
109
- fact.cause = prev._id
110
122
  end
111
123
  r = yield fact, prev
112
124
  return unless r.is_a?(String)
data/lib/fbe/copy.rb CHANGED
@@ -29,11 +29,14 @@ require_relative 'fb'
29
29
  #
30
30
  # @param [Factbase::Fact] source The source
31
31
  # @param [Factbase::Fact] target The targer
32
- def Fbe.copy(source, target)
32
+ # @param [Array<String>] except List of properties to NOT copy
33
+ def Fbe.copy(source, target, except: [])
33
34
  raise 'The source is nil' if source.nil?
34
35
  raise 'The target is nil' if target.nil?
36
+ raise 'The except is nil' if except.nil?
35
37
  source.all_properties.each do |k|
36
38
  next unless target[k].nil?
39
+ next if except.include?(k)
37
40
  source[k].each do |v|
38
41
  target.send(:"#{k}=", v)
39
42
  end
data/lib/fbe/fb.rb CHANGED
@@ -30,6 +30,12 @@ require 'factbase/pre'
30
30
  require 'factbase/rules'
31
31
  require_relative '../fbe'
32
32
 
33
+ # Returns an instance of +Factbase+ (cached).
34
+ #
35
+ # @param [Factbase] fb The global factbase provided by the +judges+ tool
36
+ # @param [Hash] global The hash for global caching
37
+ # @param [Judges::Options] options The options coming from the +judges+ tool
38
+ # @param [Loog] logg The logging facility
33
39
  def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog)
34
40
  global[:fb] ||=
35
41
  begin
data/lib/fbe/issue.rb CHANGED
@@ -24,6 +24,18 @@
24
24
 
25
25
  require_relative '../fbe'
26
26
 
27
+ # Converts an ID of GitHub issue into a nicely formatting string.
28
+ #
29
+ # @param [Factbase::Fact] fact The fact, where to get the ID of GitHub issue
30
+ # @param [Judges::Options] options The options coming from the +judges+ tool
31
+ # @param [Hash] global The hash for global caching
32
+ # @param [Loog] logg The logging facility
27
33
  def Fbe.issue(fact, options: $options, global: $global, loog: $loog)
28
- "#{Fbe.octo(global:, options:, loog:).repo_name_by_id(fact.repository)}##{fact.issue}"
34
+ rid = fact['repository']
35
+ raise "There is no 'repository' property" if rid.nil?
36
+ rid = rid.first.to_i
37
+ issue = fact['issue']
38
+ raise "There is no 'issue' property" if issue.nil?
39
+ issue = issue.first.to_i
40
+ "#{Fbe.octo(global:, options:, loog:).repo_name_by_id(rid)}##{issue}"
29
41
  end
data/lib/fbe/octo.rb CHANGED
@@ -498,6 +498,206 @@ class Fbe::FakeOctokit
498
498
  },
499
499
  created_at: random_time,
500
500
  public: true
501
+ },
502
+ {
503
+ id: 42,
504
+ created_at: Time.now,
505
+ actor: { id: 42 },
506
+ type: 'PullRequestEvent',
507
+ repo: { id: repo },
508
+ payload: {
509
+ action: 'closed',
510
+ number: 172,
511
+ ref_type: 'tag',
512
+ ref: 'foo',
513
+ pull_request: {
514
+ url: 'https://api.github.com/repos/yegor256/judges/pulls/93',
515
+ id: 1_990_323_142,
516
+ node_id: 'PR_kwDOL6GCO852oevG',
517
+ number: 172,
518
+ state: 'closed',
519
+ locked: false,
520
+ title: '#999 new feature',
521
+ user: {
522
+ login: 'test',
523
+ id: 88_084_038,
524
+ node_id: 'MDQ6VXNlcjE2NDYwMjA=',
525
+ type: 'User',
526
+ site_admin: false
527
+ },
528
+ base: {
529
+ label: 'zerocracy:master',
530
+ ref: 'master',
531
+ user: {
532
+ login: 'zerocracy',
533
+ id: 24_234_201
534
+ },
535
+ repo: {
536
+ id: repo,
537
+ node_id: 'R_kgDOK2_4Aw',
538
+ name: 'baza',
539
+ full_name: 'zerocracy/baza',
540
+ private: false
541
+ }
542
+ },
543
+ head: {
544
+ ref: 'zerocracy/baza'
545
+ },
546
+ merged_at: Time.now,
547
+ comments: 2,
548
+ review_comments: 2,
549
+ commits: 1,
550
+ additions: 3,
551
+ deletions: 3,
552
+ changed_files: 2
553
+ }
554
+ }
555
+ }
556
+ ]
557
+ end
558
+
559
+ def pull_request_comments(_name, _number)
560
+ [
561
+ {
562
+ pull_request_review_id: 2_227_372_510,
563
+ id: 1_709_082_318,
564
+ path: 'test/baza/test_locks.rb',
565
+ commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847',
566
+ original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c',
567
+ user: {
568
+ login: 'Reviewer',
569
+ id: 2_566_462
570
+ },
571
+ body: 'Most likely, parentheses were missed here.',
572
+ created_at: '2024-08-08T09:41:46Z',
573
+ updated_at: '2024-08-08T09:42:46Z',
574
+ reactions: {
575
+ url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082318/reactions',
576
+ total_count: 0
577
+ },
578
+ start_line: 'null',
579
+ original_start_line: 'null',
580
+ start_side: 'null',
581
+ line: 'null',
582
+ original_line: 62,
583
+ side: 'RIGHT',
584
+ original_position: 25,
585
+ position: 'null',
586
+ subject_type: 'line'
587
+ },
588
+ {
589
+ pull_request_review_id: 2_227_372_510,
590
+ id: 1_709_082_319,
591
+ path: 'test/baza/test_locks.rb',
592
+ commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847',
593
+ original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c',
594
+ user: {
595
+ login: 'test',
596
+ id: 88_084_038
597
+ },
598
+ body: 'definitely a typo',
599
+ created_at: '2024-08-08T09:42:46Z',
600
+ updated_at: '2024-08-08T09:42:46Z',
601
+ reactions: {
602
+ url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082319/reactions',
603
+ total_count: 0
604
+ },
605
+ start_line: 'null',
606
+ original_start_line: 'null',
607
+ start_side: 'null',
608
+ line: 'null',
609
+ original_line: 62,
610
+ side: 'RIGHT',
611
+ original_position: 25,
612
+ in_reply_to_id: 1_709_082_318,
613
+ position: 'null',
614
+ subject_type: 'line'
615
+ }
616
+ ]
617
+ end
618
+
619
+ def issue_comments(_name, _number)
620
+ [
621
+ {
622
+ pull_request_review_id: 2_227_372_510,
623
+ id: 1_709_082_320,
624
+ path: 'test/baza/test_locks.rb',
625
+ commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847',
626
+ original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c',
627
+ user: {
628
+ login: 'Reviewer',
629
+ id: 2_566_462
630
+ },
631
+ body: 'reviewer comment',
632
+ created_at: '2024-08-08T09:41:46Z',
633
+ updated_at: '2024-08-08T09:42:46Z',
634
+ reactions: {
635
+ url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082320/reactions',
636
+ total_count: 1
637
+ },
638
+ start_line: 'null',
639
+ original_start_line: 'null',
640
+ start_side: 'null',
641
+ line: 'null',
642
+ original_line: 62,
643
+ side: 'RIGHT',
644
+ original_position: 25,
645
+ position: 'null',
646
+ subject_type: 'line'
647
+ },
648
+ {
649
+ pull_request_review_id: 2_227_372_510,
650
+ id: 1_709_082_321,
651
+ path: 'test/baza/test_locks.rb',
652
+ commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847',
653
+ original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c',
654
+ user: {
655
+ login: 'test',
656
+ id: 88_084_038
657
+ },
658
+ body: 'author comment',
659
+ created_at: '2024-08-08T09:42:46Z',
660
+ updated_at: '2024-08-08T09:42:46Z',
661
+ reactions: {
662
+ url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082321/reactions',
663
+ total_count: 1
664
+ },
665
+ start_line: 'null',
666
+ original_start_line: 'null',
667
+ start_side: 'null',
668
+ line: 'null',
669
+ original_line: 62,
670
+ side: 'RIGHT',
671
+ original_position: 25,
672
+ in_reply_to_id: 1_709_082_318,
673
+ position: 'null',
674
+ subject_type: 'line'
675
+ }
676
+ ]
677
+ end
678
+
679
+ def issue_comment_reactions(_name, _comment)
680
+ [
681
+ {
682
+ id: 248_923_574,
683
+ user: {
684
+ login: 'user',
685
+ id: 8_086_956
686
+ },
687
+ content: 'heart'
688
+ }
689
+ ]
690
+ end
691
+
692
+ def pull_request_review_comment_reactions(_name, _comment)
693
+ [
694
+ {
695
+ id: 248_923_574,
696
+ user: {
697
+ login: 'user',
698
+ id: 8_086_956
699
+ },
700
+ content: 'heart'
501
701
  }
502
702
  ]
503
703
  end
data/lib/fbe/pmp.rb CHANGED
@@ -24,10 +24,14 @@
24
24
 
25
25
  require 'others'
26
26
  require_relative 'fb'
27
+ require_relative '../fbe'
27
28
 
28
- # Project management functions.
29
- module Fbe; end
30
-
29
+ # Get configuration parameter from the "PMP" fact.
30
+ #
31
+ # @param [Factbase] fb The factbase
32
+ # @param [Hash] global The hash for global caching
33
+ # @param [Judges::Options] options The options coming from the +judges+ tool
34
+ # @param [Loog] logg The logging facility
31
35
  def Fbe.pmp(fb: Fbe.fb, global: $global, options: $options, loog: $loog)
32
36
  others do |*args1|
33
37
  area = args1.first
data/lib/fbe/regularly.rb CHANGED
@@ -25,6 +25,14 @@
25
25
  require_relative '../fbe'
26
26
  require_relative 'fb'
27
27
 
28
+ # Run the block provided every X days.
29
+ #
30
+ # @param [String] area The name of the PMP area
31
+ # @param [Integer] p_every_days How frequently to run, every X days
32
+ # @param [Integer] p_since_days Since when to collect stats, X days
33
+ # @param [Factbase] fb The factbase
34
+ # @param [String] judge The name of the judge, from the +judges+ tool
35
+ # @param [Loog] logg The logging facility
28
36
  def Fbe.regularly(area, p_every_days, p_since_days = nil, fb: Fbe.fb, judge: $judge, loog: $loog, &)
29
37
  pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{p_every_days}))").each.to_a.first
30
38
  interval = pmp.nil? ? 7 : pmp[p_every_days].first
@@ -30,6 +30,9 @@ require_relative 'overwrite'
30
30
  #
31
31
  # @param [String] area The name of the PMP area
32
32
  # @param [Integer] p_every_hours How frequently to run, every X hours
33
+ # @param [Factbase] fb The factbase
34
+ # @param [String] judge The name of the judge, from the +judges+ tool
35
+ # @param [Loog] logg The logging facility
33
36
  def Fbe.repeatedly(area, p_every_hours, fb: Fbe.fb, judge: $judge, loog: $loog, &)
34
37
  pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{p_every_hours}))").each.to_a.first
35
38
  hours = pmp.nil? ? 24 : pmp[p_every_hours].first
data/lib/fbe/sec.rb CHANGED
@@ -24,8 +24,14 @@
24
24
 
25
25
  require_relative '../fbe'
26
26
 
27
+ # Converts number of seconds into text.
28
+ #
29
+ # @param [Factbase::Fact] fact The fact, where to get the number of seconds
30
+ # @param [String] prop The property in the fact, with the seconds
27
31
  def Fbe.sec(fact, prop = :seconds)
28
- s = fact.send(prop.to_s)
32
+ s = fact[prop.to_s]
33
+ raise "There is no #{prop} property" if s.nil?
34
+ s = s.first.to_i
29
35
  if s < 60
30
36
  format('%d seconds', s)
31
37
  elsif s < 60 * 60
data/lib/fbe/who.rb CHANGED
@@ -24,6 +24,16 @@
24
24
 
25
25
  require_relative '../fbe'
26
26
 
27
+ # Converts an ID of GitHub user into a nicely formatting string with his name.
28
+ #
29
+ # @param [Factbase::Fact] fact The fact, where to get the ID of GitHub user
30
+ # @param [String] prop The property in the fact, with the ID
31
+ # @param [Judges::Options] options The options coming from the +judges+ tool
32
+ # @param [Hash] global The hash for global caching
33
+ # @param [Loog] logg The logging facility
27
34
  def Fbe.who(fact, prop = :who, options: $options, global: $global, loog: $loog)
28
- "@#{Fbe.octo(options:, global:, loog:).user_name_by_id(fact.send(prop.to_s))}"
35
+ id = fact[prop.to_s]
36
+ raise "There is no #{prop} property" if id.nil?
37
+ id = id.first.to_i
38
+ "@#{Fbe.octo(options:, global:, loog:).user_name_by_id(id)}"
29
39
  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.53'
30
+ VERSION = '0.0.55'
31
31
  end
@@ -96,6 +96,7 @@ class TestAward < Minitest::Test
96
96
 
97
97
  def test_some_greetings
98
98
  {
99
+ '(award (give (times 7 0.25 "fun")))' => 'You\'ve earned +2 points. ',
99
100
  '(award (give (times 5 0.25 "fun")))' => 'You\'ve earned +1 points. ',
100
101
  '(award (give 25 "for being a good boy"))' => 'You\'ve earned +25 points. ',
101
102
  '(award (let x 0.1) (set b (times x 14)) (give b "fun"))' => 'You\'ve earned +1 points. '
@@ -43,4 +43,15 @@ class TestCopy < Minitest::Test
43
43
  assert_equal(2, f2._id)
44
44
  assert_equal(42, f2.foo)
45
45
  end
46
+
47
+ def test_with_except
48
+ fb = Factbase.new
49
+ f1 = fb.insert
50
+ f1._id = 1
51
+ f1.foo = 42
52
+ f2 = fb.insert
53
+ f2._id = 2
54
+ Fbe.copy(f1, f2, except: ['foo'])
55
+ assert(f2['foo'].nil?)
56
+ end
46
57
  end
@@ -160,6 +160,6 @@ class TestOcto < Minitest::Test
160
160
  assert(!o.off_quota) if n > 100
161
161
  limit -= 1
162
162
  end
163
- assert_in_delta(pause, Time.now - start_time, 0.4)
163
+ assert_in_delta(pause, Time.now - start_time, 1)
164
164
  end
165
165
  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.53
4
+ version: 0.0.55
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-08-16 00:00:00.000000000 Z
11
+ date: 2024-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace