Skip to content

Commit

Permalink
#61 fbe up
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 6, 2024
1 parent 0b52221 commit ceec59d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/zerocracy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: zerocracy/judges-action@master
- uses: zerocracy/judges-action@0.0.10
with:
token: ${{ secrets.ZEROCRACY_TOKEN }}
verbose: true
Expand All @@ -46,7 +46,7 @@ jobs:
repositories=yegor256/judges,yegor256/factbase,zerocracy/judges-action,zerocracy/pages-action,zerocracy/baza
factbase: zerocracy.fb
cycles: 2
- uses: zerocracy/pages-action@0.0.15
- uses: zerocracy/pages-action@0.0.16
with:
options: |
token=${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ GEM
net-http
faraday-retry (2.2.1)
faraday (~> 2.0)
fbe (0.0.8)
fbe (0.0.9)
backtrace (~> 0.3)
decoor (~> 0.0)
factbase (~> 0.0)
Expand Down
42 changes: 42 additions & 0 deletions judges/aaa-030-set-pmp-defaults/aaa-030-set-pmp-defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fbe/fb'

{
hr: {
days_to_reward: 7,
days_of_running_balance: 28
}
}.each do |area, props|
f = Fbe.fb.query("(and (eq what 'pmp') (eq area '#{area}'))").each.to_a.first
if f.nil?
f = Fbe.fb.insert
f.what = 'pmp'
f.area = area.to_s
end
props.each do |k, v|
f.send("#{k}=", v) if f[k].nil?
end
end
26 changes: 26 additions & 0 deletions judges/aaa-030-set-pmp-defaults/set-hr-defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
input: []
expected:
- /fb[count(f)=1]
- /fb/f[what='pmp' and area='hr' and days_to_reward='7']
2 changes: 1 addition & 1 deletion judges/github-events/github-events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def self.fill_up_event(fact, json)
break
end
Fbe.fb.txn do |fbt|
f = Fbe.if_absent(fbt) do |n|
f = Fbe.if_absent(fb: fbt) do |n|
n.where = 'github'
n.event_id = json[:id].to_i
end
Expand Down
2 changes: 1 addition & 1 deletion judges/label-was-attached/label-was-attached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
next unless te[:event] == 'labeled'
badge = te[:label][:name]
next unless %w[bug enhancement question].include?(badge)
nn = Fbe.if_absent(Fbe.fb) do |n|
nn = Fbe.if_absent do |n|
n.where = 'github'
n.repository = repository
n.issue = issue
Expand Down
28 changes: 6 additions & 22 deletions lib/pmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,16 @@
# Project management functions.
module J; end

def J.pmp
defaults = {
hr: {
days_to_reward: 7,
days_of_running_balance: 28
}
}
def J.pmp(fb: Fbe.fb, global: $global, options: $options)
others do |*args1|
area = args1.first
d = defaults[area]
raise "Unknown area 'pmp.#{area}'" if d.nil?
others do |*args2|
param = args2.first
d = d[param]
raise "Unknown parameter 'pmp.#{area}.#{param}'" if d.nil?
f = Fbe.fb.query("(and (eq what 'pmp') (eq area '#{area}'))").each.to_a.first
if f.nil?
d
else
r = f[param]
if r.nil?
d
else
r.first
end
end
f = Fbe.fb(global:, fb:, options:).query("(and (eq what 'pmp') (eq area '#{area}'))").each.to_a.first
raise "Unknown area '#{area}'" if f.nil?
r = f[param]
raise "Unknown '#{param}' in '#{area}' area" if r.nil?
r.first
end
end
end
11 changes: 8 additions & 3 deletions test/test_pmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

require 'minitest/autorun'
require 'factbase'
require 'judges/options'
require_relative '../lib/pmp'

# Test.
Expand All @@ -34,12 +35,16 @@ class TestPmp < Minitest::Test
def test_defaults
$fb = Factbase.new
$global = {}
assert_equal(7, J.pmp.hr.days_to_reward)
$options = Judges::Options.new
f = Fbe.fb.insert
f.what = 'pmp'
f.area = 'hr'
f.days_to_reward = 55
assert_equal(55, J.pmp.hr.days_to_reward)
end

def test_fail_on_wrong_area
$fb = Factbase.new
$global = {}
assert_raises { J.pmp.something }
assert_raises { J.pmp(Factbase.new).something }
end
end

0 comments on commit ceec59d

Please sign in to comment.