fbe 0.0.68 → 0.0.70
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fbe/github_graph.rb +28 -0
- data/lib/fbe/middleware/logging_formatter.rb +63 -0
- data/lib/fbe/octo.rb +14 -9
- 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 +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb74a645eddc2d5e41b4c8c8700e90a36c72bf33471698fa1c9a0594e7aad4b5
|
4
|
+
data.tar.gz: d401101d44e6335fe181310877a9163542c01b4f06399d5f84395cd465ca95c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcfc1d97f4d9ff179cde9774b5c0941aa530aef4b6a522d4f746c6dd3b1bcb902ecf1b6248633294cc5e644b69b8b2eb2495f699ae711316731a049f896126d6
|
7
|
+
data.tar.gz: 944b3d04d46806f25fdd21fb1744b6814d71dd2d1d9c74aa2b6d9a847c398c0ddce34351bc045afa090a77b0591f659af1ba11def4bcdd95e0ec3fdb6456b44f
|
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
|
@@ -653,10 +664,7 @@ class Fbe::FakeOctokit
|
|
653
664
|
node_id: 'R_kgDOK2_4Aw',
|
654
665
|
name: 'baza',
|
655
666
|
full_name: 'zerocracy/baza',
|
656
|
-
private: false
|
657
|
-
owner: {
|
658
|
-
login: 'zerocracy'
|
659
|
-
}
|
667
|
+
private: false
|
660
668
|
}
|
661
669
|
},
|
662
670
|
head: {
|
@@ -711,10 +719,7 @@ class Fbe::FakeOctokit
|
|
711
719
|
node_id: 'R_kgDOK2_4Aw',
|
712
720
|
name: 'judges-action',
|
713
721
|
full_name: 'zerocracy/judges-action',
|
714
|
-
private: false
|
715
|
-
owner: {
|
716
|
-
login: 'zerocracy'
|
717
|
-
}
|
722
|
+
private: false
|
718
723
|
}
|
719
724
|
},
|
720
725
|
head: {
|
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.70
|
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-09-
|
11
|
+
date: 2024-09-24 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
|