fbe 0.0.68 → 0.0.69

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: ae6d025a9d9a5313f1f119bcad19e8a258b6e0d3aa54ce82271954f90b2b8faa
4
- data.tar.gz: 561ffc4e127b79438b22c5553657f3bb1b4e5c300443dc49b6d33e2d1983c7e7
3
+ metadata.gz: a538e70cd251261fa8b1a980051cfd90195c79e291cbcc08431ae3a78481b5e7
4
+ data.tar.gz: 7492622c36dedef8fa2582cd47ecacf4006dec00244b28b0f8832ca68eb81bc8
5
5
  SHA512:
6
- metadata.gz: 63acde9b2e7c70995bd0b9a618f6503bad162c761ef36f8385d8a1796828d71731fa347cd99fb6906965a6c358897300a06a149376fb2a7dc3cde4c7ea7b05d9
7
- data.tar.gz: 74a1126e2dbb842ba8523f5a3276fbcbdcbf6ee505ef88f9412451d9933df3ba0c898d9dc8358178eba86828bd4aa7d92f7421e8c71814399df920f8fa7c66e1
6
+ metadata.gz: 9d4c8417052d583b4a83177771c75c7cee4567a2e56f3522d6bd34cd81eeeafaa7328f38d251345023dbaca9b76fcc3cdda9b0252bb1ff8a5edee6702c49eb09
7
+ data.tar.gz: ef57a016e97e85e12da1426a97557f0d54d059b34fcfc07246e82124141726d9e82326f4d86bdea3394337823b35b48568652be0ad0c5a175b854bc243497da9
@@ -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(Faraday::Response::Logger, Loog::NULL)
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
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.68'
30
+ VERSION = '0.0.69'
31
31
  end
@@ -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.68
4
+ version: 0.0.69
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-17 00:00:00.000000000 Z
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