fbe 0.0.82 → 0.0.84

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: 51fe0b687df4a15c1472d3a88588801a8d8c000be7004f0d8537de7e1813ace5
4
- data.tar.gz: cbb8890bdc7c56264a3d9e316c0d4b682ec230a234323f3ce23efbf703ea4a36
3
+ metadata.gz: 9af0aad17aa024fb5572cde92c99169e2923a7c581306581201c8814f9e46f24
4
+ data.tar.gz: c7ed8ba4fc122775f9ce0690cd2aba47eeff9e24860d5835912406a5ab3ecd12
5
5
  SHA512:
6
- metadata.gz: 926492d589e6740135445210ae19dbaa60b99b3cb9fecdbdead14002fa4865eb98c0d35ab9e86b976c6cbc4809884ce0a24c6476a3622163bc141c0180b7dae0
7
- data.tar.gz: d43ea58b294e127c1d016b678de8a63e69d09ca1e28c69267a92a8b018a2ae54b32b177eefce41af1e1cdb4824f3308983d616aac85421b27bed6f51f59350b9
6
+ metadata.gz: 64c47a8d7e5ec53751fd677321646523d33aef2fcc51674990ca6a94f0b1382ad29f28dd516e0de2bb1366d7e7cd05c3370fbd311c57b472a0cb716ab4fa7377
7
+ data.tar.gz: caa828b8f477167eee3445914baafb72d07764dc25c9462459f0fa49c7157a3bafe17b24c2486203d4c35b0f79e277d5eea2d05b494df4a66a1a96d50e049261
data/Gemfile.lock CHANGED
@@ -86,7 +86,7 @@ GEM
86
86
  elapsed (0.0.1)
87
87
  loog (> 0)
88
88
  tago (> 0)
89
- erubi (1.13.0)
89
+ erubi (1.13.1)
90
90
  ethon (0.16.0)
91
91
  ffi (>= 1.15.0)
92
92
  factbase (0.4.0)
@@ -130,8 +130,8 @@ GEM
130
130
  rdoc (>= 4.0.0)
131
131
  reline (>= 0.4.2)
132
132
  iri (0.8.0)
133
- json (2.9.0)
134
- judges (0.27.0)
133
+ json (2.9.1)
134
+ judges (0.28.1)
135
135
  backtrace (~> 0)
136
136
  baza.rb (~> 0)
137
137
  concurrent-ruby (~> 1.2)
@@ -148,7 +148,7 @@ GEM
148
148
  typhoeus (~> 1.3)
149
149
  language_server-protocol (3.17.0.3)
150
150
  liquid (5.5.1)
151
- logger (1.6.3)
151
+ logger (1.6.4)
152
152
  loofah (2.23.1)
153
153
  crass (~> 1.0.2)
154
154
  nokogiri (>= 1.12.0)
@@ -290,6 +290,7 @@ GEM
290
290
  PLATFORMS
291
291
  arm64-darwin-22
292
292
  arm64-darwin-23
293
+ arm64-darwin-24
293
294
  x64-mingw-ucrt
294
295
  x86_64-darwin-20
295
296
  x86_64-darwin-21
@@ -311,4 +312,4 @@ DEPENDENCIES
311
312
  yard (= 0.9.37)
312
313
 
313
314
  BUNDLED WITH
314
- 2.4.22
315
+ 2.5.16
data/lib/fbe/iterate.rb CHANGED
@@ -175,17 +175,21 @@ class Fbe::Iterate
175
175
  end
176
176
  end
177
177
  if oct.off_quota
178
- @loog.debug('We are off GitHub quota, time to stop')
178
+ @loog.info("We are off GitHub quota, time to stop after #{start.ago}")
179
179
  break
180
180
  end
181
181
  unless seen.any? { |r, v| v < @repeats && !restarted.include?(r) }
182
- @loog.debug("No more repos to scan (out of #{repos.size}), quitting")
182
+ @loog.debug("No more repos to scan (out of #{repos.size}), quitting after #{start.ago}")
183
183
  break
184
184
  end
185
185
  if restarted.size == repos.size
186
- @loog.debug("All #{repos.size} repos restarted, quitting")
186
+ @loog.debug("All #{repos.size} repos restarted, quitting after #{start.ago}")
187
187
  break
188
188
  end
189
+ if Time.now - start > timeout
190
+ $loog.info("We are iterating for #{start.ago} already, time to give up")
191
+ next
192
+ end
189
193
  end
190
194
  @loog.debug("Finished scanning #{repos.size} repos in #{start.ago}: #{seen.map { |k, v| "#{k}:#{v}" }.join(', ')}")
191
195
  end
@@ -0,0 +1,84 @@
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/logging/formatter'
26
+ require_relative '../../fbe'
27
+ require_relative '../../fbe/middleware'
28
+
29
+ # Faraday logging formatter show verbose log for only error response
30
+ #
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Zerocracy
33
+ # License:: MIT
34
+ class Fbe::Middleware::Formatter < Faraday::Logging::Formatter
35
+ # Log HTTP request.
36
+ #
37
+ # @param [Hash] http The hash with data about HTTP request
38
+ def request(http)
39
+ @req = http
40
+ end
41
+
42
+ # Log HTTP response.
43
+ #
44
+ # @param [Hash] http The hash with data about HTTP response
45
+ def response(http)
46
+ return if http.status < 400
47
+ if http.status == 403 && http.response_headers['content-type'].start_with?('application/json')
48
+ warn(
49
+ [
50
+ "#{@req.method.upcase} #{apply_filters(@req.url.to_s)}",
51
+ '->',
52
+ http.status,
53
+ '/',
54
+ JSON.parse(http.response_body)['message']
55
+ ].join(' ')
56
+ )
57
+ return
58
+ end
59
+ error(
60
+ [
61
+ "#{@req.method.upcase} #{apply_filters(@req.url.to_s)} HTTP/1.1",
62
+ shifted(apply_filters(dump_headers(@req.request_headers))),
63
+ '',
64
+ shifted(apply_filters(@req.request_body)),
65
+ "HTTP/1.1 #{http.status}",
66
+ shifted(apply_filters(dump_headers(http.response_headers))),
67
+ '',
68
+ shifted(apply_filters(http.response_body))
69
+ ].join("\n")
70
+ )
71
+ end
72
+
73
+ private
74
+
75
+ def shifted(txt)
76
+ return '' if txt.nil?
77
+ " #{txt.gsub("\n", "\n ")}"
78
+ end
79
+
80
+ def dump_headers(headers)
81
+ return '' if headers.nil?
82
+ headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
83
+ end
84
+ end
@@ -51,9 +51,7 @@ class Fbe::Middleware::Quota < Faraday::Middleware
51
51
  @requests += 1
52
52
  response = @app.call(env)
53
53
  if out_of_limit?(env)
54
- @loog.info(
55
- "Too much GitHub API quota consumed, pausing for #{@pause} seconds"
56
- )
54
+ @loog.info("Too much GitHub API quota consumed, pausing for #{@pause} seconds")
57
55
  sleep(@pause)
58
56
  @requests = 0
59
57
  end
data/lib/fbe/octo.rb CHANGED
@@ -31,7 +31,7 @@ require 'octokit'
31
31
  require 'verbose'
32
32
  require_relative '../fbe'
33
33
  require_relative 'middleware'
34
- require_relative 'middleware/logging_formatter'
34
+ require_relative 'middleware/formatter'
35
35
  require_relative 'middleware/quota'
36
36
 
37
37
  # Makes a call to the GitHub API.
@@ -93,17 +93,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
93
93
  builder.use(Fbe::Middleware::Quota, loog:, pause: options.github_api_pause || 60)
94
94
  builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false, logger: Loog::NULL)
95
95
  builder.use(Octokit::Response::RaiseError)
96
- builder.use(
97
- Faraday::Response::Logger,
98
- loog,
99
- {
100
- formatter: Fbe::Middleware::LoggingFormatter,
101
- log_only_errors: true,
102
- headers: true,
103
- bodies: true,
104
- errors: false
105
- }
106
- )
96
+ builder.use(Faraday::Response::Logger, loog, formatter: Fbe::Middleware::Formatter)
107
97
  builder.adapter(Faraday.default_adapter)
108
98
  end
109
99
  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.82'
30
+ VERSION = '0.0.84'
31
31
  end
@@ -0,0 +1,100 @@
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
+ require 'loog'
27
+ require 'minitest/autorun'
28
+ require_relative '../../../lib/fbe'
29
+ require_relative '../../../lib/fbe/middleware'
30
+ require_relative '../../../lib/fbe/middleware/formatter'
31
+
32
+ # Test.
33
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
34
+ # Copyright:: Copyright (c) 2024 Zerocracy
35
+ # License:: MIT
36
+ class LoggingFormatterTest < Minitest::Test
37
+ def test_success_response
38
+ log_it(status: 200) do |loog|
39
+ assert_empty(loog.to_s)
40
+ end
41
+ end
42
+
43
+ def test_forward_response
44
+ log_it(status: 303) do |loog|
45
+ assert_empty(loog.to_s)
46
+ end
47
+ end
48
+
49
+ def test_error_response
50
+ log_it(status: 401) do |loog|
51
+ str = loog.to_s
52
+ refute_empty(str)
53
+ assert_match(%r{http://example.com}, str)
54
+ assert_match(/Authorization:/, str)
55
+ assert_match(%r{HTTP/1.1 401}, str)
56
+ assert_match(/x-github-api-version-selected: "2022-11-28"/, str)
57
+ assert_match(/hello, world!/, str)
58
+ assert_match(/request body/, str)
59
+ end
60
+ end
61
+
62
+ def test_limit_response
63
+ log_it(status: 403) do |loog|
64
+ str = loog.to_s
65
+ refute_empty(str)
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def log_it(status:, method: :get)
72
+ loog = Loog::Buffer.new
73
+ formatter = Fbe::Middleware::Formatter.new(logger: loog, options: {})
74
+ formatter.request(
75
+ Faraday::Env.from(
76
+ {
77
+ method:,
78
+ request_body: 'some request body',
79
+ url: URI('http://example.com'),
80
+ request_headers: {
81
+ 'Authorization' => 'Bearer github_pat_11AAsecret'
82
+ }
83
+ }
84
+ )
85
+ )
86
+ formatter.response(
87
+ Faraday::Env.from(
88
+ {
89
+ status:,
90
+ response_body: '{"message": "hello, world!"}',
91
+ response_headers: {
92
+ 'content-type' => 'application/json',
93
+ 'x-github-api-version-selected' => '2022-11-28'
94
+ }
95
+ }
96
+ )
97
+ )
98
+ yield loog
99
+ end
100
+ 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.82
4
+ version: 0.0.84
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-12-19 00:00:00.000000000 Z
11
+ date: 2024-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -287,7 +287,7 @@ files:
287
287
  - lib/fbe/iterate.rb
288
288
  - lib/fbe/just_one.rb
289
289
  - lib/fbe/middleware.rb
290
- - lib/fbe/middleware/logging_formatter.rb
290
+ - lib/fbe/middleware/formatter.rb
291
291
  - lib/fbe/middleware/quota.rb
292
292
  - lib/fbe/octo.rb
293
293
  - lib/fbe/overwrite.rb
@@ -299,7 +299,7 @@ files:
299
299
  - lib/fbe/who.rb
300
300
  - renovate.json
301
301
  - rules/basic.fe
302
- - test/fbe/middleware/test_logging_formatter.rb
302
+ - test/fbe/middleware/test_formatter.rb
303
303
  - test/fbe/middleware/test_quota.rb
304
304
  - test/fbe/test_award.rb
305
305
  - test/fbe/test_bylaws.rb
@@ -1,63 +0,0 @@
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
@@ -1,99 +0,0 @@
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