fbe 0.0.67 → 0.0.69
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.
- checksums.yaml +4 -4
- data/.rultor.yml +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/lib/fbe/github_graph.rb +28 -0
- data/lib/fbe/middleware/logging_formatter.rb +63 -0
- data/lib/fbe/octo.rb +13 -2
- data/lib/fbe.rb +1 -1
- data/test/fbe/middleware/test_logging_formatter.rb +99 -0
- data/test/fbe/test_github_graph.rb +9 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a538e70cd251261fa8b1a980051cfd90195c79e291cbcc08431ae3a78481b5e7
|
4
|
+
data.tar.gz: 7492622c36dedef8fa2582cd47ecacf4006dec00244b28b0f8832ca68eb81bc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d4c8417052d583b4a83177771c75c7cee4567a2e56f3522d6bd34cd81eeeafaa7328f38d251345023dbaca9b76fcc3cdda9b0252bb1ff8a5edee6702c49eb09
|
7
|
+
data.tar.gz: ef57a016e97e85e12da1426a97557f0d54d059b34fcfc07246e82124141726d9e82326f4d86bdea3394337823b35b48568652be0ad0c5a175b854bc243497da9
|
data/.rultor.yml
CHANGED
data/Gemfile
CHANGED
@@ -29,7 +29,7 @@ gem 'minitest-reporters', '1.7.1', require: false
|
|
29
29
|
gem 'rake', '13.2.1', require: false
|
30
30
|
gem 'rspec-rails', '7.0.1', require: false
|
31
31
|
gem 'rubocop', '1.66.1', require: false
|
32
|
-
gem 'rubocop-performance', '1.22.
|
32
|
+
gem 'rubocop-performance', '1.22.1', require: false
|
33
33
|
gem 'rubocop-rspec', '3.0.5', require: false
|
34
34
|
gem 'simplecov', '0.22.0', require: false
|
35
35
|
gem 'simplecov-cobertura', '2.1.0', require: false
|
data/Gemfile.lock
CHANGED
@@ -240,7 +240,7 @@ GEM
|
|
240
240
|
unicode-display_width (>= 2.4.0, < 3.0)
|
241
241
|
rubocop-ast (1.32.3)
|
242
242
|
parser (>= 3.3.1.0)
|
243
|
-
rubocop-performance (1.22.
|
243
|
+
rubocop-performance (1.22.1)
|
244
244
|
rubocop (>= 1.48.1, < 2.0)
|
245
245
|
rubocop-ast (>= 1.31.1, < 2.0)
|
246
246
|
rubocop-rspec (3.0.5)
|
@@ -297,7 +297,7 @@ DEPENDENCIES
|
|
297
297
|
rake (= 13.2.1)
|
298
298
|
rspec-rails (= 7.0.1)
|
299
299
|
rubocop (= 1.66.1)
|
300
|
-
rubocop-performance (= 1.22.
|
300
|
+
rubocop-performance (= 1.22.1)
|
301
301
|
rubocop-rspec (= 3.0.5)
|
302
302
|
simplecov (= 0.22.0)
|
303
303
|
simplecov-cobertura (= 2.1.0)
|
data/lib/fbe/github_graph.rb
CHANGED
@@ -108,6 +108,27 @@ class Fbe::Graph
|
|
108
108
|
result.repository.ref.target.history.total_count
|
109
109
|
end
|
110
110
|
|
111
|
+
def total_issues_and_pulls(owner, name)
|
112
|
+
result = query(
|
113
|
+
<<~GRAPHQL
|
114
|
+
{
|
115
|
+
repository(owner: "#{owner}", name: "#{name}") {
|
116
|
+
issues {
|
117
|
+
totalCount
|
118
|
+
}
|
119
|
+
pullRequests {
|
120
|
+
totalCount
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
GRAPHQL
|
125
|
+
).to_h
|
126
|
+
{
|
127
|
+
'issues' => result.dig('repository', 'issues', 'totalCount') || 0,
|
128
|
+
'pulls' => result.dig('repository', 'pullRequests', 'totalCount') || 0
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
111
132
|
# The HTTP class
|
112
133
|
class HTTP < GraphQL::Client::HTTP
|
113
134
|
def initialize(token, host)
|
@@ -135,6 +156,13 @@ class Fbe::Graph
|
|
135
156
|
data[:"#{owner}_#{name}"] || []
|
136
157
|
end
|
137
158
|
|
159
|
+
def total_issues_and_pulls(_owner, _name)
|
160
|
+
{
|
161
|
+
'issues' => 23,
|
162
|
+
'pulls' => 19
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
138
166
|
private
|
139
167
|
|
140
168
|
def conversation(id)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# MIT License
|
4
|
+
#
|
5
|
+
# Copyright (c) 2024 Zerocracy
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'faraday'
|
26
|
+
|
27
|
+
# Faraday logging formatter show verbose log for only error response
|
28
|
+
class Fbe::Middleware::LoggingFormatter < Faraday::Logging::Formatter
|
29
|
+
AUTHORIZATION_FILTER = [/(Authorization: )([^&]+)([^&]{5})/, '\1********\3'].freeze
|
30
|
+
|
31
|
+
def initialize(**)
|
32
|
+
super
|
33
|
+
filter(*AUTHORIZATION_FILTER)
|
34
|
+
end
|
35
|
+
|
36
|
+
def request(env)
|
37
|
+
super unless log_only_errors?
|
38
|
+
end
|
39
|
+
|
40
|
+
def response(env)
|
41
|
+
return super unless log_only_errors?
|
42
|
+
request_with_response(env) if env.status.nil? || env.status >= 400
|
43
|
+
end
|
44
|
+
|
45
|
+
def request_with_response(env)
|
46
|
+
oll = @options[:log_level]
|
47
|
+
@options[:log_level] = :error
|
48
|
+
public_send(log_level, 'request') do
|
49
|
+
"#{env.method.upcase} #{apply_filters(env.url.to_s)}"
|
50
|
+
end
|
51
|
+
log_headers('request', env.request_headers) if log_headers?(:request)
|
52
|
+
log_body('request', env[:request_body]) if env[:request_body] && log_body?(:request)
|
53
|
+
public_send(log_level, 'response') { "Status #{env.status}" }
|
54
|
+
log_headers('response', env.response_headers) if log_headers?(:response)
|
55
|
+
log_body('response', env[:response_body]) if env[:response_body] && log_body?(:response)
|
56
|
+
@options[:log_level] = oll
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def log_only_errors?
|
61
|
+
@options[:log_only_errors]
|
62
|
+
end
|
63
|
+
end
|
data/lib/fbe/octo.rb
CHANGED
@@ -32,6 +32,7 @@ require 'faraday/retry'
|
|
32
32
|
require_relative '../fbe'
|
33
33
|
require_relative 'middleware'
|
34
34
|
require_relative 'middleware/quota'
|
35
|
+
require_relative 'middleware/logging_formatter'
|
35
36
|
|
36
37
|
# Interface to GitHub API.
|
37
38
|
#
|
@@ -91,7 +92,17 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
91
92
|
builder.use(Fbe::Middleware::Quota, loog:, pause: options.github_api_pause || 60)
|
92
93
|
builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false, logger: Loog::NULL)
|
93
94
|
builder.use(Octokit::Response::RaiseError)
|
94
|
-
builder.use(
|
95
|
+
builder.use(
|
96
|
+
Faraday::Response::Logger,
|
97
|
+
loog,
|
98
|
+
{
|
99
|
+
formatter: Fbe::Middleware::LoggingFormatter,
|
100
|
+
log_only_errors: true,
|
101
|
+
headers: true,
|
102
|
+
bodies: true,
|
103
|
+
errors: false
|
104
|
+
}
|
105
|
+
)
|
95
106
|
builder.adapter(Faraday.default_adapter)
|
96
107
|
end
|
97
108
|
o.middleware = stack
|
@@ -452,7 +463,7 @@ class Fbe::FakeOctokit
|
|
452
463
|
number: 10,
|
453
464
|
title: 'Awesome PR 10',
|
454
465
|
created_at: Time.parse('2024-08-21 19:00:00 UTC'),
|
455
|
-
merged_at: Time.parse('2024-08-23 19:00:00 UTC')
|
466
|
+
pull_request: { merged_at: Time.parse('2024-08-23 19:00:00 UTC') }
|
456
467
|
}
|
457
468
|
]
|
458
469
|
}
|
data/lib/fbe.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# MIT License
|
4
|
+
#
|
5
|
+
# Copyright (c) 2024 Zerocracy
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require 'faraday'
|
27
|
+
require 'loog'
|
28
|
+
require_relative '../../../lib/fbe/middleware'
|
29
|
+
require_relative '../../../lib/fbe/middleware/logging_formatter'
|
30
|
+
|
31
|
+
class LoggingFormatterTest < Minitest::Test
|
32
|
+
def test_success_response_with_debug_log_level
|
33
|
+
run_logging_formatter(status: 200, log_level: Logger::DEBUG) do |logger|
|
34
|
+
assert_empty(logger.to_s)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_success_response_with_error_log_level
|
39
|
+
run_logging_formatter(status: 307, log_level: Logger::ERROR) do |logger|
|
40
|
+
assert_empty(logger.to_s)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_error_response_with_debug_log_level
|
45
|
+
run_logging_formatter(status: 400, log_level: Logger::DEBUG) do |logger|
|
46
|
+
str = logger.to_s
|
47
|
+
refute_empty(str)
|
48
|
+
assert_match(%r{http://example.com}, str)
|
49
|
+
assert_match(/Authorization: [\*]{8}cret"/, str)
|
50
|
+
assert_match(/Status 400/, str)
|
51
|
+
assert_match(/x-github-api-version-selected: "2022-11-28"/, str)
|
52
|
+
assert_match(/some response body/, str)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_error_response_with_error_log_level
|
57
|
+
run_logging_formatter(method: :post, status: 500, log_level: Logger::ERROR) do |logger|
|
58
|
+
str = logger.to_s
|
59
|
+
refute_empty(str)
|
60
|
+
assert_match(%r{http://example.com}, str)
|
61
|
+
assert_match(/Authorization: [\*]{8}cret"/, str)
|
62
|
+
assert_match(/some request body/, str)
|
63
|
+
assert_match(/Status 500/, str)
|
64
|
+
assert_match(/x-github-api-version-selected: "2022-11-28"/, str)
|
65
|
+
assert_match(/some response body/, str)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def run_logging_formatter(status:, log_level:, method: :get)
|
72
|
+
logger = Loog::Buffer.new(level: log_level)
|
73
|
+
options = {
|
74
|
+
log_only_errors: true,
|
75
|
+
headers: true,
|
76
|
+
bodies: true,
|
77
|
+
errors: false
|
78
|
+
}
|
79
|
+
formatter = Fbe::Middleware::LoggingFormatter.new(logger:, options:)
|
80
|
+
env = Faraday::Env.from(
|
81
|
+
{
|
82
|
+
method:,
|
83
|
+
request_body: method == :get ? nil : 'some request body',
|
84
|
+
url: URI('http://example.com'),
|
85
|
+
request_headers: {
|
86
|
+
'Authorization' => 'Bearer github_pat_11AAsecret'
|
87
|
+
}
|
88
|
+
}
|
89
|
+
)
|
90
|
+
formatter.request(env)
|
91
|
+
env[:response_headers] = {
|
92
|
+
'x-github-api-version-selected' => '2022-11-28'
|
93
|
+
}
|
94
|
+
env[:status] = status
|
95
|
+
env[:response_body] = 'some response body'
|
96
|
+
formatter.response(env)
|
97
|
+
yield logger
|
98
|
+
end
|
99
|
+
end
|
@@ -122,4 +122,13 @@ class TestGitHubGraph < Minitest::Test
|
|
122
122
|
result = graph.resolved_conversations('zerocracy', 'baza', 172)
|
123
123
|
assert_equal(1, result.count)
|
124
124
|
end
|
125
|
+
|
126
|
+
def test_total_issues_and_pulls
|
127
|
+
WebMock.disable_net_connect!
|
128
|
+
graph = Fbe.github_graph(options: Judges::Options.new('testing' => true), loog: Loog::NULL, global: {})
|
129
|
+
result = graph.total_issues_and_pulls('zerocracy', 'fbe')
|
130
|
+
refute_empty(result)
|
131
|
+
assert_equal(23, result['issues'])
|
132
|
+
assert_equal(19, result['pulls'])
|
133
|
+
end
|
125
134
|
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.
|
4
|
+
version: 0.0.69
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- lib/fbe/iterate.rb
|
273
273
|
- lib/fbe/just_one.rb
|
274
274
|
- lib/fbe/middleware.rb
|
275
|
+
- lib/fbe/middleware/logging_formatter.rb
|
275
276
|
- lib/fbe/middleware/quota.rb
|
276
277
|
- lib/fbe/octo.rb
|
277
278
|
- lib/fbe/overwrite.rb
|
@@ -283,6 +284,7 @@ files:
|
|
283
284
|
- lib/fbe/who.rb
|
284
285
|
- renovate.json
|
285
286
|
- rules/basic.fe
|
287
|
+
- test/fbe/middleware/test_logging_formatter.rb
|
286
288
|
- test/fbe/middleware/test_quota.rb
|
287
289
|
- test/fbe/test_award.rb
|
288
290
|
- test/fbe/test_bylaws.rb
|
@@ -309,7 +311,7 @@ licenses:
|
|
309
311
|
- MIT
|
310
312
|
metadata:
|
311
313
|
rubygems_mfa_required: 'true'
|
312
|
-
post_install_message:
|
314
|
+
post_install_message:
|
313
315
|
rdoc_options:
|
314
316
|
- "--charset=UTF-8"
|
315
317
|
require_paths:
|
@@ -326,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
326
328
|
version: '0'
|
327
329
|
requirements: []
|
328
330
|
rubygems_version: 3.4.10
|
329
|
-
signing_key:
|
331
|
+
signing_key:
|
330
332
|
specification_version: 4
|
331
333
|
summary: FactBase Extended (FBE), a collection of utility classes for Zerocracy judges
|
332
334
|
test_files: []
|